Skip to content

Instantly share code, notes, and snippets.

@karthink
Created January 21, 2024 04:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karthink/4b6f1d37672b704841b2c5fc944d9c73 to your computer and use it in GitHub Desktop.
Save karthink/4b6f1d37672b704841b2c5fc944d9c73 to your computer and use it in GitHub Desktop.
(require 'org-pcomplete)
(require 'org-compat)
(eval-when-compile (require 'cl-lib))
(defun pcomplete/org-mode/file-option/bibliography ()
"Complete arguments for the #+BIBLIOGRAPHY file option."
(require 'oc)
(pcomplete-here (append
(mapcar (lambda (bibfile)
(propertize bibfile
'pcomplete-annotation
"org-cite's global bibliography"))
(org-ensure-list org-cite-global-bibliography))
(directory-files
default-directory nil
"\\.\\(?:json\\|bib\\)$"))))
(defvar org-pcomplete-extra--export-processors
(let (beg lib procdata)
(with-temp-buffer
(dolist (dir load-path procdata)
(dolist (file (ignore-errors (directory-files dir 'full "^oc-\\(.*\\).el$" 'nosort)))
(string-match "oc-\\(.*\\).el$" file)
(setq lib (match-string 1 file))
(save-excursion (insert-file-contents file nil 1 100 'replace))
(when (re-search-forward "---" nil t)
(setq beg (point))
(when (re-search-forward (rx (or eol (seq (* space) "-*-"))))
(goto-char (match-beginning 0))
(setf (alist-get lib procdata nil nil #'equal)
(concat (string-trim (buffer-substring beg (point)))))))))))
"Completion data for available citation export processors.")
(defvar org-pcomplete-extra--bibliography-styles
'(("bibtex" "abbrv" "acm" "alpha" "apalike" "ieeetr" "plain" "siam" "unsrt")
("basic" "plain" "numeric" "author-year")
("natbib" "dinat" "plainnat" "abbrvnat" "unsrtnat" "rusnat" "ksfh_nat")
("biblatex" "numeric" "alphabetic" "authoryear" "authortitle" "verbose" "reading" "draft")))
(defun pcomplete/org-mode/file-option/cite_export ()
";TODO: "
(require 'oc)
(pcomplete-here* (mapcar
(lambda (proc)
(message "index: %S args: %S" pcomplete-index pcomplete-args)
(propertize (car proc)
'pcomplete-annotation
(cdr proc)))
org-pcomplete-extra--export-processors))
(when (and (= pcomplete-index 2)
(pcomplete-match
(regexp-opt (mapcar #'car org-pcomplete-extra--export-processors))
1))
(pcomplete-here*
(mapcar (lambda (cand) (propertize cand 'pcomplete-annotation " bibliography style"))
(cdr (assoc (nth 1 pcomplete-args) org-pcomplete-extra--bibliography-styles)))))
(when (= pcomplete-last 3)
(when-let* ((style (intern (nth 1 pcomplete-args)))
(processor (seq-find (lambda (p) (eq style (org-cite-processor-name p)))
org-cite--processors))
(styles (org-cite-processor-cite-styles processor))
(styles-annotated (mapcar (lambda (s) (propertize
(caar s)
'pcomplete-annotation
" citation style"
'pcomplete-help
"Test string"))
(cl-typecase styles
(function (funcall styles))
(symbol (symbol-value styles))
(t styles)))))
(pcomplete-here* styles-annotated))))
(provide 'org-pcomplete-extra)
;;; org-pcomplete-extra.el ends here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment