I could not find a way to do this in the manual, so I programmed a solution in 3 steps:
- Retrieve the headings of the org file
contacts.org. Although a very simple requirement, no function seems to do that in the manual, so here's mine:
(defun get-headers (org-filename)
"Get the headers of the org-file located at <org-filename>"
(with-current-buffer (find-file-noselect org-filename)
(let ((parsetree (org-element-parse-buffer 'headline)))
(org-element-map parsetree 'headline
(lambda (hl) (org-element-property :title hl))))))
which you would call, for instance, with
(get-headers "~/contacts.org") :
("Contact" "John DOE" "Alicia PING" "Bob DELTA").
- Building from that, here's how to create a quick link to a contact, from an org-file:
(defun link-to-contact ()
"Quickly insert a link to one of the contacts in ~/contacts.org, with autocompletion."
(completing-read "Link to contact: " (cdr (get-headers "~/contacts.org")))))
(insert (format "[[file:~/contacts.org::*%s][%s]]" contact contact))))
- And here's how to quickly go there:
(defun goto-contact ()
"Quickly navigate to a contact in ~/contacs.org"
(completing-read "Go to contact: " (cdr (get-headers "~/contacts.org")))))
(pop-to-buffer (find-file-noselect "~/contacts.org"))
(search-forward (format "** %s" contact))))