[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Emacs 27-28, improvements to BibTeX
From: |
Emanuel Berg |
Subject: |
Re: Emacs 27-28, improvements to BibTeX |
Date: |
Sat, 24 Oct 2020 06:11:12 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
If you wonder why I care about `bibtex-mode' - I use it every day!
(almost)
Because I have a file to keep track of my reading, I started it summer
2014 and it now has 432 entries! Not bad for a guy who everyone tells
to read stuff :)
https://dataswamp.org/~incal/books/books.bib
I use this
(+ (how-many "^@book" (point)) (how-many "^@periodical" (point)))
to find out how many! Something for bibtex-mode, maybe?
Another thing I use all the time is "new-book" [1] - the source yanked
last in this post - hm, I wonder why I set it up that way? Anyway, it
is very useful! It outputs this
@book{,
author = {x},
isbn = {},
publisher = {},
title = {},
year = {}
}
with x denoting the position of point after invocation!
I then tab and backtab between fields until it is complete, then
I hit M-n for "bibtex-insert-autokey-check-isbn" (source last). As you
can see, that is integrated with my verifiers of ISBN and ISSNs [3]
I know what you are thinking: ain't it cool stuff!
(defun create-book (&optional title author publisher year isbn)
"Insert a Bibtex book at point.
\nOptional insert TITLE, AUTHOR, PUBLISHER, YEAR, and ISBN.
\nTo insert an entry with blank field, use \\[new-book]"
(interactive "stitle: \nsauthor: \nspublisher: \nsyear: \nsISBN: ")
(let*((bib-str-nils (format "@book{,\n author = {%s},\n isbn =
{%s},\n publisher = {%s},\n title = {%s},\n year = {%s}\n}"
author isbn publisher title year))
(bib-str (replace-regexp-in-string "{nil}" "{}" bib-str-nils)) )
(beginning-of-line)
(let ((start (point)))
(insert bib-str)
(goto-char (+ start 24) )))) ; point at first field
(defun new-book ()
"Insert a Bibtex book, with blank field, at point.
\nsee `create-book'"
(interactive)
(create-book) )
(defun bibtex-insert-autokey-check-isbn ()
(interactive)
(let*((ids (list (bibtex-autokey-get-field "issn")
(bibtex-autokey-get-field "isbn") ))
(issn (car ids))
(isbn (cadr ids)) )
(cond ((not (empty-string-p issn)) (issn-verify issn))
((not (empty-string-p isbn)) (isbn-verify isbn)) )
(bibtex-insert-autokey) ))
(defalias 'bibtex-insert-autokey-check-issn #'bibtex-insert-autokey-check-isbn)
;; asked about this on gmane.emacs.devel and gmane.emacs.help
(defun bibtex-insert-autokey ()
(re-search-forward "^}")
(let ((title (bibtex-autokey-get-title)))
(bibtex-beginning-of-entry)
(search-forward "{")
(insert title)
(kill-line)
(insert ",") ))
[1] https://dataswamp.org/~incal/emacs-init/my-bibtex.el line 132
[2] https://dataswamp.org/~incal/emacs-init/isbn-verify.el
https://dataswamp.org/~incal/emacs-init/issn-verify.el
--
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal