From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id IDfLBcKiu2CzcwEAgWs5BA (envelope-from ) for ; Sat, 05 Jun 2021 18:13:54 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id WOoWAcKiu2BqRwAA1q6Kng (envelope-from ) for ; Sat, 05 Jun 2021 16:13:54 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 713281F8BF for ; Sat, 5 Jun 2021 18:13:53 +0200 (CEST) Received: from localhost ([::1]:46186 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lpYvn-0006oR-CI for larch@yhetil.org; Sat, 05 Jun 2021 12:13:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45904) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lpYvG-0006ns-Ps for emacs-orgmode@gnu.org; Sat, 05 Jun 2021 12:13:18 -0400 Received: from mail-wr1-x42a.google.com ([2a00:1450:4864:20::42a]:35572) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lpYvF-0004Hp-3I for emacs-orgmode@gnu.org; Sat, 05 Jun 2021 12:13:18 -0400 Received: by mail-wr1-x42a.google.com with SMTP id m18so12358640wrv.2 for ; Sat, 05 Jun 2021 09:13:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=IDrfkHRlkW9+mtJ+gZdJJGSVPA0iR7jURfNSdLdP6d8=; b=R7KN3JfFvLsfEoVS1VRnzBxWPqA6Z7P0hhNixdaHS4pWc0dd9wr8WX8sTUUe/xT6XH UH3ySDp487xp45lIxMhIbXJpQFWB+AkMZUtX0MMEe4omr29X8zXjUom4dPQ/ri2mA/FW Ggu5D2O0SpoFg05zFzOspGDQzY5GPB/hjg569fLg3xtYkx4MU4hNS7sYIigNU8XahkV3 0rdVlLBEpNnnr2RytwcQDjTA4B4sDzUddg0Cfj5NkJjfFVMRTt51nR5dH4b82xInmrac Q/R3oPeJPZMLes/0opEv0UT2iC1GYMl7UA+geNeH1qL1luyPg/Le1H95nVfXioabHFeQ 9BdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=IDrfkHRlkW9+mtJ+gZdJJGSVPA0iR7jURfNSdLdP6d8=; b=qUOG619dvB2RTtC+W65c3Ut/PwjufExekzkghgP1PUnzH7r7gL9aJzJRyDmOol17vs GTeGh6aKHKmzHzwc5q06WuxNZIOTIx0W340RU9KJ3pg8SlXFz4q0G7u5gnrfQ7WjJ1N1 obqRgzZ3eI1edbv4bOSJXgJ/LnkQC7vGMvStEWANiPCKYIa+7yrewwA6eBDYaoXk/nhd m0sOmY5Jzarq0HnwK/vAhwaT7jFB7TAtXtl+x548d+44PElb90xW/k/uhlFksz0n1MGs BMUoO3nr+EN2ZIwgQmRgipI+9Rgxu6z7alf8q1s3ao9PK2XbMlgKmO/ZfXw2PokShiM2 mVLw== X-Gm-Message-State: AOAM5314XIqYzfDXxZmBpaA53Qg3Qiqi0RFpYApsz90PD5W5Ropoka4x jF+z1QhqCHuf7AS5urILHGq3MUU3lZfpKhvnernhyYoI4hg= X-Google-Smtp-Source: ABdhPJxHc48rkeg+axilzKklIv8bO0Qe3RuE9E/Mm4+JtRvLXoXsllEZ/0ubHT7/dAM/Azw5qZfdDH7zigZaW8gRHH8= X-Received: by 2002:a5d:4203:: with SMTP id n3mr9219374wrq.132.1622909594934; Sat, 05 Jun 2021 09:13:14 -0700 (PDT) MIME-Version: 1.0 From: "Bruce D'Arcus" Date: Sat, 5 Jun 2021 12:13:04 -0400 Message-ID: Subject: [org-cite] request for coding help on a capf to insert citation key To: org-mode-email Content-Type: multipart/alternative; boundary="000000000000e8a2d005c4071506" Received-SPF: pass client-ip=2a00:1450:4864:20::42a; envelope-from=bdarcus@gmail.com; helo=mail-wr1-x42a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1622909633; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=IDrfkHRlkW9+mtJ+gZdJJGSVPA0iR7jURfNSdLdP6d8=; b=SQnMEsI6FnjcAG45jXpRraZXtTH09ZYRLIcCeAF/gPXRBmvJ582AJdeDxLwaQ1iRqRjgPO z6oRHjNU1lX2UfoHW/yiHvlAGqFk9tfGxGb/LQXR1/ZPf0PvI+rmD4OlYiHgicso8YPa2w nrAMP3YyrglMvaTVi6Qiui4qVe3Xalr+dTfL1qXp0Zj5ATcYaBjma6z4qUXeHp/q+r/a9U LkCUAaP90Xf8IwmFke4npxPMobpTfTEXKAGjEDeMYpcdONRQ5H40y09QAXQDiLuOHajcC9 gN0hWFRXKbm4+E5quoESnT+a4yn/zw+ZG/QvCU1mHK94cSTTRzZqOo6w+3IDNA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1622909633; a=rsa-sha256; cv=none; b=aat90PQlh3ViEHnFkxIzA4kwrXk13tMQYJrDzJJI0/pRbCgTa6KgCTtjcnaD73sn/3tef4 7J7fdQCHZirWinL53PDzbzspf6Mw6GS0hyfC9zKDWUrRGYzBYvVJAkZn8+QwAseZHNDfqk cdzxd+nkhpaZ7v39FY490Ljd2eVwg6kv4nnYIQveFBtj2OyadW/0zXInz6WYwo00+Y3GpZ db8YBjC6LDa/Jj91QMPAVDsV8rLaUOV1SWLbyRxWdztWmpCKwpqVstsHOhSjvfIfhN4zBN UfirEM065gD/4exf0KNbtR9ZQx+K9O7qcrOZe+LtsJVxh02BYQ8fsPzp//eDbg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=R7KN3JfF; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Spam-Score: -3.13 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=R7KN3JfF; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Queue-Id: 713281F8BF X-Spam-Score: -3.13 X-Migadu-Scanner: scn1.migadu.com X-TUID: 6U2CSzV3Qy9Y --000000000000e8a2d005c4071506 Content-Type: text/plain; charset="UTF-8" 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--- --000000000000e8a2d005c4071506 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
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 fo= rm:

("long search string with title, author, etc." . "citekey&qu= ot;)

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 ()
=C2=A0 =C2=A0 "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.=C2=A0 This
function will then return the key 'key', resulting in '@key'= ; at
point."
=C2=A0 =C2=A0 ;; FIX exit-function is wrong; results in "no match"= ;
=C2=A0 =C2=A0 ;; TODO tighten this regex for org-cite
=C2=A0 (when (looking-back "@[a-zA-Z]+" 5)
=C2=A0 =C2=A0 (let* ((candidates (bibtex-actions--get-candidates))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(begin (save-excursion (backward-w= ord) (point)))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(end (point)))
=C2=A0 =C2=A0 =C2=A0 (list begin end candidates :exclusive 'no
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 :exit-function
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (lambda (chosen status)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (when (eq status 'fini= shed)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (cdr (assoc chosen = candidates))))))))
--8<---------------cut here---------------end--------------->8---

--000000000000e8a2d005c4071506--