emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[org-cite] request for coding help on a capf to insert citation key


From: Bruce D'Arcus
Subject: [org-cite] request for coding help on a capf to insert citation key
Date: Sat, 5 Jun 2021 12:13:04 -0400

I've been struggling with this for a while, and am a mediocre programmer, so thought I'd ask for help here.

I started out writing this generate capf to insert citation keys, but have decided to make it specific to org-cite.

Here's the commented function.

TIA.

Note the "candidates" variable accesses a cached alist, of the form:

("long search string with title, author, etc." . "citekey")

So I want the user to be able to select on the car, but insert the cdr.


--8<---------------cut here---------------start------------->8---
(defun bibtex-actions-complete-key-at-point-oc ()
    "Complete org-cite citation key at point.

When inserting '@' in a buffer the capf UI will present user with
a list of entries, from which they can narrow against a string
which includes title, author, etc., and then select one.  This
function will then return the key 'key', resulting in '@key' at
point."
    ;; FIX exit-function is wrong; results in "no match"
    ;; TODO tighten this regex for org-cite
  (when (looking-back "@[a-zA-Z]+" 5)
    (let* ((candidates (bibtex-actions--get-candidates))
           (begin (save-excursion (backward-word) (point)))
           (end (point)))
      (list begin end candidates :exclusive 'no
            :exit-function
            (lambda (chosen status)
              (when (eq status 'finished)
                (cdr (assoc chosen candidates))))))))
--8<---------------cut here---------------end--------------->8---


reply via email to

[Prev in Thread] Current Thread [Next in Thread]