diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ba00ae..369529a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ ### Features - [#814] Implement `org-roam-insert-immediate` - +- [#833](https://github.com/org-roam/org-roam/pull/833) Add customization of file titles with `org-roam-title-to-slug-function`. ### Bugfixes ## 1.2.0 (12-06-2020) diff --git a/org-roam-capture.el b/org-roam-capture.el index a824d5b..13e4c97 100644 --- a/org-roam-capture.el +++ b/org-roam-capture.el @@ -39,12 +39,12 @@ (defvar org-roam-encrypt-files) (defvar org-roam-directory) (defvar org-roam-mode) +(defvar org-roam-title-to-slug-function) (declare-function org-roam--get-title-path-completions "org-roam") (declare-function org-roam--get-ref-path-completions "org-roam") (declare-function org-roam--file-path-from-id "org-roam") (declare-function org-roam--find-file "org-roam") (declare-function org-roam--format-link "org-roam") -(declare-function org-roam--title-to-slug "org-roam") (declare-function org-roam-mode "org-roam") (declare-function org-roam-completion--completing-read "org-roam-completion") @@ -349,7 +349,7 @@ This uses the templates defined at `org-roam-capture-templates'." (title (or (plist-get res :title) title-with-keys)) (file-path (plist-get res :path))) (let ((org-roam-capture--info (list (cons 'title title) - (cons 'slug (org-roam--title-to-slug title)) + (cons 'slug (funcall org-roam-title-to-slug-function title)) (cons 'file file-path))) (org-roam-capture--context 'capture)) (setq org-roam-capture-additional-template-props (list :capture-fn 'org-roam-capture)) diff --git a/org-roam-protocol.el b/org-roam-protocol.el index c5c1238..48ddf3c 100644 --- a/org-roam-protocol.el +++ b/org-roam-protocol.el @@ -56,7 +56,7 @@ It opens or creates a note with the given ref. (unless (assoc 'ref decoded-alist) (error "No ref key provided")) (when-let ((title (cdr (assoc 'title decoded-alist)))) - (push (cons 'slug (org-roam--title-to-slug title)) decoded-alist)) + (push (cons 'slug (funcall org-roam-title-to-slug-function title)) decoded-alist)) (let* ((org-roam-capture-templates org-roam-capture-ref-templates) (org-roam-capture--context 'ref) (org-roam-capture--info decoded-alist) diff --git a/org-roam.el b/org-roam.el index a757102..bf1c7c0 100644 --- a/org-roam.el +++ b/org-roam.el @@ -70,7 +70,6 @@ (defvar org-id-link-to-org-use-id) (declare-function org-id-find-id-in-file "ext:org-id" (id file &optional markerp)) - ;;;; Customizable variables (defgroup org-roam nil "Roam Research replica in Org-mode." @@ -208,6 +207,12 @@ extraction methods: (const :tag "sub-directories" all-directories) (const :tag "parent directory" last-directory))) +(defcustom org-roam-title-to-slug-function #'org-roam--title-to-slug + "Function to be used in converting a title to the filename slug. +Function should return a filename string based on title." + :type 'function + :group 'org-roam) + (defcustom org-roam-title-sources '((title headline) alias) "The list of sources from which to retrieve a note title. Each element in the list is either: @@ -1297,7 +1302,7 @@ which takes as its argument an alist of path-completions. See (if file-path (org-roam--find-file file-path) (let ((org-roam-capture--info `((title . ,title-with-tags) - (slug . ,(org-roam--title-to-slug title-with-tags)))) + (slug . ,(funcall org-roam-title-to-slug-function title-with-tags)))) (org-roam-capture--context 'title)) (add-hook 'org-capture-after-finalize-hook #'org-roam-capture--find-file-h) (org-roam--with-template-error 'org-roam-capture-templates @@ -1372,7 +1377,7 @@ If DESCRIPTION is provided, use this as the link label. See (when (org-roam-capture--in-process-p) (user-error "Nested Org-roam capture processes not supported")) (let ((org-roam-capture--info `((title . ,title-with-tags) - (slug . ,(org-roam--title-to-slug title-with-tags)))) + (slug . ,(funcall org-roam-title-to-slug-function title-with-tags)))) (org-roam-capture--context 'title)) (add-hook 'org-capture-after-finalize-hook #'org-roam-capture--insert-link-h) (setq org-roam-capture-additional-template-props (list :region region