From 91f6a0a69f9f1275ad4fd73e218bd3611b5b4a18 Mon Sep 17 00:00:00 2001 From: Rock Storm Date: Wed, 27 Jul 2022 01:09:18 +0200 Subject: Allow customising ID regexp pattern See [issue #6][1] for background. [1]: https://github.com/ymherklotz/emacs-zettelkasten/issues/6 --- zettelkasten.el | 17 ++++++++++++----- 1 file 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))) -- cgit