aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-07-11 21:35:04 -0500
committerCraig Jennings <c@cjennings.net>2026-07-11 21:35:04 -0500
commit545c036ede2e1299f5c31bdb4b80f8eb92b435b4 (patch)
tree647f234e8a0a8463d4c588beb30b45d9b3621e71 /modules
parent12129ec7663137f14908381efc9198dfcaff7022 (diff)
downloaddotemacs-545c036ede2e1299f5c31bdb4b80f8eb92b435b4.tar.gz
dotemacs-545c036ede2e1299f5c31bdb4b80f8eb92b435b4.zip
fix(org-contacts-config): jump to contact heading, not a body match
cj/org-contacts-find visited the contacts file before prompting, so a C-g at the prompt stranded point at the top of it. It then jumped with search-forward, which could land inside another entry's body that mentioned the name. I collect the headings with find-file-noselect first (extracted as cj/--org-contacts-collect), prompt, then jump to the selected heading's stored position. The prompt now requires a match, since a typed non-match has no position to jump to.
Diffstat (limited to 'modules')
-rw-r--r--modules/org-contacts-config.el37
1 files changed, 24 insertions, 13 deletions
diff --git a/modules/org-contacts-config.el b/modules/org-contacts-config.el
index 944d75c1..39ff9910 100644
--- a/modules/org-contacts-config.el
+++ b/modules/org-contacts-config.el
@@ -170,29 +170,40 @@ Added: %U"
(require 'system-lib)
+(defun cj/--org-contacts-collect (buffer)
+ "Return an alist of (NAME POSITION INFO) for the contact headings in BUFFER.
+NAME is the heading text, POSITION its buffer position, and INFO the
+EMAIL or PHONE property value (or nil)."
+ (with-current-buffer buffer
+ (org-map-entries
+ (lambda ()
+ (list (nth 4 (org-heading-components))
+ (point)
+ (or (org-entry-get nil "EMAIL")
+ (org-entry-get nil "PHONE"))))
+ nil nil)))
+
(defun cj/org-contacts-find ()
- "Find and open a contact."
+ "Find a contact and jump to its heading.
+Collect the contact headings before prompting, so cancelling the prompt
+leaves point where it was, and jump to the selected heading's stored
+position instead of a text search that could land inside another entry."
(interactive)
- (find-file contacts-file)
- (goto-char (point-min))
- (let* ((alist (org-map-entries
- (lambda ()
- (cons (nth 4 (org-heading-components))
- (or (org-entry-get nil "EMAIL")
- (org-entry-get nil "PHONE"))))
- nil (list contacts-file)))
+ (let* ((buf (find-file-noselect contacts-file))
+ (alist (cj/--org-contacts-collect buf))
(contact (completing-read
"Find contact: "
(cj/completion-table-annotated
'contact
(lambda (cand)
- (let ((info (cdr (assoc cand alist))))
+ (let ((info (nth 2 (assoc cand alist))))
(when (and info (> (length info) 0))
(concat " " (propertize info 'face
'completions-annotations)))))
- alist))))
- (goto-char (point-min))
- (search-forward contact)
+ alist)
+ nil t)))
+ (switch-to-buffer buf)
+ (goto-char (nth 1 (assoc contact alist)))
(org-fold-show-entry)
(org-reveal)))