diff lisp/textmodes/bibtex.el @ 90813:e6fdae9180d4

Merge from emacs--devo--0 Patches applied: * emacs--devo--0 (patch 698-710) - Update from CVS - Merge from gnus--rel--5.10 * gnus--rel--5.10 (patch 216) - Update from CVS Revision: emacs@sv.gnu.org/emacs--unicode--0--patch-196
author Miles Bader <miles@gnu.org>
date Tue, 24 Apr 2007 21:56:25 +0000
parents 95d0cdf160ea 372e6a7ea660
children 988f1edc9674
line wrap: on
line diff
--- a/lisp/textmodes/bibtex.el	Tue Apr 24 11:35:23 2007 +0000
+++ b/lisp/textmodes/bibtex.el	Tue Apr 24 21:56:25 2007 +0000
@@ -86,7 +86,7 @@
   :group 'bibtex
   :type '(choice (const :tag "None" nil)
                  (string :tag "Initial text")
-                 (function :tag "Initialize Function" :value fun)
+                 (function :tag "Initialize Function")
                  (const :tag "Default" t)))
 (put 'bibtex-include-OPTkey 'risky-local-variable t)
 
@@ -98,11 +98,8 @@
   :group 'bibtex
   :type '(repeat (group (string :tag "Field")
                         (string :tag "Comment")
-                        (option (group :inline t
-                                       :extra-offset -4
-                                       (choice :tag "Init" :value ""
-                                               string
-                                               function))))))
+                        (option (choice :tag "Init"
+                                        (const nil) string function)))))
 (put 'bibtex-user-optional-fields 'risky-local-variable t)
 
 (defcustom bibtex-entry-format
@@ -224,7 +221,7 @@
   :group 'bibtex
   :type 'boolean)
 
-(defvar bibtex-entry-field-alist
+(defcustom bibtex-entry-field-alist
   '(("Article"
      ((("author" "Author1 [and Author2 ...] [and others]")
        ("title" "Title of the article (BibTeX converts it to lowercase)")
@@ -452,7 +449,36 @@
 field or a function, which is called to determine the initial content
 of the field, and ALTERNATIVE-FLAG (either nil or t) marks if the
 field is an alternative.  ALTERNATIVE-FLAG may be t only in the
-REQUIRED or CROSSREF-REQUIRED lists.")
+REQUIRED or CROSSREF-REQUIRED lists."
+  :group 'bibtex
+  :type '(repeat (group (string :tag "Entry name")
+                        (group (repeat :tag "Required fields"
+                                       (group (string :tag "Field")
+                                              (string :tag "Comment")
+                                              (option (choice :tag "Init" :value nil
+                                                              (const nil) string function))
+                                              (option (choice :tag "Alternative"
+                                                              (const :tag "No" nil)
+                                                              (const :tag "Yes" t)))))
+                               (repeat :tag "Optional fields"
+                                       (group (string :tag "Field")
+                                              (string :tag "Comment")
+                                              (option (choice :tag "Init" :value nil
+                                                              (const nil) string function)))))
+                        (option :extra-offset -4
+                         (group (repeat :tag "Crossref: required fields"
+                                        (group (string :tag "Field")
+                                               (string :tag "Comment")
+                                               (option (choice :tag "Init" :value nil
+                                                               (const nil) string function))
+                                               (option (choice :tag "Alternative"
+                                                               (const :tag "No" nil)
+                                                               (const :tag "Yes" t)))))
+                                (repeat :tag "Crossref: optional fields"
+                                        (group (string :tag "Field")
+                                               (string :tag "Comment")
+                                               (option (choice :tag "Init" :value nil
+                                                               (const nil) string function)))))))))
 (put 'bibtex-entry-field-alist 'risky-local-variable t)
 
 (defcustom bibtex-comment-start "@Comment"
@@ -1785,7 +1811,7 @@
           (set-mark (point))
           (message "Mark set")
           (bibtex-make-field (funcall fun 'bibtex-field-kill-ring-yank-pointer
-                                      bibtex-field-kill-ring) t))
+                                      bibtex-field-kill-ring) t nil t))
       ;; insert past the current entry
       (bibtex-skip-to-valid-entry)
       (set-mark (point))
@@ -2831,7 +2857,7 @@
         (push (list "key"
                     "Used for reference key creation if author and editor fields are missing"
                     (if (or (stringp bibtex-include-OPTkey)
-                            (fboundp bibtex-include-OPTkey))
+                            (functionp bibtex-include-OPTkey))
                         bibtex-include-OPTkey))
               optional))
     (if (member-ignore-case entry-type bibtex-include-OPTcrossref)
@@ -3020,7 +3046,7 @@
       (if comment (message "%s" (nth 1 comment))
         (message "No comment available")))))
 
-(defun bibtex-make-field (field &optional move interactive)
+(defun bibtex-make-field (field &optional move interactive nodelim)
   "Make a field named FIELD in current BibTeX entry.
 FIELD is either a string or a list of the form
 \(FIELD-NAME COMMENT-STRING INIT ALTERNATIVE-FLAG) as in
@@ -3028,7 +3054,8 @@
 If MOVE is non-nil, move point past the present field before making
 the new field.  If INTERACTIVE is non-nil, move point to the end of
 the new field.  Otherwise move point past the new field.
-MOVE and INTERACTIVE are t when called interactively."
+MOVE and INTERACTIVE are t when called interactively.
+INIT is surrounded by field delimiters, unless NODELIM is non-nil."
   (interactive
    (list (let ((completion-ignore-case t)
                (field-list (bibtex-field-list
@@ -3058,10 +3085,13 @@
     (indent-to-column (+ bibtex-entry-offset
                          bibtex-text-indentation)))
   (let ((init (nth 2 field)))
-    (insert (cond ((stringp init) init)
-                  ((fboundp init) (funcall init))
-                  (t (concat (bibtex-field-left-delimiter)
-                             (bibtex-field-right-delimiter))))))
+    (if (not init) (setq init "")
+      (if (functionp init) (setq init (funcall init)))
+      (unless (stringp init) (error "`%s' is not a string" init)))
+    ;; NODELIM is required by `bibtex-insert-kill'
+    (if nodelim (insert init)
+      (insert (bibtex-field-left-delimiter) init
+              (bibtex-field-right-delimiter))))
   (when interactive
     ;; (bibtex-find-text nil nil bibtex-help-message)
     (if (memq (preceding-char) '(?} ?\")) (forward-char -1))