Skip to content

Commit

Permalink
General cleanup (version 1.7)
Browse files Browse the repository at this point in the history
  • Loading branch information
pprevos committed Oct 14, 2023
1 parent b4d0027 commit c5d3a35
Showing 1 changed file with 25 additions and 24 deletions.
49 changes: 25 additions & 24 deletions citar-denote.el
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ Configurable with `citar-denote-keyword'.")
(delete-dups keywords)))

(defun citar-denote--add-reference (citekey)
"Add reference line with CITEKEY in the front matter of the Denote file.
"Add reference line with CITEKEY in front matter of the Denote file.
`citar-denote-add-citekey' is the interactive version of this function."
(let ((file-type citar-denote-file-type))
Expand All @@ -203,6 +203,7 @@ Configurable with `citar-denote-keyword'.")
(buffer-substring-no-properties (point) (line-end-position))
trims trims) ";")))))

;;;###autoload
(defun citar-denote--get-notes (&optional citekeys)
"Return has table of Denote files associated with the CITEKEYS citation keys.
If CITEKEYS is omitted, return all Denote files tagged with
Expand Down Expand Up @@ -231,6 +232,7 @@ If CITEKEYS is omitted, return all Denote files tagged with
(mapcar #'xref-match-item-location
(xref-matches-in-files (format "@%s" citekey) files))))))

;;;###autoload
(defun citar-denote--has-notes ()
"Return a list of all citekeys referenced in a Denote file.
Expand Down Expand Up @@ -320,14 +322,13 @@ Based on `citar-denote-title-format'."
:multiple t
:filter (citar-denote--has-citekeys unused))))

;; Interactive functions

;;;###autoload
(defun citar-denote-create-note (citekey &optional _entry)
(defun citar-denote--create-note (citekey &optional _entry)
"Create a bibliographic note for CITEKEY with properties ENTRY.
The file type for the new note is determined by `citar-denote-file-type'.
The title of the new note is set by `citar-denote-title-format'.
The file type is determined by `citar-denote-file-type'.
The title format is set by `citar-denote-title-format'.
When `citar-denote-subdir' is non-nil, prompt for a subdirectory."
(denote
Expand All @@ -337,6 +338,8 @@ When `citar-denote-subdir' is non-nil, prompt for a subdirectory."
(when citar-denote-subdir (denote-subdirectory-prompt)))
(citar-denote--add-reference citekey))

;; Interactive functions

;;;###autoload
(defun citar-denote-open-note ()
"Open a bibliographic note using Citar."
Expand Down Expand Up @@ -420,19 +423,19 @@ When more than one bibliographic item is referenced, select item first."
:filter
(citar-denote--has-citekeys citekeys)))))
(let ((new-citekeys (delete selected citekeys)))
(save-excursion
;; Remove references line
(goto-char (point-min))
(re-search-forward
(citar-denote--reference-regex file-type))
(move-beginning-of-line nil)
(kill-line 1)
;; Add new line or remove file tags when applicable
(if (> (length new-citekeys) 0)
(citar-denote--add-reference
(mapconcat 'identity new-citekeys ";"))
(citar-denote--remove-bibkey file))
(save-buffer)))
(save-excursion
;; Remove references line
(goto-char (point-min))
(re-search-forward
(citar-denote--reference-regex file-type))
(move-beginning-of-line nil)
(kill-line 1)
;; Add new line or remove file tags when applicable
(if (> (length new-citekeys) 0)
(citar-denote--add-reference
(mapconcat 'identity new-citekeys ";"))
(citar-denote--remove-bibkey file))
(save-buffer)))
(user-error "No references in this buffer, or not a Denote file")))

;;;###autoload
Expand Down Expand Up @@ -512,11 +515,9 @@ When more than one bibliographic item is referenced, select item first."

;;;###autoload
(defun citar-denote-reference-nocite ()
"Create note for bibliographic entries not cited or referenced in Denote files.
If multiple entries are selected, the note is created for the first entry."
"Create note for bibliographic entries not cited or referenced in Denote files."
(interactive)
(citar-create-note (car (citar-denote--get-nocite))))
(citar-denote--create-note (citar-denote--get-nocite)))

;; Citar integration

Expand All @@ -526,7 +527,7 @@ If multiple entries are selected, the note is created for the first entry."
:items #'citar-denote--get-notes
:hasitems #'citar-denote--has-notes
:open #'find-file
:create #'citar-denote-create-note)
:create #'citar-denote--create-note)
"Instructing citar to use citar-denote functions.")

(defconst citar-denote-orig-source
Expand Down

0 comments on commit c5d3a35

Please sign in to comment.