Skip to content

Commit 5f2cf9b

Browse files
committed
Add insert-edit major mode function
This is a thin wrapper around org-cite-insert in org-mode, citar-latex-insert-citation in latex, and citar-markdown-insert-citation in Markdown. Available under "i" in the embark at-point map.
1 parent 421e67b commit 5f2cf9b

File tree

4 files changed

+42
-5
lines changed

4 files changed

+42
-5
lines changed

citar-latex.el

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,13 @@ inserted."
153153
(citar--insert-keys-comma-separated keys)
154154
(skip-chars-forward "^}") (forward-char 1)))
155155

156+
;;;###autoload
157+
(defun citar-latex-insert-edit (&optional arg)
158+
"Prompt for keys and call `citar-latex-insert-citation.
159+
With ARG non-nil, rebuild the cache before offering candidates."
160+
(citar-latex-insert-citation
161+
(citar--extract-keys (citar-select-refs :rebuild-cache arg))))
162+
156163
(defun citar-latex-is-a-cite-command (command)
157164
"Return element of `citar-latex-cite-commands` containing COMMAND."
158165
(seq-find (lambda (x) (member command (car x)))

citar-markdown.el

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ to the beginning of the citation."
6868
(skip-chars-forward "^;]" (cddr citation))
6969
(insert "; " keyconcat))))))
7070

71+
;;;###autoload
72+
(defun citar-markdown-insert-edit (&optional arg)
73+
"Prompt for keys and call `citar-markdown-insert-citation.
74+
With ARG non-nil, rebuild the cache before offering candidates."
75+
(citar-markdown-insert-citation
76+
(citar--extract-keys (citar-select-refs :rebuild-cache arg))))
77+
7178
(defconst citar-markdown-citation-key-regexp
7279
(concat "-?@" ; @ preceded by optional -
7380
"\\(?:"

citar-org.el

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,12 @@ With PROC list, limit to specific processor(s)."
178178
(mapconcat (lambda (key) (concat "@" key)) keys "; ")))
179179
(user-error "Cannot insert a citation here")))))
180180

181-
(defun citar-org-cite-insert (&rest _args)
182-
"Wrapper for 'org-cite-insert'."
183-
(org-cite-insert current-prefix-arg))
181+
;;;###autoload
182+
(defun citar-org-insert-edit (&optional arg)
183+
"Run `org-cite-insert` with citar insert processor.
184+
ARG is used as the prefix argument."
185+
(let ((org-cite-insert-processor 'citar))
186+
(org-cite-insert arg)))
184187

185188
;;;###autoload
186189
(defun citar-org-follow (_datum _arg)

citar.el

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353

5454
(defvar embark-keymap-alist)
5555
(defvar embark-target-finders)
56+
(defvar embark-pre-action-hooks)
5657
(defvar embark-general-map)
5758
(defvar embark-meta-map)
5859
(defvar citar-org-open-note-function)
@@ -191,16 +192,19 @@ If you use 'org-roam' and 'org-roam-bibtex', you can use
191192
'(((org-mode) .
192193
((local-bib-files . citar-org-local-bib-files)
193194
(insert-citation . citar-org-insert-citation)
195+
(insert-edit . citar-org-insert-edit)
194196
(key-at-point . citar-org-key-at-point)
195197
(citation-at-point . citar-org-citation-at-point)))
196198
((latex-mode) .
197199
((local-bib-files . citar-latex-local-bib-files)
198200
(insert-citation . citar-latex-insert-citation)
201+
(insert-edit . citar-latex-insert-edit)
199202
(key-at-point . citar-latex-key-at-point)
200203
(citation-at-point . citar-latex-citation-at-point)))
201204
((markdown-mode) .
202205
((insert-keys . citar-markdown-insert-keys)
203206
(insert-citation . citar-markdown-insert-citation)
207+
(insert-edit . citar-markdown-insert-edit)
204208
(key-at-point . citar-markdown-key-at-point)
205209
(citation-at-point . citar-markdown-citation-at-point)))
206210
(t .
@@ -223,6 +227,10 @@ insert-citation: the corresponding function should insert a
223227
complete citation from a list of keys at point. If the point is
224228
in a citation, new keys should be added to the citation.
225229
230+
insert-edit: the corresponding function should accept an optional
231+
prefix argument and interactively edit the citation or key at
232+
point.
233+
226234
key-at-point: the corresponding function should return the
227235
citation key at point or nil if there is none. The return value
228236
should be (KEY . BOUNDS), where KEY is a string and BOUNDS is a
@@ -266,8 +274,9 @@ start and end of the citation."
266274
map)
267275
"Keymap for Embark minibuffer actions.")
268276

269-
(defvar citar-buffer-map
277+
(defvar citar-citation-map
270278
(let ((map (make-sparse-keymap)))
279+
(define-key map (kbd "i") (cons "insert or edit" #'citar-insert-edit))
271280
(define-key map (kbd "o") (cons "open source document" #'citar-open))
272281
(define-key map (kbd "e") (cons "open bibtex entry" #'citar-open-entry))
273282
(define-key map (kbd "l") (cons "open source URL or DOI" #'citar-open-link))
@@ -716,7 +725,9 @@ FORMAT-STRING."
716725

717726
(with-eval-after-load 'embark
718727
(add-to-list 'embark-keymap-alist '(citar-reference . citar-map))
719-
(add-to-list 'embark-keymap-alist '(citar-key . citar-buffer-map)))
728+
(add-to-list 'embark-keymap-alist '(citar-key . citar-citation-map))
729+
(add-to-list 'embark-keymap-alist '(citar-citation . citar-citation-map))
730+
(add-to-list 'embark-pre-action-hooks '(citar-insert-edit embark--ignore-target)))
720731

721732
;;; Commands
722733

@@ -861,6 +872,15 @@ With prefix, rebuild the cache before offering candidates."
861872
(message "Citation insertion is not supported for %s" major-mode))
862873
(citar--extract-keys keys-entries)))
863874

875+
(defun citar-insert-edit (&optional arg)
876+
"Edit the citation at point."
877+
(interactive "P")
878+
(citar--major-mode-function
879+
'insert-edit
880+
(lambda (&rest _)
881+
(message "Citation editing is not supported for %s" major-mode))
882+
arg))
883+
864884
;;;###autoload
865885
(defun citar-insert-reference (keys-entries)
866886
"Insert formatted reference(s) associated with the KEYS-ENTRIES.

0 commit comments

Comments
 (0)