From 710dcf99bd73763dcdfa5418a699955a9aeb60d8 Mon Sep 17 00:00:00 2001 From: Daniel Kraus Date: Tue, 31 Jul 2018 11:19:19 +0200 Subject: [PATCH] Add: org-make-toc-filename-prefix option Closes #2. Thanks to Daniel Kraus (@dakra). --- README.org | 3 +++ org-make-toc.el | 12 ++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/README.org b/README.org index 2e5ab2a..74473d9 100644 --- a/README.org +++ b/README.org @@ -85,6 +85,9 @@ See [[https://github.com/alphapapa/org-make-toc/blob/master/example.org][example ** 0.3-pre +*Additions* ++ Option ~org-make-toc-filename-prefix~ to add the filename before the anchor in links. This allows a ToC to refer to entries in another file by manually copying a ToC from one file into another. See [[https://github.com/alphapapa/org-make-toc/pull/2][issue 2]]. Thanks to [[https://github.com/dakra][Daniel Kraus]]. + *Changes* + Minor refactoring. diff --git a/org-make-toc.el b/org-make-toc.el index fbc0dd0..281fced 100644 --- a/org-make-toc.el +++ b/org-make-toc.el @@ -80,6 +80,11 @@ :group 'org :link '(url-link "http://github.com/alphapapa/org-make-toc")) +(defcustom org-make-toc-filename-prefix nil + "Prefix links with filename before anchor tag." + :type 'boolean + :safe #'booleanp) + ;;;; Commands ;;;###autoload @@ -285,8 +290,11 @@ When KEEP-ALL is non-nil, return all entries." (-when-let* ((title (org-element-property :title entry)) (title (org-link-display-format title)) (target (replace-regexp-in-string " " "-" (downcase title))) - (target (replace-regexp-in-string "[^[:alnum:]_-]" "" target))) - (format "[[#%s][%s]]" target title))) + (target (replace-regexp-in-string "[^[:alnum:]_-]" "" target)) + (filename (if org-make-toc-filename-prefix + (file-name-nondirectory (buffer-file-name)) + ""))) + (format "[[%s#%s][%s]]" filename target title))) ;;;;; Misc