Skip to content

Commit 78a3a4b

Browse files
committed
refactor: Add dependency cond-let
1 parent 0f49c2b commit 78a3a4b

4 files changed

Lines changed: 87 additions & 33 deletions

File tree

org-node-backlink.el

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
(require 'cl-lib)
2424
(require 'fileloop)
2525
(require 'llama)
26+
(require 'cond-let)
2627
(require 'org-mem)
2728
(require 'org-mem-updater)
2829
(require 'org-node)
@@ -452,7 +453,7 @@ To force an update at any time, use one of these commands:
452453
(org-node--assert-transclusion-safe)
453454
(let ((user-is-editing (buffer-modified-p)))
454455
(dolist (id (delete-dups ids))
455-
(if-let* ((pos (and id (org-find-property "ID" id))))
456+
(if-let ((pos (and id (org-find-property "ID" id))))
456457
(progn (goto-char pos)
457458
(org-node-backlink--fix-nearby))
458459
(error "Could not find ID %s in file %s" id file)))
@@ -487,7 +488,7 @@ Or if KIND is symbol `update-drawers', `del-drawers', `update-props', or
487488
(defun org-node-backlink--fix-nearby-property (&optional remove)
488489
"Update the :BACKLINKS: property in the current entry.
489490
If REMOVE is non-nil, remove it instead."
490-
(when-let* ((prop-pos (car (org-get-property-block))))
491+
(when-let ((prop-pos (car (org-get-property-block))))
491492
(when (get-text-property prop-pos 'read-only)
492493
;; Because `org-entry-put' is so unsafe that it inhibits read-only
493494
(error "org-node-backlink: Area seems to be read-only at %d in %s"
@@ -636,17 +637,17 @@ If REMOVE non-nil, remove it instead."
636637
(org-node--assert-transclusion-safe)
637638
(let ((origin-id (org-entry-get-with-inheritance "ID")))
638639
(when (and origin-id (not (equal origin-id target-id)))
639-
(when-let* ((origin-title
640-
(save-excursion
641-
(without-restriction
642-
(goto-char org-entry-property-inherited-from)
643-
(or (org-get-heading t t t t)
644-
(org-get-title))))))
640+
(when-let ((origin-title
641+
(save-excursion
642+
(without-restriction
643+
(goto-char org-entry-property-inherited-from)
644+
(or (org-get-heading t t t t)
645+
(org-get-title))))))
645646

646647
(org-node--with-quick-file-buffer target-file
647648
:about-to-do "Org-node going to add backlink in target of link you just inserted"
648649
(org-node--assert-transclusion-safe)
649-
(if-let* ((pos (org-find-property "ID" target-id)))
650+
(if-let ((pos (org-find-property "ID" target-id)))
650651
(progn (goto-char pos)
651652
(org-node-backlink--add-nearby origin-id origin-title))
652653
(message "`org-node-backlink--add-in-target' could not find ID %s in file %s"
@@ -660,7 +661,7 @@ If REMOVE non-nil, remove it instead."
660661

661662
(defun org-node-backlink--add-to-property (id title)
662663
"Insert a link with ID and TITLE into nearby :BACKLINKS: property."
663-
(when-let* ((prop-pos (car (org-get-property-block))))
664+
(when-let ((prop-pos (car (org-get-property-block))))
664665
(when (get-text-property prop-pos 'read-only)
665666
;; Because `org-entry-put' is so unsafe that it inhibits read-only
666667
(error "org-node-backlink: Area seems to be read-only at %d in %s"
@@ -773,3 +774,15 @@ See Info node `(org-node)'."
773774
(provide 'org-node-backlink)
774775

775776
;;; org-node-backlink.el ends here
777+
778+
;; Local Variables:
779+
;; checkdoc-spellcheck-documentation-flag: nil
780+
;; checkdoc-verb-check-experimental-flag: nil
781+
;; emacs-lisp-docstring-fill-column: 72
782+
;; read-symbol-shorthands: (("and$" . "cond-let--and$")
783+
;; ("and>" . "cond-let--and>")
784+
;; ("and-let" . "cond-let--and-let")
785+
;; ("if-let" . "cond-let--if-let")
786+
;; ("when-let" . "cond-let--when-let")
787+
;; ("while-let" . "cond-let--while-let"))
788+
;; End:

org-node-context.el

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
(require 'magit-section)
1515
(require 'repeat)
1616
(require 'map)
17+
(require 'cond-let)
18+
(require 'llama)
1719
(eval-when-compile
1820
(require 'org)
1921
(require 'org-node)
@@ -94,15 +96,15 @@ time that context was shown in a visible window. Including:
9496
(defun org-node-context-history-go-back ()
9597
"Show the last context."
9698
(interactive () org-node-context-mode)
97-
(when-let* ((last (pop org-node-context--past)))
99+
(when-let ((last (pop org-node-context--past)))
98100
(push org-node-context--current
99101
org-node-context--future)
100102
(org-node-context--refresh nil last t)))
101103

102104
(defun org-node-context-history-go-forward ()
103105
"Show the next context."
104106
(interactive () org-node-context-mode)
105-
(when-let* ((next (pop org-node-context--future)))
107+
(when-let ((next (pop org-node-context--future)))
106108
(push org-node-context--current
107109
org-node-context--past)
108110
(org-node-context--refresh nil next t)))
@@ -127,7 +129,7 @@ time that context was shown in a visible window. Including:
127129
;; TODO: Solve problem if truncating away a :END: or #+END_... but not #+BEGIN,
128130
;; or vice versa.
129131
;; (defun org-node-context--truncate-buffer ()
130-
;; (when-let* ((cutoff org-node-context-truncate-to-lines))
132+
;; (when-let ((cutoff org-node-context-truncate-to-lines))
131133
;; (when (> (line-number-at-pos) cutoff)
132134
;; (forward-line (- cutoff))
133135
;; (delete-region (point-min) (point)))
@@ -304,7 +306,7 @@ Repeatable on the last key of a key sequence if
304306
(defun org-node-context-toggle ()
305307
"Show the main context buffer, or hide it if already showing."
306308
(interactive)
307-
(if-let* ((win (get-buffer-window org-node-context-main-buffer 'visible)))
309+
(if-let ((win (get-buffer-window org-node-context-main-buffer 'visible)))
308310
(quit-window nil win)
309311
(let ((buf (get-buffer-create org-node-context-main-buffer)))
310312
(when (derived-mode-p 'org-mode)
@@ -336,7 +338,7 @@ otherwise call the latter."
336338

337339
(defun org-node-context--displaying-p (buf id)
338340
"Is BUF displaying context for ID?"
339-
(when-let* ((buf (get-buffer (or buf org-node-context-main-buffer))))
341+
(when-let ((buf (get-buffer (or buf org-node-context-main-buffer))))
340342
(equal id (buffer-local-value 'org-node-context--current buf))))
341343

342344
(defun org-node-context-refresh-this-buffer (&rest _)
@@ -385,12 +387,12 @@ that buffer."
385387
(setq header-line-format
386388
(concat "Context for \"" (org-mem-entry-title node) "\""))
387389
(magit-insert-section (org-node-context :root)
388-
(when-let* ((links (org-mem-id-links-to-entry node)))
390+
(when-let ((links (org-mem-id-links-to-entry node)))
389391
(magit-insert-section (org-node-context :id-links)
390392
(magit-insert-heading "ID backlinks:")
391393
(org-node-context--insert-backlink-sections links)
392394
(insert "\n")))
393-
(when-let* ((links (org-mem-roam-reflinks-to-entry node)))
395+
(when-let ((links (org-mem-roam-reflinks-to-entry node)))
394396
(magit-insert-section (org-node-context :reflinks)
395397
(magit-insert-heading "Ref backlinks:")
396398
(org-node-context--insert-backlink-sections links)
@@ -402,7 +404,7 @@ that buffer."
402404
"Insert a section displaying a preview of LINK."
403405
(dolist (link (sort links #'org-node-context--origin-title-lessp))
404406
(let* ((entry (org-node-context--get-link-origin link))
405-
(breadcrumbs (if-let* ((olp (org-mem-olpath-with-file-title entry)))
407+
(breadcrumbs (if-let ((olp (org-mem-olpath-with-file-title entry)))
406408
(string-join olp " > ")
407409
"Top")))
408410
(magit-insert-section (org-node-context link)
@@ -523,3 +525,15 @@ No-op if user option `org-node-context-persist-on-disk' is nil."
523525
(provide 'org-node-context)
524526

525527
;;; org-node-context.el ends here
528+
529+
;; Local Variables:
530+
;; checkdoc-spellcheck-documentation-flag: nil
531+
;; checkdoc-verb-check-experimental-flag: nil
532+
;; emacs-lisp-docstring-fill-column: 72
533+
;; read-symbol-shorthands: (("and$" . "cond-let--and$")
534+
;; ("and>" . "cond-let--and>")
535+
;; ("and-let" . "cond-let--and-let")
536+
;; ("if-let" . "cond-let--if-let")
537+
;; ("when-let" . "cond-let--when-let")
538+
;; ("while-let" . "cond-let--while-let"))
539+
;; End:

org-node-seq.el

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
(require 'transient)
3030
(require 'org-node)
3131
(require 'org-mem)
32+
(require 'llama)
33+
(require 'cond-let)
3234
(defvar org-node-proposed-seq)
3335
(defvar org-mem--next-message)
3436
(declare-function org-entry-get-with-inheritance "org")
@@ -53,7 +55,7 @@ For KEY, NAME and CAPTURE, see `org-node-seq-defs'."
5355
(cons (concat sortstr " " (org-mem-entry-title node))
5456
(org-mem-entry-id node)))))
5557
:whereami (lambda ()
56-
(when-let* ((sortstr (org-entry-get nil ,prop t))
58+
(when-let ((sortstr (org-entry-get nil ,prop t))
5759
(node (org-node-at-point)))
5860
(concat sortstr " " (org-mem-entry-title node))))
5961
:prompter (lambda (key)
@@ -198,7 +200,7 @@ The latter uses a sloppy algorithm so not all formats work, see
198200
(match-string 0 clipped-name)
199201
;; Even in a non-daily file, pretend it is a daily if possible,
200202
;; to allow entering the sequence at a more relevant date
201-
(when-let* ((stamp (org-node-extract-file-name-datestamp path)))
203+
(when-let ((stamp (org-node-extract-file-name-datestamp path)))
202204
(org-node-seq-extract-ymd stamp org-node-file-timestamp-format))))))
203205

204206
;; TODO: Handle %s, %V, %y... is there a library?
@@ -721,3 +723,15 @@ not exist."
721723
(provide 'org-node-seq)
722724

723725
;;; org-node-seq.el ends here
726+
727+
;; Local Variables:
728+
;; checkdoc-spellcheck-documentation-flag: nil
729+
;; checkdoc-verb-check-experimental-flag: nil
730+
;; emacs-lisp-docstring-fill-column: 72
731+
;; read-symbol-shorthands: (("and$" . "cond-let--and$")
732+
;; ("and>" . "cond-let--and>")
733+
;; ("and-let" . "cond-let--and-let")
734+
;; ("if-let" . "cond-let--if-let")
735+
;; ("when-let" . "cond-let--when-let")
736+
;; ("while-let" . "cond-let--while-let"))
737+
;; End:

org-node.el

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
;; URL: https://github.com/meedstrom/org-node
88
;; Created: 2024-04-13
99
;; Keywords: org, hypermedia
10-
;; Package-Requires: ((emacs "29.1") (llama "1.0") (magit-section "4.3.0") (org-mem "0.32.0"))
10+
;; Package-Requires: ((emacs "29.1") (cond-let "0.2") (llama "1.0") (magit-section "4.3.0") (org-mem "0.32.0"))
1111

1212
;;; Commentary:
1313

@@ -130,6 +130,7 @@
130130
(require 'cl-lib)
131131
(require 'fileloop)
132132
(require 'llama)
133+
(require 'cond-let)
133134
(require 'org-faces)
134135
(require 'org-mem)
135136
(require 'org-mem-updater)
@@ -486,11 +487,11 @@ aliases."
486487
(defun org-node-prepend-olp (node title)
487488
"Prepend NODE\\='s outline path to TITLE."
488489
(list title
489-
(if-let* ((fontified-ancestors
490-
(cl-loop
491-
for ancestor in (org-mem-olpath-with-file-title node)
492-
collect
493-
(propertize ancestor 'face 'org-node-parent))))
490+
(if-let ((fontified-ancestors
491+
(cl-loop
492+
for ancestor in (org-mem-olpath-with-file-title node)
493+
collect
494+
(propertize ancestor 'face 'org-node-parent))))
494495
(concat (string-join fontified-ancestors " > ") " > ")
495496
"")
496497
""))
@@ -697,7 +698,7 @@ used as INITIAL-INPUT in `completing-read'."
697698
(when (and (org-mem-entry-id entry)
698699
(funcall org-node-filter-fn entry))
699700
(dolist (ref (org-mem-entry-roam-refs entry))
700-
(puthash (concat (when-let* ((type (gethash ref org-mem--roam-ref<>type)))
701+
(puthash (concat (when-let ((type (gethash ref org-mem--roam-ref<>type)))
701702
(propertize (concat type ":") 'face 'org-node-cite-type))
702703
(propertize ref 'face 'org-node-cite))
703704
entry
@@ -1275,7 +1276,7 @@ type the name of a node that does not exist. That enables this
12751276
;; expansions %(org-capture-get :title) and %(org-capture-get :id) in the
12761277
;; template string.
12771278
(apply #'org-capture-put (org-node-capture-infer-title-etc))
1278-
(if-let* ((node (org-capture-get :existing-node)))
1279+
(if-let ((node (org-capture-get :existing-node)))
12791280
(org-node-goto node t)
12801281
(org-node-new-file (org-capture-get :title)
12811282
(org-capture-get :id))
@@ -2245,8 +2246,8 @@ user quits, do not apply any modifications."
22452246
(setq default-directory
22462247
(read-directory-name
22472248
"Directory with Org notes to operate on: "))))
2248-
(when-let* ((bufs (seq-filter (##string-search "*grep*" (buffer-name %))
2249-
(buffer-list))))
2249+
(when-let ((bufs (seq-filter (##string-search "*grep*" (buffer-name %))
2250+
(buffer-list))))
22502251
(when (yes-or-no-p "Kill other *grep* buffers to be sure this works?")
22512252
(mapc #'kill-buffer bufs)))
22522253
(let* ((filename (file-relative-name (read-file-name "File to rename: ")))
@@ -2917,7 +2918,7 @@ As bonus, do not land on an inlinetask, seek a real heading."
29172918
(defun org-node-complete-at-point ()
29182919
"Expand word at point to a known node title, and linkify.
29192920
Designed for `completion-at-point-functions'."
2920-
(when-let* ((bounds (bounds-of-thing-at-point 'word)))
2921+
(when-let ((bounds (bounds-of-thing-at-point 'word)))
29212922
(and (not (org-in-src-block-p))
29222923
(not (save-match-data (org-in-regexp org-link-any-re)))
29232924
(list (car bounds)
@@ -2926,7 +2927,7 @@ Designed for `completion-at-point-functions'."
29262927
:exclusive 'no
29272928
:exit-function
29282929
(lambda (text _)
2929-
(when-let* ((id (gethash text org-mem--title<>id)))
2930+
(when-let ((id (gethash text org-mem--title<>id)))
29302931
(atomic-change-group
29312932
(delete-char (- (length text)))
29322933
(insert (org-link-make-string (concat "id:" id) text)))
@@ -2961,7 +2962,7 @@ the same link in its ROAM_REFS property, visit that node rather than
29612962
following the link normally.
29622963
29632964
If already visiting that node, then follow the link normally."
2964-
(when-let* ((url (thing-at-point 'url)))
2965+
(when-let ((url (thing-at-point 'url)))
29652966
;; Rarely more than one valid target
29662967
(let* ((target (car (org-mem--split-roam-refs-field url)))
29672968
(found (cl-loop for node in (org-mem-all-id-nodes)
@@ -3450,3 +3451,15 @@ ENTRY should be an `org-mem-entry' object."
34503451
(provide 'org-node)
34513452

34523453
;;; org-node.el ends here
3454+
3455+
;; Local Variables:
3456+
;; checkdoc-spellcheck-documentation-flag: nil
3457+
;; checkdoc-verb-check-experimental-flag: nil
3458+
;; emacs-lisp-docstring-fill-column: 72
3459+
;; read-symbol-shorthands: (("and$" . "cond-let--and$")
3460+
;; ("and>" . "cond-let--and>")
3461+
;; ("and-let" . "cond-let--and-let")
3462+
;; ("if-let" . "cond-let--if-let")
3463+
;; ("when-let" . "cond-let--when-let")
3464+
;; ("while-let" . "cond-let--while-let"))
3465+
;; End:

0 commit comments

Comments
 (0)