aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoland Winkler2006-04-09 18:29:19 +0000
committerRoland Winkler2006-04-09 18:29:19 +0000
commit5ad23234d6988b65a4b71ecb10d1570facf84ea2 (patch)
tree9d434ccd3e1baaaa312c74e5e2834d29cd14bf48
parentba7e3f51f264729f3ef2b91e11c0cee46ad67509 (diff)
downloademacs-5ad23234d6988b65a4b71ecb10d1570facf84ea2.tar.gz
emacs-5ad23234d6988b65a4b71ecb10d1570facf84ea2.zip
(bibtex-entry-update): New optional arg entry-type. Add field
delimiters to numerical fields if they are not present.
-rw-r--r--lisp/textmodes/bibtex.el50
1 files changed, 35 insertions, 15 deletions
diff --git a/lisp/textmodes/bibtex.el b/lisp/textmodes/bibtex.el
index a70ab1591ca..ff1c1e48eb0 100644
--- a/lisp/textmodes/bibtex.el
+++ b/lisp/textmodes/bibtex.el
@@ -2856,25 +2856,45 @@ is non-nil."
2856 (bibtex-autofill-entry)) 2856 (bibtex-autofill-entry))
2857 (run-hooks 'bibtex-add-entry-hook))) 2857 (run-hooks 'bibtex-add-entry-hook)))
2858 2858
2859(defun bibtex-entry-update () 2859(defun bibtex-entry-update (&optional entry-type)
2860 "Update an existing BibTeX entry. 2860 "Update an existing BibTeX entry.
2861In the BibTeX entry at point, make new fields for those items that may occur 2861In the BibTeX entry at point, make new fields for those items that may occur
2862according to `bibtex-field-list', but are not yet present." 2862according to `bibtex-field-list', but are not yet present.
2863 (interactive) 2863Also, add field delimiters to numerical fields if they are not present.
2864If ENTRY-TYPE is non-nil, change first the entry type to ENTRY-TYPE.
2865When called interactively with a prefix arg, query for a value of ENTRY-TYPE."
2866 (interactive
2867 (list (if current-prefix-arg
2868 (let ((completion-ignore-case t))
2869 (completing-read "New entry type: " bibtex-entry-field-alist
2870 nil t nil 'bibtex-entry-type-history)))))
2864 (save-excursion 2871 (save-excursion
2865 (bibtex-beginning-of-entry) 2872 (bibtex-beginning-of-entry)
2866 ;; For inserting new fields, we use the fact that 2873 (when (looking-at bibtex-entry-maybe-empty-head)
2867 ;; `bibtex-parse-entry' moves point to the end of the last field. 2874 (goto-char (match-end 0))
2868 (let* ((fields-alist (bibtex-parse-entry)) 2875 (if entry-type
2869 (field-list (bibtex-field-list 2876 (save-excursion
2870 (cdr (assoc "=type=" fields-alist))))) 2877 (replace-match (concat "@" entry-type) nil nil nil 1))
2871 (skip-chars-backward " \t\n") 2878 (setq entry-type (bibtex-type-in-head)))
2872 (dolist (field (car field-list)) 2879 (let* ((field-list (bibtex-field-list entry-type))
2873 (unless (assoc-string (car field) fields-alist t) 2880 (required (copy-tree (car field-list)))
2874 (bibtex-make-field field))) 2881 (optional (copy-tree (cdr field-list)))
2875 (dolist (field (cdr field-list)) 2882 bounds)
2876 (unless (assoc-string (car field) fields-alist t) 2883 (while (setq bounds (bibtex-parse-field))
2877 (bibtex-make-optional-field field)))))) 2884 (let ((fname (bibtex-name-in-field bounds t))
2885 (end (copy-marker (bibtex-end-of-field bounds) t)))
2886 (setq required (delete (assoc-string fname required t) required)
2887 optional (delete (assoc-string fname optional t) optional))
2888 (when (string-match "\\`[0-9]+\\'"
2889 (bibtex-text-in-field-bounds bounds))
2890 (goto-char (bibtex-end-of-text-in-field bounds))
2891 (insert (bibtex-field-right-delimiter))
2892 (goto-char (bibtex-start-of-text-in-field bounds))
2893 (insert (bibtex-field-left-delimiter)))
2894 (goto-char end)))
2895 (skip-chars-backward " \t\n")
2896 (dolist (field required) (bibtex-make-field field))
2897 (dolist (field optional) (bibtex-make-optional-field field))))))
2878 2898
2879(defun bibtex-parse-entry (&optional content) 2899(defun bibtex-parse-entry (&optional content)
2880 "Parse entry at point, return an alist. 2900 "Parse entry at point, return an alist.