Org-mode mailing list
 help / color / mirror / Atom feed
* [org-cite] request for coding help on a capf to insert citation key
@ 2021-06-05 16:13 Bruce D'Arcus
  2021-06-05 21:14 ` Bruce D'Arcus
  0 siblings, 1 reply; 3+ messages in thread
From: Bruce D'Arcus @ 2021-06-05 16:13 UTC (permalink / raw)
  To: org-mode-email

[-- Attachment #1: Type: text/plain, Size: 1451 bytes --]

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---

[-- Attachment #2: Type: text/html, Size: 1827 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [org-cite] request for coding help on a capf to insert citation key
  2021-06-05 16:13 [org-cite] request for coding help on a capf to insert citation key Bruce D'Arcus
@ 2021-06-05 21:14 ` Bruce D'Arcus
  2021-06-06 16:21   ` Bruce D'Arcus
  0 siblings, 1 reply; 3+ messages in thread
From: Bruce D'Arcus @ 2021-06-05 21:14 UTC (permalink / raw)
  To: org-mode-email

Round 2, which should address the "regex" todo.

--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"
  (when (and (eq major-mode 'org-mode)
             (eq (car (org-element-context)) 'citation))
    (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---


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [org-cite] request for coding help on a capf to insert citation key
  2021-06-05 21:14 ` Bruce D'Arcus
@ 2021-06-06 16:21   ` Bruce D'Arcus
  0 siblings, 0 replies; 3+ messages in thread
From: Bruce D'Arcus @ 2021-06-06 16:21 UTC (permalink / raw)
  To: org-mode-email

One other idea, Nicolas:

Is there room to include a org-cite somehow, so that one had a defcustom like:

(setq org-cite-complete-key-candidates my-candidates)
;; here override default with results from my package
(setq my-candidates (bibtex-actions--get-candidates))

... and default could be some simple thing in oc-basic?

If not, totally fine of course, but I thought I'd mention it as I'm
trying to figure this out.

Bruce

On Sat, Jun 5, 2021 at 5:14 PM Bruce D'Arcus <bdarcus@gmail.com> wrote:
>
> Round 2, which should address the "regex" todo.
>
> --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"
>   (when (and (eq major-mode 'org-mode)
>              (eq (car (org-element-context)) 'citation))
>     (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---


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-06-06 16:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-05 16:13 [org-cite] request for coding help on a capf to insert citation key Bruce D'Arcus
2021-06-05 21:14 ` Bruce D'Arcus
2021-06-06 16:21   ` Bruce D'Arcus

Org-mode mailing list

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://orgmode.org/list/0 list/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 list list/ https://orgmode.org/list \
		emacs-orgmode@gnu.org
	public-inbox-index list

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.yhetil.org/yhetil.emacs.orgmode
	nntp://news.gmane.io/gmane.emacs.orgmode


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git