From: Emanuel Berg via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org>
To: help-gnu-emacs@gnu.org
Cc: emacs-devel@gnu.org
Subject: Re: Bibtex stuff
Date: Sun, 17 Oct 2021 00:47:11 +0200 [thread overview]
Message-ID: <87o87oa8pc.fsf@zoho.eu> (raw)
In-Reply-To: 87wnmcaa6l.fsf@zoho.eu
> In this case, the bibtex-field stuff is probably such
> a thing that ought to be pretty much a basic building block
> of any such mode ... not necessarily the exact way I wrote
> it tho.
Oh, someone has added a `bibtex-next-field'! Great work!
Shouldn't BEGIN be default tho? Other than that I wonder what
the difference is between that and mine ...
Anyway so then add a modified version of my "-prev-" as well
then ;)
Awesome stuff :)
From /usr/local/share/emacs/29.0.50/lisp/textmodes/bibtex.el
(defun bibtex-next-field (begin &optional comma)
"Move point to end of text of next BibTeX field or entry head.
With prefix BEGIN non-nil, move point to its beginning. Optional arg COMMA
is as in `bibtex-enclosing-field'. It is t for interactive calls."
(interactive (list current-prefix-arg t))
(let ((bounds (bibtex-find-text-internal t nil comma))
end-of-entry)
(if (not bounds)
(setq end-of-entry t)
(goto-char (nth 3 bounds))
(if (assoc-string (car bounds) '("@String" "@Preamble") t)
(setq end-of-entry t)
;; BibTeX key or field
(if (looking-at ",[ \t\n]*") (goto-char (match-end 0)))
;; end of entry
(if (looking-at "[)}][ \t\n]*") (setq end-of-entry t))))
(if (and end-of-entry
(re-search-forward bibtex-any-entry-maybe-empty-head nil t))
(goto-char (match-beginning 0)))
(bibtex-find-text begin nil bibtex-help-message)))
My file:
;;; -*- lexical-binding: t -*-
;;;
;;; this file:
;;; https://dataswamp.org/~incal/emacs-init/bibtex/bibtex-field.el
;;;
;;; test here:
;;; https://dataswamp.org/~incal/books/books.bib
(require 'cl-lib)
(defun bibtex-prev-field ()
(interactive)
(cl-labels ((search-prev ()
(when (re-search-backward "=\\|@" nil t)
(let ((eol (line-end-position)))
(unless (re-search-forward "{" eol t)
(forward-char 2) )))
(point) ))
(when (= (point) (search-prev))
(let ((beg (point)))
(beginning-of-line)
(when (= (point) (search-prev))
(goto-char beg) )))))
(defun re-search-forward-return (regexp)
(save-excursion
(re-search-forward regexp (point-max) t) ))
(defun bibtex-beginning-of-next-field ()
(interactive)
(cl-labels ((advance (to)
(goto-char to)
(if (looking-at "[[:space:]]*{")
(goto-char (match-end 0))
(forward-char 1) )))
(let*((next-curly (re-search-forward-return "{"))
(next-equal (re-search-forward-return "=")) )
(if (and next-curly next-equal)
(if (< next-curly next-equal)
(goto-char next-curly)
(advance next-equal) )
(if next-equal
(advance next-equal)
(when next-curly
(goto-char next-curly) ))))))
(provide 'bibtex-field)
--
underground experts united
https://dataswamp.org/~incal
next prev parent reply other threads:[~2021-10-16 22:47 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-16 22:15 Bibtex stuff Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-16 22:47 ` Emanuel Berg via Users list for the GNU Emacs text editor [this message]
2021-10-16 22:57 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-17 1:37 ` weird key message (was: Re: Bibtex stuff) Emanuel Berg via Users list for the GNU Emacs text editor
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=87o87oa8pc.fsf@zoho.eu \
--to=help-gnu-emacs@gnu.org \
--cc=emacs-devel@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).