help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bibtex stuff


From: Emanuel Berg
Subject: Re: Bibtex stuff
Date: Sun, 17 Oct 2021 00:47:11 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

> 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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]