Skip to content

Commit

Permalink
Merge back PR ymherklotz#8 'custom-id-regexp'
Browse files Browse the repository at this point in the history
  • Loading branch information
ymherklotz committed Aug 19, 2022
2 parents c1f3ca9 + 91f6a0a commit 505fd41
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions zettelkasten.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
;;; -----------------------------
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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'.
Expand All @@ -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)))
Expand Down

0 comments on commit 505fd41

Please # to comment.