aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoland Winkler2009-12-05 04:08:48 +0000
committerRoland Winkler2009-12-05 04:08:48 +0000
commit403111a821d91a0f74fa700f921f0d4e128f9b90 (patch)
treedabffdfa4794e8bbeec9531de7eac887975a1cb4
parent6a495b76f2824456a2ea6748d9df13f474087844 (diff)
downloademacs-403111a821d91a0f74fa700f921f0d4e128f9b90.tar.gz
emacs-403111a821d91a0f74fa700f921f0d4e128f9b90.zip
(bibtex-map-entries): Use marker to keep
track of the buffer position of the end of a BibTeX entry as this position may change during reformatting. (bibtex-format-entry): Remove whitespace before processing numerical fields so that we recognize the latter properly. (bibtex-reformat): Do not use push which changes the global value of bibtex-entry-format. (bibtex-field-braces-alist, bibtex-field-strings-alist) (bibtex-field-re-init): Replace only space characters by regexp for whitespace. (bibtex-generate-url-list, bibtex-cite-matcher-alist): Fix docstring. (bibtex-initialize): Also update bibtex-strings. (bibtex-kill-field): Preserve white space at end of entry. (bibtex-kill-entry, bibtex-yank-pop, bibtex-insert-kill): Update bibtex-reference-keys.
-rw-r--r--lisp/ChangeLog19
-rw-r--r--lisp/textmodes/bibtex.el81
2 files changed, 77 insertions, 23 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 9cf33c9aa70..d0651d2e646 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,22 @@
12009-12-05 Roland Winkler <Roland.Winkler@physik.uni-erlangen.de>
2
3 * textmodes/bibtex.el (bibtex-map-entries): Use marker to keep
4 track of the buffer position of the end of a BibTeX entry as this
5 position may change during reformatting.
6 (bibtex-format-entry): Remove whitespace before processing
7 numerical fields so that we recognize the latter properly.
8 (bibtex-reformat): Do not use push which changes the global value
9 of bibtex-entry-format.
10 (bibtex-field-braces-alist, bibtex-field-strings-alist)
11 (bibtex-field-re-init): Replace only space characters by regexp
12 for whitespace.
13 (bibtex-generate-url-list, bibtex-cite-matcher-alist): Fix
14 docstring.
15 (bibtex-initialize): Also update bibtex-strings.
16 (bibtex-kill-field): Preserve white space at end of entry.
17 (bibtex-kill-entry, bibtex-yank-pop, bibtex-insert-kill): Update
18 bibtex-reference-keys.
19
12009-12-05 Stefan Monnier <monnier@iro.umontreal.ca> 202009-12-05 Stefan Monnier <monnier@iro.umontreal.ca>
2 21
3 * minibuffer.el (completion-pcm--merge-try): Also consider placing 22 * minibuffer.el (completion-pcm--merge-try): Also consider placing
diff --git a/lisp/textmodes/bibtex.el b/lisp/textmodes/bibtex.el
index 0f2674cd99e..dba40f10559 100644
--- a/lisp/textmodes/bibtex.el
+++ b/lisp/textmodes/bibtex.el
@@ -163,7 +163,7 @@ The value nil means do no formatting at all."
163 "Alist of field regexps that \\[bibtex-clean-entry] encloses by braces. 163 "Alist of field regexps that \\[bibtex-clean-entry] encloses by braces.
164Each element has the form (FIELDS REGEXP), where FIELDS is a list 164Each element has the form (FIELDS REGEXP), where FIELDS is a list
165of BibTeX field names and REGEXP is a regexp. 165of BibTeX field names and REGEXP is a regexp.
166Whitespace in REGEXP will be replaced by \"[ \\t\\n]+\"." 166Space characters in REGEXP will be replaced by \"[ \\t\\n]+\"."
167 :group 'bibtex 167 :group 'bibtex
168 :type '(repeat (list (repeat (string :tag "field name")) 168 :type '(repeat (list (repeat (string :tag "field name"))
169 (choice (regexp :tag "regexp") 169 (choice (regexp :tag "regexp")
@@ -174,7 +174,7 @@ Whitespace in REGEXP will be replaced by \"[ \\t\\n]+\"."
174Each element has the form (FIELDS REGEXP TO-STR), where FIELDS is a list 174Each element has the form (FIELDS REGEXP TO-STR), where FIELDS is a list
175of BibTeX field names. In FIELDS search for REGEXP, which are replaced 175of BibTeX field names. In FIELDS search for REGEXP, which are replaced
176by the BibTeX string constant TO-STR. 176by the BibTeX string constant TO-STR.
177Whitespace in REGEXP will be replaced by \"[ \\t\\n]+\"." 177Space characters in REGEXP will be replaced by \"[ \\t\\n]+\"."
178 :group 'bibtex 178 :group 'bibtex
179 :type '(repeat (list (repeat (string :tag "field name")) 179 :type '(repeat (list (repeat (string :tag "field name"))
180 (regexp :tag "From regexp") 180 (regexp :tag "From regexp")
@@ -907,6 +907,7 @@ and with the `match-data' properly set.
907Case is always ignored. Always remove the field delimiters. 907Case is always ignored. Always remove the field delimiters.
908If `bibtex-expand-strings' is non-nil, BibTeX strings are expanded 908If `bibtex-expand-strings' is non-nil, BibTeX strings are expanded
909for generating the URL. 909for generating the URL.
910Set this variable before loading BibTeX mode.
910 911
911The following is a complex example, see http://link.aps.org/linkfaq.html. 912The following is a complex example, see http://link.aps.org/linkfaq.html.
912 913
@@ -945,7 +946,8 @@ The following is a complex example, see http://link.aps.org/linkfaq.html.
945Each rule should be of the form (REGEXP . SUBEXP), where SUBEXP 946Each rule should be of the form (REGEXP . SUBEXP), where SUBEXP
946specifies which parenthesized expression in REGEXP is a cited key. 947specifies which parenthesized expression in REGEXP is a cited key.
947Case is significant. 948Case is significant.
948Used by `bibtex-search-crossref' and for font-locking." 949Used by `bibtex-search-crossref' and for font-locking.
950Set this variable before loading BibTeX mode."
949 :group 'bibtex 951 :group 'bibtex
950 :type '(repeat (cons (regexp :tag "Regexp") 952 :type '(repeat (cons (regexp :tag "Regexp")
951 (integer :tag "Number"))) 953 (integer :tag "Number")))
@@ -1725,13 +1727,18 @@ entry and `match-data' corresponds to the header of the entry,
1725see regexp `bibtex-entry-head'. If `bibtex-sort-ignore-string-entries' 1727see regexp `bibtex-entry-head'. If `bibtex-sort-ignore-string-entries'
1726is non-nil, FUN is not called for @String entries." 1728is non-nil, FUN is not called for @String entries."
1727 (let ((case-fold-search t) 1729 (let ((case-fold-search t)
1730 (end-marker (make-marker))
1728 found) 1731 found)
1732 ;; Use marker to keep track of the buffer position of the end of
1733 ;; a BibTeX entry as this position may change during reformatting.
1734 (set-marker-insertion-type end-marker t)
1729 (save-excursion 1735 (save-excursion
1730 (goto-char (point-min)) 1736 (goto-char (point-min))
1731 (while (setq found (bibtex-skip-to-valid-entry)) 1737 (while (setq found (bibtex-skip-to-valid-entry))
1738 (set-marker end-marker (cdr found))
1732 (looking-at bibtex-any-entry-maybe-empty-head) 1739 (looking-at bibtex-any-entry-maybe-empty-head)
1733 (funcall fun (bibtex-key-in-head "") (car found) (cdr found)) 1740 (funcall fun (bibtex-key-in-head "") (car found) end-marker)
1734 (goto-char (cdr found)))))) 1741 (goto-char end-marker)))))
1735 1742
1736(defun bibtex-progress-message (&optional flag interval) 1743(defun bibtex-progress-message (&optional flag interval)
1737 "Echo a message about progress of current buffer. 1744 "Echo a message about progress of current buffer.
@@ -1871,7 +1878,14 @@ Optional arg COMMA is as in `bibtex-enclosing-field'."
1871 (bibtex-skip-to-valid-entry) 1878 (bibtex-skip-to-valid-entry)
1872 (push-mark) 1879 (push-mark)
1873 (insert (funcall fun 'bibtex-entry-kill-ring-yank-pointer 1880 (insert (funcall fun 'bibtex-entry-kill-ring-yank-pointer
1874 bibtex-entry-kill-ring))))) 1881 bibtex-entry-kill-ring))
1882 (unless (functionp bibtex-reference-keys)
1883 ;; update `bibtex-reference-keys'
1884 (save-excursion
1885 (goto-char (mark t))
1886 (looking-at bibtex-any-entry-maybe-empty-head)
1887 (let ((key (bibtex-key-in-head)))
1888 (if key (push (cons key t) bibtex-reference-keys))))))))
1875 1889
1876(defun bibtex-format-entry () 1890(defun bibtex-format-entry ()
1877 "Helper function for `bibtex-clean-entry'. 1891 "Helper function for `bibtex-clean-entry'.
@@ -1988,6 +2002,17 @@ Formats current entry according to variable `bibtex-entry-format'."
1988 (unless deleted 2002 (unless deleted
1989 (push field-name field-list) 2003 (push field-name field-list)
1990 2004
2005 ;; Remove whitespace at beginning and end of field.
2006 ;; We do not look at individual parts of the field
2007 ;; as {foo } # bar # { baz} is a fine field.
2008 (when (memq 'whitespace format)
2009 (goto-char beg-text)
2010 (if (looking-at "\\([{\"]\\)[ \t\n]+")
2011 (replace-match "\\1"))
2012 (goto-char end-text)
2013 (if (looking-back "[ \t\n]+\\([}\"]\\)" beg-text t)
2014 (replace-match "\\1")))
2015
1991 ;; remove delimiters from purely numerical fields 2016 ;; remove delimiters from purely numerical fields
1992 (when (and (memq 'numerical-fields format) 2017 (when (and (memq 'numerical-fields format)
1993 (progn (goto-char beg-text) 2018 (progn (goto-char beg-text)
@@ -2024,17 +2049,6 @@ Formats current entry according to variable `bibtex-entry-format'."
2024 "\\([\"{][0-9]+\\)[ \t\n]*--?[ \t\n]*\\([0-9]+[\"}]\\)"))) 2049 "\\([\"{][0-9]+\\)[ \t\n]*--?[ \t\n]*\\([0-9]+[\"}]\\)")))
2025 (replace-match "\\1-\\2")) 2050 (replace-match "\\1-\\2"))
2026 2051
2027 ;; Remove whitespace at beginning and end of field.
2028 ;; We do not look at individual parts of the field
2029 ;; as {foo } # bar # { baz} is a fine field.
2030 (when (memq 'whitespace format)
2031 (goto-char beg-text)
2032 (if (looking-at "\\([{\"]\\)[ \t\n]+")
2033 (replace-match "\\1"))
2034 (goto-char end-text)
2035 (if (looking-back "[ \t\n]+\\([}\"]\\)" beg-text t)
2036 (replace-match "\\1")))
2037
2038 ;; enclose field text by braces according to 2052 ;; enclose field text by braces according to
2039 ;; `bibtex-field-braces-alist'. 2053 ;; `bibtex-field-braces-alist'.
2040 (let (case-fold-search temp) ; Case-sensitive search 2054 (let (case-fold-search temp) ; Case-sensitive search
@@ -2184,7 +2198,7 @@ Return optimized value to be used by `bibtex-format-entry'."
2184 (setq regexp-alist 2198 (setq regexp-alist
2185 (mapcar (lambda (e) 2199 (mapcar (lambda (e)
2186 (list (car e) 2200 (list (car e)
2187 (replace-regexp-in-string "[ \t\n]+" "[ \t\n]+" (nth 1 e)) 2201 (replace-regexp-in-string " +" "[ \t\n]+" (nth 1 e))
2188 (nth 2 e))) ; nil for 'braces'. 2202 (nth 2 e))) ; nil for 'braces'.
2189 regexp-alist)) 2203 regexp-alist))
2190 (let (opt-list) 2204 (let (opt-list)
@@ -2684,7 +2698,9 @@ When called interactively, FORCE is t, CURRENT is t if current buffer uses
2684 (dolist (buffer buffer-list) 2698 (dolist (buffer buffer-list)
2685 (with-current-buffer buffer 2699 (with-current-buffer buffer
2686 (if (or force (functionp bibtex-reference-keys)) 2700 (if (or force (functionp bibtex-reference-keys))
2687 (bibtex-parse-keys)))) 2701 (bibtex-parse-keys))
2702 (unless (functionp bibtex-strings)
2703 (bibtex-parse-strings (bibtex-string-files-init)))))
2688 ;; select BibTeX buffer 2704 ;; select BibTeX buffer
2689 (if select 2705 (if select
2690 (if buffer-list 2706 (if buffer-list
@@ -4053,7 +4069,11 @@ but do not actually kill it. Optional arg COMMA is as in
4053 (end (bibtex-end-of-field bounds)) 4069 (end (bibtex-end-of-field bounds))
4054 (beg (bibtex-start-of-field bounds))) 4070 (beg (bibtex-start-of-field bounds)))
4055 (goto-char end) 4071 (goto-char end)
4056 (skip-chars-forward ",") 4072 ;; Preserve white space at end of BibTeX entry
4073 (if (looking-at "[ \t\n]*[)}]")
4074 (progn (skip-chars-backward " \t\n")
4075 (setq end (point)))
4076 (skip-chars-forward ","))
4057 (push (list (bibtex-name-in-field bounds) nil 4077 (push (list (bibtex-name-in-field bounds) nil
4058 (bibtex-text-in-field-bounds bounds)) 4078 (bibtex-text-in-field-bounds bounds))
4059 bibtex-field-kill-ring) 4079 bibtex-field-kill-ring)
@@ -4081,6 +4101,8 @@ but do not actually kill it."
4081 (save-excursion 4101 (save-excursion
4082 (let* ((case-fold-search t) 4102 (let* ((case-fold-search t)
4083 (beg (bibtex-beginning-of-entry)) 4103 (beg (bibtex-beginning-of-entry))
4104 (key (progn (looking-at bibtex-any-entry-maybe-empty-head)
4105 (bibtex-key-in-head)))
4084 (end (progn (bibtex-end-of-entry) 4106 (end (progn (bibtex-end-of-entry)
4085 (if (re-search-forward 4107 (if (re-search-forward
4086 bibtex-any-entry-maybe-empty-head nil 'move) 4108 bibtex-any-entry-maybe-empty-head nil 'move)
@@ -4094,7 +4116,11 @@ but do not actually kill it."
4094 nil)) 4116 nil))
4095 (setq bibtex-entry-kill-ring-yank-pointer bibtex-entry-kill-ring) 4117 (setq bibtex-entry-kill-ring-yank-pointer bibtex-entry-kill-ring)
4096 (unless copy-only 4118 (unless copy-only
4097 (delete-region beg end)))) 4119 (delete-region beg end)
4120 ;; remove key from `bibtex-reference-keys'.
4121 (unless (functionp bibtex-reference-keys)
4122 (setq bibtex-reference-keys
4123 (delete (cons key t) bibtex-reference-keys))))))
4098 (setq bibtex-last-kill-command 'entry)) 4124 (setq bibtex-last-kill-command 'entry))
4099 4125
4100(defun bibtex-copy-entry-as-kill () 4126(defun bibtex-copy-entry-as-kill ()
@@ -4128,7 +4154,16 @@ comes the newest one."
4128 (unless (eq last-command 'bibtex-yank) 4154 (unless (eq last-command 'bibtex-yank)
4129 (error "Previous command was not a BibTeX yank")) 4155 (error "Previous command was not a BibTeX yank"))
4130 (setq this-command 'bibtex-yank) 4156 (setq this-command 'bibtex-yank)
4131 (let ((inhibit-read-only t)) 4157 (let ((inhibit-read-only t) key)
4158 ;; point is at end of yanked entry
4159 (unless (functionp bibtex-reference-keys)
4160 ;; remove key of yanked entry from `bibtex-reference-keys'
4161 (save-excursion
4162 (goto-char (mark t))
4163 (if (and (looking-at bibtex-any-entry-maybe-empty-head)
4164 (setq key (bibtex-key-in-head)))
4165 (setq bibtex-reference-keys
4166 (delete (cons key t) bibtex-reference-keys)))))
4132 (delete-region (point) (mark t)) 4167 (delete-region (point) (mark t))
4133 (bibtex-insert-kill n t))) 4168 (bibtex-insert-kill n t)))
4134 4169
@@ -4390,7 +4425,7 @@ If mark is active reformat entries in region, if not in whole buffer."
4390 last-comma page-dashes unify-case inherit-booktitle 4425 last-comma page-dashes unify-case inherit-booktitle
4391 whitespace braces strings)) 4426 whitespace braces strings))
4392 (t 4427 (t
4393 (remove 'required-fields (push 'realign bibtex-entry-format))))) 4428 (cons 'realign (remove 'required-fields bibtex-entry-format)))))
4394 (reformat-reference-keys 4429 (reformat-reference-keys
4395 (if read-options 4430 (if read-options
4396 (if use-previous-options 4431 (if use-previous-options