Skip to content

Commit

Permalink
citar-open and citar-open-notes now allow creating notes.
Browse files Browse the repository at this point in the history
Both these functions now offer to create notes for the chosen keys. The
customization variable `citar-open-always-create-note` controls whether the
"create" option is offered only for keys that don't already have notes.

This new feature is implemented as an extra option to `citar--select-resource`,
which has now learned about the `create-note` pseudo-resource type. The
`citar-open-notes` and `citar--open-resource` also learned to create new notes.

Other Changes

There is a new command called `citar-open-note`, which prompts to select a note
from all the available notes and opens it. It can also be called
non-interactively with a note returned by `citar-get-notes`, which is its
primary purpose.

The customization variable `citar-open-prompt` can now be set to a list of
commands that will always prompt before selecting resources. The default is to
always prompt for `citar-open`, `citar-attach-files`, and `citar-open-note`.
  • Loading branch information
roshanshariff committed Jul 18, 2022
1 parent 0da2458 commit 763a83d
Show file tree
Hide file tree
Showing 4 changed files with 212 additions and 116 deletions.
13 changes: 3 additions & 10 deletions citar-cache.el
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

(declare-function citar--get-template "citar")
(declare-function citar--fields-to-parse "citar")
(declare-function citar--prepend-key "citar")

(defvar citar-ellipsis)

Expand Down Expand Up @@ -254,16 +255,8 @@ PROPS."
(lambda (citekey entry)
(let* ((preformat (citar-format--preformat fieldspecs entry
t citar-ellipsis))
;; CSL-JSON lets citekey be an arbitrary string. Quote it if...
(keyquoted (if (or (string-empty-p citekey) ; ... it's empty,
(= ?\" (aref citekey 0)) ; ... starts with ",
(seq-contains-p citekey ?\s #'=)) ; ... or has a space
(prin1-to-string citekey)
citekey))
(prefix (propertize (concat keyquoted (when (cdr preformat) " "))
'invisible t)))
(setcdr preformat (cons (concat prefix (cadr preformat))
(cddr preformat)))
(withkey (citar--prepend-candidate-citekey citekey (cadr preformat))))
(setcdr preformat (cons withkey (cddr preformat)))
(puthash citekey preformat preformatted)))
entries)))

Expand Down
3 changes: 2 additions & 1 deletion citar-embark.el
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@

(defun citar-embark--candidate-transformer (_type target)
"Look up key for a citar-reference TYPE and TARGET."
(cons 'citar-reference (citar--extract-candidate-citekey target)))
(or (get-text-property 0 'multi-category target)
(cons 'citar-reference (citar--extract-candidate-citekey target))))

(defun citar-embark--selected ()
"Return selected candidates from `citar--select-multiple' for embark."
Expand Down
10 changes: 6 additions & 4 deletions citar-format.el
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
;;; Formatting bibliography entries


(cl-defun citar-format--entry (format-string entry &optional width
&key hide-elided ellipsis)
"Format ENTRY according to FORMAT-STRING."
(let* ((fieldspecs (citar-format--parse format-string))
(cl-defun citar-format--entry (format entry &optional width
&key hide-elided ellipsis)
"Format ENTRY according to FORMAT.
FORMAT may be either a format string or a parsed format string as
returned by `citar-format--parse'."
(let* ((fieldspecs (if (stringp format) (citar-format--parse format) format))
(preform (citar-format--preformat fieldspecs entry
hide-elided ellipsis)))
(if width
Expand Down
Loading

0 comments on commit 763a83d

Please sign in to comment.