mirror of
https://github.com/org-roam/org-roam
synced 2025-09-28 16:50:58 -05:00
(feat): Allow function for org-roam-link-title-format (#261)
Addresses #255
This commit is contained in:
19
org-roam.el
19
org-roam.el
@@ -80,8 +80,11 @@ Valid values are
|
|||||||
:group 'org-roam)
|
:group 'org-roam)
|
||||||
|
|
||||||
(defcustom org-roam-link-title-format "%s"
|
(defcustom org-roam-link-title-format "%s"
|
||||||
"The format string used when inserting Org-roam links that use their title."
|
"The formatter used when inserting Org-roam links that use their title.
|
||||||
:type 'string
|
Formatter may be a function that takes title as its only argument."
|
||||||
|
:type '(choice
|
||||||
|
(string :tag "String Format" "%s")
|
||||||
|
(function :tag "Custom function"))
|
||||||
:group 'org-roam)
|
:group 'org-roam)
|
||||||
|
|
||||||
(defcustom org-roam-buffer-width 0.33 "Width of `org-roam' buffer."
|
(defcustom org-roam-buffer-width 0.33 "Width of `org-roam' buffer."
|
||||||
@@ -728,6 +731,12 @@ GOTO and KEYS argument have the same functionality as
|
|||||||
(defvar org-roam--capture-insert-point nil
|
(defvar org-roam--capture-insert-point nil
|
||||||
"The point to jump to after the call to `org-roam-insert'.")
|
"The point to jump to after the call to `org-roam-insert'.")
|
||||||
|
|
||||||
|
(defun org-roam--format-link-title (title)
|
||||||
|
"Returns the link title, given the file TITLE."
|
||||||
|
(if (functionp org-roam-link-title-format)
|
||||||
|
(funcall org-roam-link-title-format title)
|
||||||
|
(format org-roam-link-title-format title)))
|
||||||
|
|
||||||
(defun org-roam-insert (prefix)
|
(defun org-roam-insert (prefix)
|
||||||
"Find an Org-roam file, and insert a relative org link to it at point.
|
"Find an Org-roam file, and insert a relative org link to it at point.
|
||||||
If PREFIX, downcase the title before insertion."
|
If PREFIX, downcase the title before insertion."
|
||||||
@@ -759,9 +768,9 @@ If PREFIX, downcase the title before insertion."
|
|||||||
(when region ;; Remove previously selected text.
|
(when region ;; Remove previously selected text.
|
||||||
(delete-region (car region) (cdr region)))
|
(delete-region (car region) (cdr region)))
|
||||||
(let ((link-location (concat "file:" (file-relative-name target-file-path current-file-path)))
|
(let ((link-location (concat "file:" (file-relative-name target-file-path current-file-path)))
|
||||||
(description (format org-roam-link-title-format (if prefix
|
(description (org-roam--format-link-title (if prefix
|
||||||
(downcase region-or-title)
|
(downcase region-or-title)
|
||||||
region-or-title))))
|
region-or-title))))
|
||||||
(goto-char p)
|
(goto-char p)
|
||||||
(insert (format "[[%s][%s]]"
|
(insert (format "[[%s][%s]]"
|
||||||
link-location
|
link-location
|
||||||
|
Reference in New Issue
Block a user