Skip to content

Commit

Permalink
Add option to prefix links with filename before anchor tag
Browse files Browse the repository at this point in the history
  • Loading branch information
dakra committed Jul 31, 2018
1 parent 69bfc93 commit fbbac97
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions org-make-toc.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit fbbac97

Please sign in to comment.