unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Emanuel Berg via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org>
To: help-gnu-emacs@gnu.org
Subject: Re: Emacs 27-28, improvements to BibTeX
Date: Sat, 24 Oct 2020 06:11:12 +0200	[thread overview]
Message-ID: <87h7qks1pb.fsf@zoho.eu> (raw)
In-Reply-To: 87pn58s45t.fsf@zoho.eu

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




  reply	other threads:[~2020-10-24  4:11 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-24  2:47 Emacs 27-28, improvements to BibTeX Emanuel Berg via Users list for the GNU Emacs text editor
2020-10-24  2:59 ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-10-24  3:04   ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-10-24  3:18     ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-10-24  4:11       ` Emanuel Berg via Users list for the GNU Emacs text editor [this message]
2020-10-24  8:26       ` Eli Zaretskii
2020-10-24  8:25   ` Eli Zaretskii

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.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87h7qks1pb.fsf@zoho.eu \
    --to=help-gnu-emacs@gnu.org \
    --cc=moasenwood@zoho.eu \
    /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.
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).