From fbbac978cbc90d6e1791853e88c4e860eff82bed Mon Sep 17 00:00:00 2001 From: Daniel Kraus Date: Tue, 31 Jul 2018 11:19:19 +0200 Subject: [PATCH] Add option to prefix links with filename before anchor tag --- org-make-toc.el | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/org-make-toc.el b/org-make-toc.el index ca83ff9..a95c13e 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-prefix-filename-p nil + "If non-nil, prefix links with filename before anchor tag." + :type 'boolean + :safe #'booleanp) + ;;;; Commands ;;;###autoload @@ -281,8 +286,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-prefix-filename-p + (file-name-nondirectory (buffer-file-name)) + ""))) + (format "[[%s#%s][%s]]" filename target title))) ;;;;; Misc