forked from mirrors/org-mode
Add helper functions to org-bibtex
* lisp/org-bibtex.el: (org-bibtex-search): New function. (org-bibtex-export-to-kill-ring): New function. Export to kill ring. (org-bibtex-create-in-current-entry): New function (org-bibtex-create): Make it easier to add bib fields to an existing headline (org-bibtex-export-arbitrary-fields) (org-bibtex-treat-headline-as-title): Fix typos (org-bibtex-fleshout): Don't upcase optional field; remove ":" from type completion This patch implements several helper functions: exporting to kill ring, searching only for entries with bib fields, and creating bib fields in an existing headline. It makes the UI of org-bibtex-fleshout more consistent.
This commit is contained in:
parent
3c148beeb7
commit
1918731fdf
|
@ -226,14 +226,14 @@ For example setting to 'BIB_' would allow interoperability with fireforg."
|
||||||
(defcustom org-bibtex-treat-headline-as-title t
|
(defcustom org-bibtex-treat-headline-as-title t
|
||||||
"Treat headline text as title if title property is absent.
|
"Treat headline text as title if title property is absent.
|
||||||
If an entry is missing a title property, use the headline text as
|
If an entry is missing a title property, use the headline text as
|
||||||
the property. If this value is t, `org-bibtex-check` will ignore
|
the property. If this value is t, `org-bibtex-check' will ignore
|
||||||
a missing title field."
|
a missing title field."
|
||||||
:group 'org-bibtex
|
:group 'org-bibtex
|
||||||
:type 'boolean)
|
:type 'boolean)
|
||||||
|
|
||||||
(defcustom org-bibtex-export-arbitrary-fields nil
|
(defcustom org-bibtex-export-arbitrary-fields nil
|
||||||
"When converting to bibtex allow fields not defined in `org-bibtex-fields'.
|
"When converting to bibtex allow fields not defined in `org-bibtex-fields'.
|
||||||
This only has effect if org-bibtex-prefix is defined, so as to
|
This only has effect if `org-bibtex-prefix' is defined, so as to
|
||||||
ensure that other org-properties, such as CATEGORY or LOGGING are
|
ensure that other org-properties, such as CATEGORY or LOGGING are
|
||||||
not placed in the exported bibtex entry."
|
not placed in the exported bibtex entry."
|
||||||
:group 'org-bibtex
|
:group 'org-bibtex
|
||||||
|
@ -303,7 +303,7 @@ This variable is relevant only if `org-bibtex-export-tags-as-keywords` is t."
|
||||||
(type (org-bibtex-get "type"))
|
(type (org-bibtex-get "type"))
|
||||||
(tags (when org-bibtex-tags-are-keywords
|
(tags (when org-bibtex-tags-are-keywords
|
||||||
(delq nil
|
(delq nil
|
||||||
(mapcar
|
(mapcar
|
||||||
(lambda (tag)
|
(lambda (tag)
|
||||||
(unless (member tag
|
(unless (member tag
|
||||||
(append org-bibtex-tags
|
(append org-bibtex-tags
|
||||||
|
@ -318,13 +318,13 @@ This variable is relevant only if `org-bibtex-export-tags-as-keywords` is t."
|
||||||
(remove nil
|
(remove nil
|
||||||
(if (and org-bibtex-export-arbitrary-fields
|
(if (and org-bibtex-export-arbitrary-fields
|
||||||
org-bibtex-prefix)
|
org-bibtex-prefix)
|
||||||
(mapcar
|
(mapcar
|
||||||
(lambda (kv)
|
(lambda (kv)
|
||||||
(let ((key (car kv)) (val (cdr kv)))
|
(let ((key (car kv)) (val (cdr kv)))
|
||||||
(when (and (string-match org-bibtex-prefix key)
|
(when (and (string-match org-bibtex-prefix key)
|
||||||
(not (equalp
|
(not (equalp
|
||||||
(concat org-bibtex-prefix "TYPE") key)))
|
(concat org-bibtex-prefix "TYPE") key)))
|
||||||
(cons (downcase (replace-regexp-in-string
|
(cons (downcase (replace-regexp-in-string
|
||||||
org-bibtex-prefix "" key))
|
org-bibtex-prefix "" key))
|
||||||
val))))
|
val))))
|
||||||
(org-entry-properties nil 'standard))
|
(org-entry-properties nil 'standard))
|
||||||
|
@ -366,7 +366,7 @@ This variable is relevant only if `org-bibtex-export-tags-as-keywords` is t."
|
||||||
(org-bibtex-put org-bibtex-key-property
|
(org-bibtex-put org-bibtex-key-property
|
||||||
(if org-bibtex-autogen-keys
|
(if org-bibtex-autogen-keys
|
||||||
(let* ((entry (org-bibtex-headline))
|
(let* ((entry (org-bibtex-headline))
|
||||||
(key
|
(key
|
||||||
(with-temp-buffer
|
(with-temp-buffer
|
||||||
(insert entry)
|
(insert entry)
|
||||||
(bibtex-generate-autokey))))
|
(bibtex-generate-autokey))))
|
||||||
|
@ -385,7 +385,7 @@ This variable is relevant only if `org-bibtex-export-tags-as-keywords` is t."
|
||||||
With optional argument OPTIONAL, also prompt for optional fields."
|
With optional argument OPTIONAL, also prompt for optional fields."
|
||||||
(flet ((val (key lst) (cdr (assoc key lst)))
|
(flet ((val (key lst) (cdr (assoc key lst)))
|
||||||
(keyword (name) (intern (concat ":" (downcase name))))
|
(keyword (name) (intern (concat ":" (downcase name))))
|
||||||
(name (keyword) (upcase (substring (symbol-name keyword) 1))))
|
(name (keyword) (substring (symbol-name keyword) 1)))
|
||||||
(dolist (field (append
|
(dolist (field (append
|
||||||
(if org-bibtex-treat-headline-as-title
|
(if org-bibtex-treat-headline-as-title
|
||||||
(remove :title (val :required (val type org-bibtex-types)))
|
(remove :title (val :required (val type org-bibtex-types)))
|
||||||
|
@ -530,22 +530,36 @@ With prefix argument OPTIONAL also prompt for optional fields."
|
||||||
With prefix argument OPTIONAL also prompt for optional fields."
|
With prefix argument OPTIONAL also prompt for optional fields."
|
||||||
(interactive) (org-map-entries (lambda () (org-bibtex-check optional))))
|
(interactive) (org-map-entries (lambda () (org-bibtex-check optional))))
|
||||||
|
|
||||||
(defun org-bibtex-create (&optional arg)
|
(defun org-bibtex-create (&optional arg nonew)
|
||||||
"Create a new entry at the given level."
|
"Create a new entry at the given level.
|
||||||
|
With a prefix arg, query for optional fields as well.
|
||||||
|
If nonew is t, add data to the headline of the entry at point."
|
||||||
(interactive "P")
|
(interactive "P")
|
||||||
(let* ((type (org-icompleting-read
|
(let* ((type (org-icompleting-read
|
||||||
"Type: " (mapcar (lambda (type) (symbol-name (car type)))
|
"Type: " (mapcar (lambda (type)
|
||||||
org-bibtex-types)))
|
(substring (symbol-name (car type)) 1))
|
||||||
(type (if (keywordp type) type (intern type))))
|
org-bibtex-types)
|
||||||
|
nil nil (when nonew (org-bibtex-get "TYPE"))))
|
||||||
|
(type (if (keywordp type) type (intern (concat ":" type))))
|
||||||
|
(org-bibtex-treat-headline-as-title (if nonew nil t)))
|
||||||
(unless (assoc type org-bibtex-types)
|
(unless (assoc type org-bibtex-types)
|
||||||
(error "type:%s is not known" type))
|
(error "type:%s is not known" type))
|
||||||
(org-insert-heading)
|
(if nonew
|
||||||
(let ((title (org-bibtex-ask :title)))
|
(org-back-to-heading)
|
||||||
(insert title) (org-bibtex-put "TITLE" title))
|
(org-insert-heading)
|
||||||
|
(let ((title (org-bibtex-ask :title)))
|
||||||
|
(insert title)
|
||||||
|
(org-bibtex-put "TITLE" title)))
|
||||||
(org-bibtex-put "TYPE" (substring (symbol-name type) 1))
|
(org-bibtex-put "TYPE" (substring (symbol-name type) 1))
|
||||||
(org-bibtex-fleshout type arg)
|
(org-bibtex-fleshout type arg)
|
||||||
(mapc (lambda (tag) (org-toggle-tag tag t)) org-bibtex-tags)))
|
(mapc (lambda (tag) (org-toggle-tag tag t)) org-bibtex-tags)))
|
||||||
|
|
||||||
|
(defun org-bibtex-create-in-current-entry (&optional arg)
|
||||||
|
"Add bibliographical data to the current entry.
|
||||||
|
With a prefix arg, query for optional fields."
|
||||||
|
(interactive "P")
|
||||||
|
(org-bibtex-create arg t))
|
||||||
|
|
||||||
(defun org-bibtex-read ()
|
(defun org-bibtex-read ()
|
||||||
"Read a bibtex entry and save to `*org-bibtex-entries*'.
|
"Read a bibtex entry and save to `*org-bibtex-entries*'.
|
||||||
This uses `bibtex-parse-entry'."
|
This uses `bibtex-parse-entry'."
|
||||||
|
@ -588,11 +602,11 @@ This uses `bibtex-parse-entry'."
|
||||||
(:type nil)
|
(:type nil)
|
||||||
(:key (org-bibtex-put org-bibtex-key-property (cdr pair)))
|
(:key (org-bibtex-put org-bibtex-key-property (cdr pair)))
|
||||||
(:keywords (if org-bibtex-tags-are-keywords
|
(:keywords (if org-bibtex-tags-are-keywords
|
||||||
(mapc
|
(mapc
|
||||||
(lambda (kw)
|
(lambda (kw)
|
||||||
(togtag
|
(togtag
|
||||||
(replace-regexp-in-string
|
(replace-regexp-in-string
|
||||||
"[^[:alnum:]_@#%]" ""
|
"[^[:alnum:]_@#%]" ""
|
||||||
(replace-regexp-in-string "[ \t]+" "_" kw))))
|
(replace-regexp-in-string "[ \t]+" "_" kw))))
|
||||||
(split-string (cdr pair) ", *"))
|
(split-string (cdr pair) ", *"))
|
||||||
(org-bibtex-put (car pair) (cdr pair))))
|
(org-bibtex-put (car pair) (cdr pair))))
|
||||||
|
@ -608,6 +622,21 @@ This uses `bibtex-parse-entry'."
|
||||||
(org-bibtex-write)
|
(org-bibtex-write)
|
||||||
(error "yanked text does not appear to contain a bibtex entry"))))
|
(error "yanked text does not appear to contain a bibtex entry"))))
|
||||||
|
|
||||||
|
(defun org-bibtex-export-to-kill-ring ()
|
||||||
|
"Export current headline to kill ring as bibtex entry."
|
||||||
|
(interactive)
|
||||||
|
(kill-new (org-bibtex-headline)))
|
||||||
|
|
||||||
|
(defun org-bibtex-search (string)
|
||||||
|
"Search for bibliographical entries in agenda files.
|
||||||
|
This function relies `org-search-view' to locate results."
|
||||||
|
(interactive "sSearch string: ")
|
||||||
|
(let ((org-agenda-overriding-header "Bib search results:")
|
||||||
|
(org-agenda-search-view-always-boolean t))
|
||||||
|
(org-search-view nil
|
||||||
|
(format "%s +{:%sTYPE:}"
|
||||||
|
string org-bibtex-prefix))))
|
||||||
|
|
||||||
(provide 'org-bibtex)
|
(provide 'org-bibtex)
|
||||||
|
|
||||||
;; arch-tag: 83987d5a-01b8-41c7-85bc-77700f1285f5
|
;; arch-tag: 83987d5a-01b8-41c7-85bc-77700f1285f5
|
||||||
|
|
Loading…
Reference in a new issue