@@ -11,39 +11,71 @@ If you use Emacs, Weibian is accompanied by an Emacs Lisp package providing the
1111
1212```lisp
1313(use-package denote
14- :bind (("C-c n n" . denote))
14+ :bind (("C-c n n" . denote)) ;; add your keybindings
1515 :config
16- (setq denote-directory (expand-file-name "~/Documents/notes/typ/")))
16+ (setq denote-directory (expand-file-name "~/Documents/notes/typ/"))
17+ (setq denote-prompts '(signature title))
18+ (setq denote-excluded-directories-regexp "_template")
19+
20+ ;;; Use incrementing base-36 numbers as id
21+ ;;; This function assumes that IDENTIFIERS is a list of base-36 strings
22+ ;;; i.e. 4-character strings consisting of numbers and uppercase letters
23+ (defun my/denote-get-next-base36 (identifiers)
24+ (let ((maxs nil))
25+ (dolist (s identifiers)
26+ (let ((u (upcase s)))
27+ (when (or (null maxs) (string> u maxs))
28+ (setq maxs u))))
29+ ;; increment maxs
30+ (let ((buf (copy-sequence maxs))
31+ (i 3)
32+ (carry 1))
33+ (while (and (>= i 0) (= carry 1))
34+ (let* ((d (aref buf i)))
35+ (if (= d ?Z)
36+ (progn
37+ (aset buf i ?0)
38+ (setq carry 1))
39+ (if (= d ?9)
40+ (aset buf i ?A)
41+ (aset buf i (+ d 1)))
42+ (setq carry 0)))
43+ (setq i (1- i)))
44+ buf)))
45+
46+ (defun my/denote-generate-base36-identifier (initial-identifier _date)
47+ (let ((denote-used-identifiers (or denote-used-identifiers (denote--get-all-used-ids))))
48+ (cond (;; Always use the supplied initial-identifier if possible,
49+ ;; regardless of format.
50+ (and initial-identifier
51+ (not (gethash initial-identifier denote-used-identifiers)))
52+ initial-identifier)
53+ (;; Else, the supplied initial-identifier is nil or it is already
54+ ;; used. Ignore it and generate a valid identifier with the right
55+ ;; format.
56+ t
57+ (let* ((identifiers (hash-table-keys denote-used-identifiers))
58+ (case-fold-search nil)
59+ (base36-identifiers (seq-filter (lambda (id) (string-match-p "[0-9A-Z]\\{4\\}" id)) identifiers)))
60+ (if base36-identifiers
61+ (my/denote-get-next-base36 base36-identifiers)
62+ "0000"))))))
63+ (setq denote-get-identifier-function #'my/denote-generate-base36-identifier))
1764
1865(use-package typst-ts-mode)
1966
2067(use-package denote-weibian
2168 :load-path "/path/to/weibian/directory/"
22- :after (denote typst-ts-mode )
69+ :after (denote)
2370 :demand t
24- :bind (:map typst-ts-mode-map
25- ("C-c n b" . denote-weibian-backlinks)
71+ :bind (("C-c n b" . denote-weibian-backlinks)
2672 ("C-c n c" . denote-weibian-contexts)
27- ("C-c n t" . denote-weibian-transclude)
28- ("C-c n l" . denote-link)
29- ("C-c n L" . denote-add-links)
30- ("C-c n q c" . denote-query-contents-link) ; create link that triggers a grep
31- ("C-c n q f" . denote-query-filenames-link) ; create link that triggers a dired
32- ;; Note that `denote-rename-file' can work from any context, not just
33- ;; Dired bufffers. That is why we bind it here to the `global-map'.
34- ("C-c n r" . denote-rename-file)
35- ("C-c n R" . denote-rename-file-using-front-matter))
73+ ("C-c n t" . denote-weibian-transclude))
3674 :config
3775 (push denote-weibian-file-type denote-file-types)
3876
39- ;; Customize slugification to allow uppercase letters in signatures; this can also be handled
40- ;; at the Typst side.
41- (defun +denote-sluggify-signature (str)
42- "Make STR an appropriate slug but allowing uppercase letters."
43- (denote-slug-put-equals
44- (replace-regexp-in-string "[][{}!@#$%^&*()+'\"?,.\|;:~`‘’“”/-]*" "" str)))
4577 (setq denote-file-name-slug-functions
4678 '((title . denote-sluggify-title)
47- (signature . +denote-sluggify-signature )
79+ (signature . identity )
4880 (keyword . denote-sluggify-keyword))))
4981```
0 commit comments