Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to prefix links with filename before anchor tag #2

Merged
merged 1 commit into from
Jul 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
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-filename-prefix nil
"Prefix links with filename before anchor tag."
:type 'boolean
:safe #'booleanp)

;;;; Commands

;;;###autoload
Expand Down Expand Up @@ -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

Expand Down