From: Martin Kampas <martin.kampas@ubedi.net>
To: emacs-orgmode@gnu.org
Subject: [PATCH] org-bibtex-yank: Allow to populate existing item
Date: Mon, 12 Feb 2024 13:50:05 +0100 [thread overview]
Message-ID: <4868155.GXAFRqVoOG@gt1> (raw)
[-- Attachment #1.1: Type: text/plain, Size: 181 bytes --]
Hi,
The attached patch allows to use org-bibtex-yank to
populate an existing item instead of creating a new one,
aligning its behavior with org-bibtex-create.
BR,
Martin Kampas
[-- Attachment #1.2: Type: text/html, Size: 635 bytes --]
[-- Attachment #2: 0001-org-bibtex-yank-Allow-to-populate-existing-item.patch --]
[-- Type: text/x-patch, Size: 3834 bytes --]
From 96af3ef46bb056e58206af77d3d37c5af2e43d7f Mon Sep 17 00:00:00 2001
From: Martin Kampas <martin.kampas@ubedi.net>
Date: Mon, 12 Feb 2024 13:24:54 +0100
Subject: [PATCH] org-bibtex-yank: Allow to populate existing item
Align with org-bibtex-create.
* lisp/ol-bibtex.el (org-bibtex-write): New optional argument nonew,
similar to the existing nonew argument of org-bibtex-create
* lisp/ol-bibtex.el (org-bibtex-yank): New optional argument nonew,
similar to the existing nonew argument of org-bibtex-create
---
lisp/ol-bibtex.el | 39 ++++++++++++++++++++++-----------------
1 file changed, 22 insertions(+), 17 deletions(-)
diff --git a/lisp/ol-bibtex.el b/lisp/ol-bibtex.el
index c5a950e2d..6ae4ae3cc 100644
--- a/lisp/ol-bibtex.el
+++ b/lisp/ol-bibtex.el
@@ -722,29 +722,31 @@ Return the number of saved entries."
(interactive "fFile: ")
(org-bibtex-read-buffer (find-file-noselect file 'nowarn 'rawfile)))
-(defun org-bibtex-write (&optional noindent)
+(defun org-bibtex-write (&optional noindent nonew)
"Insert a heading built from the first element of `org-bibtex-entries'.
When optional argument NOINDENT is non-nil, do not indent the properties
-drawer."
+drawer. If NONEW is t, add data to the headline of the entry at point."
(interactive)
(unless org-bibtex-entries
(error "No entries in `org-bibtex-entries'"))
(let* ((entry (pop org-bibtex-entries))
(org-special-properties nil) ; avoids errors with `org-entry-put'
(val (lambda (field) (cdr (assoc field entry))))
- (togtag (lambda (tag) (org-toggle-tag tag 'on))))
- (org-insert-heading)
- (insert (funcall org-bibtex-headline-format-function entry))
- (insert "\n:PROPERTIES:\n")
- (org-bibtex-put "TITLE" (funcall val :title) 'insert)
+ (togtag (lambda (tag) (org-toggle-tag tag 'on)))
+ (insert-raw (not nonew)))
+ (unless nonew
+ (org-insert-heading)
+ (insert (funcall org-bibtex-headline-format-function entry))
+ (insert "\n:PROPERTIES:\n"))
+ (org-bibtex-put "TITLE" (funcall val :title) insert-raw)
(org-bibtex-put org-bibtex-type-property-name
(downcase (funcall val :type))
- 'insert)
+ insert-raw)
(dolist (pair entry)
(pcase (car pair)
(:title nil)
(:type nil)
- (:key (org-bibtex-put org-bibtex-key-property (cdr pair) 'insert))
+ (:key (org-bibtex-put org-bibtex-key-property (cdr pair) insert-raw))
(:keywords (if org-bibtex-tags-are-keywords
(dolist (kw (split-string (cdr pair) ", *"))
(funcall
@@ -752,25 +754,28 @@ drawer."
(replace-regexp-in-string
"[^[:alnum:]_@#%]" ""
(replace-regexp-in-string "[ \t]+" "_" kw))))
- (org-bibtex-put (car pair) (cdr pair) 'insert)))
- (_ (org-bibtex-put (car pair) (cdr pair) 'insert))))
- (insert ":END:\n")
+ (org-bibtex-put (car pair) (cdr pair) insert-raw)))
+ (_ (org-bibtex-put (car pair) (cdr pair) insert-raw))))
+ (unless nonew
+ (insert ":END:\n"))
(mapc togtag org-bibtex-tags)
(unless noindent
(org-indent-region
(save-excursion (org-back-to-heading t) (point))
(point)))))
-(defun org-bibtex-yank ()
- "If kill ring holds a bibtex entry yank it as an Org headline."
- (interactive)
- (let (entry)
+(defun org-bibtex-yank (&optional nonew)
+ "If kill ring holds a bibtex entry yank it as an Org headline.
+If nonew is t, add data to the headline of the entry at point."
+ (interactive "P")
+ (let (entry
+ (noindent nonew))
(with-temp-buffer
(yank 1)
(bibtex-mode)
(setf entry (org-bibtex-read)))
(if entry
- (org-bibtex-write)
+ (org-bibtex-write noindent nonew)
(error "Yanked text does not appear to contain a BibTeX entry"))))
(defun org-bibtex-import-from-file (file)
--
2.43.0
next reply other threads:[~2024-02-12 13:01 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-12 12:50 Martin Kampas [this message]
2024-02-18 14:29 ` [PATCH] org-bibtex-yank: Allow to populate existing item Ihor Radchenko
2024-02-22 15:30 ` Martin Kampas
2024-02-25 8:58 ` Ihor Radchenko
2024-03-02 22:00 ` Martin Kampas
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=4868155.GXAFRqVoOG@gt1 \
--to=martin.kampas@ubedi.net \
--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).