From: Matt Lundin <mdl@imapmail.org>
To: Org Mode <emacs-orgmode@gnu.org>
Subject: [PATCH 4/4] Add helper functions to org-bibtex
Date: Sun, 1 May 2011 17:01:59 -0400 [thread overview]
Message-ID: <87iptunn4m.fsf@fastmail.fm> (raw)
* 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.
---
lisp/org-bibtex.el | 51 ++++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 40 insertions(+), 11 deletions(-)
diff --git a/lisp/org-bibtex.el b/lisp/org-bibtex.el
index 513519b..868535d 100644
--- a/lisp/org-bibtex.el
+++ b/lisp/org-bibtex.el
@@ -226,14 +226,14 @@ For example setting to 'BIB_' would allow interoperability with fireforg."
(defcustom org-bibtex-treat-headline-as-title t
"Treat headline text as title if title property is absent.
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."
:group 'org-bibtex
:type 'boolean)
(defcustom org-bibtex-export-arbitrary-fields nil
"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
not placed in the exported bibtex entry."
:group 'org-bibtex
@@ -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."
(flet ((val (key lst) (cdr (assoc key lst)))
(keyword (name) (intern (concat ":" (downcase name))))
- (name (keyword) (upcase (substring (symbol-name keyword) 1))))
+ (name (keyword) (substring (symbol-name keyword) 1)))
(dolist (field (append
(if org-bibtex-treat-headline-as-title
(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."
(interactive) (org-map-entries (lambda () (org-bibtex-check optional))))
-(defun org-bibtex-create (&optional arg)
- "Create a new entry at the given level."
+(defun org-bibtex-create (&optional arg nonew)
+ "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")
(let* ((type (org-icompleting-read
- "Type: " (mapcar (lambda (type) (symbol-name (car type)))
- org-bibtex-types)))
- (type (if (keywordp type) type (intern type))))
+ "Type: " (mapcar (lambda (type)
+ (substring (symbol-name (car type)) 1))
+ 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)
(error "type:%s is not known" type))
- (org-insert-heading)
- (let ((title (org-bibtex-ask :title)))
- (insert title) (org-bibtex-put "TITLE" title))
+ (if nonew
+ (org-back-to-heading)
+ (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-fleshout type arg)
(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 ()
"Read a bibtex entry and save to `*org-bibtex-entries*'.
This uses `bibtex-parse-entry'."
@@ -608,6 +622,21 @@ This uses `bibtex-parse-entry'."
(org-bibtex-write)
(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)
;; arch-tag: 83987d5a-01b8-41c7-85bc-77700f1285f5
--
1.7.5
next reply other threads:[~2011-05-01 21:10 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-01 21:01 Matt Lundin [this message]
2011-05-02 16:29 ` [PATCH 4/4] Add helper functions to org-bibtex Eric Schulte
2011-05-02 17:06 ` Matt Lundin
2011-05-02 17:24 ` Eric Schulte
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87iptunn4m.fsf@fastmail.fm \
--to=mdl@imapmail.org \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).