update packages

This commit is contained in:
2025-11-25 19:52:03 +01:00
parent 14ba373378
commit dbbae92267
280 changed files with 13451 additions and 11207 deletions

View File

@@ -26,17 +26,193 @@
(require 'org)
(eval-and-compile (require 'org-macs))
(require 'subr-x) ; for string-trim and string-blank-p
(defvar org-ref-cite-types)
(defvar pdftotext-executable)
(declare-function 'org-ref-get-bibtex-key-and-file "org-ref-core.el")
(declare-function 'org-ref-find-bibliography "org-ref-core.el")
(declare-function 'org-ref-bib-citation "org-ref-core.el")
(declare-function 'org-ref-get-bibtex-key-under-cursor "org-ref-core.el")
(declare-function org-ref-get-bibtex-key-and-file "org-ref-core.el")
(declare-function org-ref-find-bibliography "org-ref-core.el")
(declare-function org-ref-bib-citation "org-ref-core.el")
(declare-function org-ref-get-bibtex-key-under-cursor "org-ref-core.el")
(declare-function org-ref-parse-cite-path "org-ref-citation-links.el")
(declare-function org-ref-get-labels "org-ref-ref-links.el")
;; org-element functions (org.el)
(declare-function org-element-parse-buffer "org-element")
(declare-function org-element-map "org-element")
(declare-function org-element-property "org-element")
(declare-function org-mark-ring-push "org")
;; bibtex functions
(declare-function bibtex-kill-entry "bibtex")
(declare-function bibtex-validate "bibtex")
(declare-function bibtex-global-key-alist "bibtex")
(declare-function bibtex-autokey-get-field "bibtex")
(declare-function bibtex-search-entry "bibtex")
(declare-function bibtex-set-dialect "bibtex")
(declare-function bibtex-copy-entry-as-kill "bibtex")
(declare-function parsebib-find-bibtex-dialect "parsebib")
;; bibtex-completion functions
(declare-function bibtex-completion-get-entry "bibtex-completion")
(declare-function bibtex-completion-get-value "bibtex-completion")
(declare-function bibtex-completion-show-entry "bibtex-completion")
(declare-function bibtex-completion-edit-notes "bibtex-completion")
(declare-function bibtex-completion-find-pdf "bibtex-completion")
(declare-function bibtex-completion-find-pdf-in-library "bibtex-completion")
(declare-function bibtex-completion-apa-format-reference "bibtex-completion")
;; doi-utils functions
(declare-function doi-utils-ads "doi-utils")
(declare-function doi-utils-wos "doi-utils")
(declare-function doi-utils-wos-citing "doi-utils")
(declare-function doi-utils-wos-related "doi-utils")
(declare-function doi-utils-pubmed "doi-utils")
(declare-function doi-utils-crossref "doi-utils")
(declare-function doi-utils-get-bibtex-entry-pdf "doi-utils")
;; other functions
(declare-function biblio-lookup "biblio")
(declare-function message-goto-body "message")
(declare-function message-goto-subject "message")
(declare-function org-ref-bibtex-get-file-move-func "org-ref-bibtex")
;;; Code:
;;** Dash.el replacement utilities
;; These functions replace dash.el dependencies with native Emacs equivalents.
;; They use seq.el (Emacs 25+) and cl-lib (built-in).
(defun org-ref--flatten-list (list)
"Flatten nested LIST structure.
Compatible replacement for dash's `-flatten'.
For Emacs 27+, consider using `flatten-tree' instead."
(cond ((null list) nil)
((listp list)
(append (org-ref--flatten-list (car list))
(org-ref--flatten-list (cdr list))))
(t (list list))))
(defun org-ref--split-at (n list)
"Split LIST at position N, returning (FIRST REST).
Compatible replacement for dash's `-split-at'."
(list (seq-take list n) (seq-drop list n)))
(defun org-ref--remove-at-indices (indices list)
"Remove elements at INDICES from LIST.
Compatible replacement for dash's `-remove-at-indices'."
(cl-loop for item in list
for i from 0
unless (member i indices)
collect item))
(defun org-ref--remove-at (index list)
"Remove element at INDEX from LIST.
Compatible replacement for dash's `-remove-at'."
(append (seq-take list index)
(seq-drop list (1+ index))))
(defun org-ref--insert-at (index element list)
"Insert ELEMENT at INDEX in LIST.
Compatible replacement for dash's `-insert-at'."
(append (seq-take list index)
(list element)
(seq-drop list index)))
;;** S.el replacement utilities
;; These functions replace s.el dependencies with native Emacs equivalents.
;; Most use built-in functions, some require subr-x (Emacs 24.4+).
(defun org-ref--format-template (template alist)
"Format TEMPLATE string replacing ${key} with values from ALIST.
ALIST should be an association list of (KEY . VALUE) pairs where
KEY is a string. If a key in the template is not found in ALIST,
it is replaced with an empty string.
Compatible replacement for s-format with ${var} template syntax."
(let ((result template))
(dolist (pair alist)
(let* ((key (car pair))
(value (cdr pair))
(pattern (format "${%s}" key))
(replacement (if value (format "%s" value) "")))
(setq result (string-replace pattern replacement result))))
result))
(defun org-ref--string-match (regexp string &optional start)
"Match REGEXP against STRING and return list of match groups.
Returns a list where the first element is the entire match,
and subsequent elements are the captured groups (subexpressions).
Returns nil if no match is found.
Optional START specifies where to start searching in STRING.
Compatible replacement for s-match."
(when (string-match regexp string start)
(let ((result nil)
(i 0))
(while (match-beginning i)
(push (match-string i string) result)
(setq i (1+ i)))
(nreverse result))))
;;** F.el replacement utilities
;; These functions replace f.el dependencies with native Emacs equivalents.
;; Uses file-name-extension, directory-files, and file-name-concat (Emacs 28+).
(defun org-ref--file-ext-p (file ext)
"Return t if FILE has extension EXT.
EXT should not include the dot and comparison is case-insensitive.
Compatible replacement for f-ext?."
(when file
(string= (downcase (or (file-name-extension file) ""))
(downcase ext))))
(defun org-ref--directory-files (directory predicate)
"Return files in DIRECTORY matching PREDICATE.
PREDICATE is a function that takes a filename and returns non-nil
if the file should be included. Excludes . and .. entries.
Compatible replacement for f-entries."
(when (file-directory-p directory)
(seq-filter predicate
(directory-files directory t "\\`[^.]"))))
(defun org-ref--file-join (&rest parts)
"Join PARTS into a file path.
Uses file-name-concat if available (Emacs 28+), otherwise uses
expand-file-name for compatibility with older Emacs versions.
Compatible replacement for f-join."
(if (fboundp 'file-name-concat)
(apply #'file-name-concat parts)
;; Fallback for Emacs < 28
(let ((path (car parts)))
(dolist (part (cdr parts))
(setq path (expand-file-name part path)))
path)))
;;** bibtex-completion-bibliography utilities
(defvar bibtex-completion-bibliography)
(defun org-ref-normalize-bibtex-completion-bibliography ()
"Return `bibtex-completion-bibliography' as a list of strings.
This function handles three cases:
1. If it's a function, call it and return the result
2. If it's a list, return it as-is
3. If it's a string, return it wrapped in a list
This ensures consistent handling across org-ref functions."
(cond
((functionp bibtex-completion-bibliography)
(funcall bibtex-completion-bibliography))
((listp bibtex-completion-bibliography)
bibtex-completion-bibliography)
(t
(list bibtex-completion-bibliography))))
;;** org-ref functions
;;;###autoload
(defun org-ref-version ()
"Provide a version string for org-ref.
@@ -57,7 +233,7 @@ Copies the string to the clipboard."
(goto-char (point-min))
(if
(re-search-forward ";; Version:" nil t)
(s-trim (buffer-substring (point)
(string-trim (buffer-substring (point)
(line-end-position)))
org-ref-dir)))
@@ -69,8 +245,8 @@ Copies the string to the clipboard."
(or (file-directory-p ".git") (file-exists-p ".git"))
(= 0 (shell-command "git rev-parse --git-dir")))
(format "%s in %s"
(s-trim (shell-command-to-string "git rev-parse HEAD"))
(s-trim (shell-command-to-string "git rev-parse --show-toplevel"))))))
(string-trim (shell-command-to-string "git rev-parse HEAD"))
(string-trim (shell-command-to-string "git rev-parse --show-toplevel"))))))
(setq version-string (format "org-ref: Version %s%s"
org-version
@@ -106,7 +282,7 @@ Opens https://github.com/jkitchin/org-ref/issues/new."
(erase-buffer)
(org-mode)
(insert
(s-format "#+TITLE: org-ref debug
(org-ref--format-template "#+TITLE: org-ref debug
${org-ref-version}
@@ -152,7 +328,6 @@ You set =pdftotext-executable= to ${pdftotext-executable} (exists: ${pdftotext-e
- org-latex-pdf-process :: ${org-latex-pdf-process}
"
'aget
`(("org-ref-version" . ,(org-ref-version))
("org-latex-pdf-process" . ,(format "%S" org-latex-pdf-process))
("org-ref-location" . ,(format "%s" (locate-library "org-ref")))
@@ -332,13 +507,13 @@ in a directory. Optional PREFIX argument toggles between
;; I like this better than bibtex-url which does not always find
;; the urls
(catch 'done
(let ((url (s-trim (bibtex-autokey-get-field "url"))))
(unless (s-blank? url)
(let ((url (string-trim (bibtex-autokey-get-field "url"))))
(unless (string-blank-p url)
(browse-url url)
(throw 'done nil)))
(let ((doi (s-trim (bibtex-autokey-get-field "doi"))))
(unless (s-blank? doi)
(let ((doi (string-trim (bibtex-autokey-get-field "doi"))))
(unless (string-blank-p doi)
(if (string-match "^http" doi)
(browse-url doi)
(browse-url (format "http://dx.doi.org/%s" doi)))
@@ -594,8 +769,14 @@ if FORCE is non-nil reparse the buffer no matter what."
(lambda (x)
(file-name-directory (file-truename x)))
bibtex-files ":"))
(bibtex-keys (mapcar (lambda (x) (car x))
(bibtex-global-key-alist)))
(bibtex-key-alist (bibtex-global-key-alist))
;; Handle both old alist format and new completion table format
(bibtex-keys (if (functionp bibtex-key-alist)
;; New format: completion table (function)
;; Call with nil to get all completions
(all-completions "" bibtex-key-alist)
;; Old format: alist
(mapcar (lambda (x) (car x)) bibtex-key-alist)))
(bad-citations '()))
(org-element-map (org-ref-parse-buffer) 'link
@@ -629,7 +810,7 @@ if FORCE is non-nil reparse the buffer no matter what."
(when (assoc (plist-get plist ':type) org-ref-ref-types)
(cl-loop for label in (split-string (plist-get plist :path) ",")
do
(unless (-contains? labels label)
(unless (member label labels)
(goto-char (org-element-property :begin link))
(add-to-list
'bad-refs
@@ -647,7 +828,7 @@ if FORCE is non-nil reparse the buffer no matter what."
(goto-char (point-min))
(while (re-search-forward rx nil t)
(cl-pushnew (match-string-no-properties 1) labels))))
(-count (lambda (x) (and (stringp x) (string= x label))) labels)))
(cl-count-if (lambda (x) (and (stringp x) (string= x label))) labels)))
(defun org-ref-bad-label-candidates ()
@@ -877,7 +1058,7 @@ if FORCE is non-nil reparse the buffer no matter what."
bib-candidates)))))
;; check for multiple bibliography links
(let* ((bib-links (-filter
(let* ((bib-links (seq-filter
(lambda (el)
(string= (org-element-property :type el) "bibliography"))
(org-element-map (org-element-parse-buffer) 'link 'identity)))
@@ -931,7 +1112,7 @@ if FORCE is non-nil reparse the buffer no matter what."
(goto-char (point-min))
(while (re-search-forward "^@\\(.*?\\)[({]" nil t)
(when (and (not (string= "string" (downcase (match-string-no-properties 1))))
(not (member (s-trim (downcase (match-string-no-properties 1)))
(not (member (string-trim (downcase (match-string-no-properties 1)))
(cdr (assoc bibtex-dialect
(list
(cons 'BibTeX (mapcar (lambda (e) (downcase (car e)))
@@ -1008,7 +1189,7 @@ if FORCE is non-nil reparse the buffer no matter what."
(org-element-property :path el))))))
(cl-loop for (label . p) in matches
do
(when (and label (not (-contains? refs label)))
(when (and label (not (member label refs)))
(cl-pushnew
(cons label (set-marker (make-marker) p))
unreferenced-labels)))))))
@@ -1160,9 +1341,9 @@ if FORCE is non-nil reparse the buffer no matter what."
(insert "\n* Warnings\n")
(if (get-buffer "*Warnings*")
(cl-loop for line in (s-split "\n" (with-current-buffer "*Warnings*"
(cl-loop for line in (split-string "\n" (with-current-buffer "*Warnings*"
(buffer-string)))
if (s-starts-with? "Warning (org-ref):" line)
if (string-prefix-p "Warning (org-ref):" line)
do
(insert " - " line "\n"))
(insert "- No (org-ref) Warnings found."))