diff options
author | Yann Herklotz <git@yannherklotz.com> | 2022-08-20 00:51:28 +0100 |
---|---|---|
committer | Yann Herklotz <git@yannherklotz.com> | 2022-08-20 00:51:28 +0100 |
commit | 505fd41dea012e743962c3a376c1e63e7a1e127e (patch) | |
tree | faa0d0ab875775b1ec64da7227b2b69bb379a35d | |
parent | c1f3ca9368a43638de7a0e78a0dceaa0f8943c37 (diff) | |
parent | 91f6a0a69f9f1275ad4fd73e218bd3611b5b4a18 (diff) | |
download | org-zettelkasten-505fd41dea012e743962c3a376c1e63e7a1e127e.tar.gz org-zettelkasten-505fd41dea012e743962c3a376c1e63e7a1e127e.zip |
Merge back PR #8 'custom-id-regexp'
-rw-r--r-- | zettelkasten.el | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/zettelkasten.el b/zettelkasten.el index cad3b8b..6acb90d 100644 --- a/zettelkasten.el +++ b/zettelkasten.el @@ -65,6 +65,11 @@ For supported options, please consult `format-time-string'." :type 'string :group 'zettelkasten) +(defcustom zettelkasten-id-regexp "[0-9]+" + "Regexp for IDs." + :type 'string + :group 'zettelkasten) + ;;; ----------------------------- ;;; HELPER FUNCTIONS FOR NOTE IDs ;;; ----------------------------- @@ -76,7 +81,9 @@ For supported options, please consult `format-time-string'." (defun zettelkasten--filename-to-id (filename) "Convert FILENAME to id." - (string-match (format "\\([0-9]*\\)\\.%s\\'" zettelkasten-extension) filename) + (string-match + (format "\\(%s\\)\\.%s\\'" zettelkasten-id-regexp zettelkasten-extension) + filename) (match-string 1 filename)) (defun zettelkasten--display-for-search (note) @@ -90,7 +97,7 @@ Meant for displaying when searching." The note may be formatted with some title, which this function aims to remove." - (string-match "[^0-9]*\\([0-9]+\\)" note) + (string-match (format "[^0-9]*\\(%s\\)" zettelkasten-id-regexp) note) (match-string 1 note)) (defun zettelkasten--format-link (note &optional link-text) @@ -143,7 +150,7 @@ Return the NUMth match. If NUM is nil, return the 0th match." (mapcar #'zettelkasten--filename-to-id (directory-files (expand-file-name zettelkasten-directory) nil - (format "[0-9]+\\.%s$" zettelkasten-extension) t))) + (format "%s\\.%s$" zettelkasten-id-regexp zettelkasten-extension) t))) (defun zettelkasten--list-notes-grep () "Return all the ids and titles of notes in the `zettelkasten-directory'. @@ -161,8 +168,8 @@ This is deprecated in favour for `zettelkasten-list-notes'." (line-beginning-position) (line-end-position))) (when (string-match - (format "\\([0-9]*\\)\\.%s:#\\+TITLE: \\(.*\\)" - zettelkasten-extension) + (format "\\(%s\\)\\.%s:#\\+TITLE: \\(.*\\)" + zettelkasten-id-regexp zettelkasten-extension) current-string) (setq matched-string (concat (match-string 1 current-string) ": " (match-string 2 current-string))) |