(feat) conditionally pluralize heading in org-roam-buffer (#521)
This commit is contained in:
parent
265a3054be
commit
bd3c97bb30
1 changed files with 16 additions and 4 deletions
|
@ -100,6 +100,16 @@ When non-nil, the window will not be closed when deleting other windows."
|
|||
'font-lock-face
|
||||
'org-document-title)))
|
||||
|
||||
(defun org-roam--pluralize (string number)
|
||||
"Conditionally pluralize STRING if NUMBER is above 1."
|
||||
(let ((l (pcase number
|
||||
((pred (listp)) (length number))
|
||||
((pred (integerp)) number)
|
||||
(wrong-type (signal 'wrong-type-argument
|
||||
`((listp integerp)
|
||||
,wrong-type))))))
|
||||
(format "%s%s" string (if (> l 1) "s" ""))))
|
||||
|
||||
(defun org-roam-buffer--insert-citelinks ()
|
||||
"Insert citation backlinks for the current buffer."
|
||||
(if-let* ((roam-key (with-temp-buffer
|
||||
|
@ -108,8 +118,9 @@ When non-nil, the window will not be closed when deleting other windows."
|
|||
(key-backlinks (org-roam--get-backlinks (s-chop-prefix "cite:" roam-key)))
|
||||
(grouped-backlinks (--group-by (nth 0 it) key-backlinks)))
|
||||
(progn
|
||||
(insert (format "\n\n* %d Cite backlinks\n"
|
||||
(length key-backlinks)))
|
||||
(insert (let ((l (length key-backlinks)))
|
||||
(format "\n\n* %d %s\n"
|
||||
l (org-roam--pluralize "Cite backlink" l))))
|
||||
(dolist (group grouped-backlinks)
|
||||
(let ((file-from (car group))
|
||||
(bls (cdr group)))
|
||||
|
@ -133,8 +144,9 @@ When non-nil, the window will not be closed when deleting other windows."
|
|||
(backlinks (org-roam--get-backlinks file-path))
|
||||
(grouped-backlinks (--group-by (nth 0 it) backlinks)))
|
||||
(progn
|
||||
(insert (format "\n\n* %d Backlinks\n"
|
||||
(length backlinks)))
|
||||
(insert (let ((l (length backlinks)))
|
||||
(format "\n\n* %d %s\n"
|
||||
l (org-roam--pluralize "Backlink" l))))
|
||||
(dolist (group grouped-backlinks)
|
||||
(let ((file-from (car group))
|
||||
(bls (cdr group)))
|
||||
|
|
Loading…
Reference in a new issue