unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#10254: 24.0.92; Local variable bibtex-dialect has no effect
@ 2011-12-09  7:29 Uwe Siart
  2011-12-10  7:43 ` Glenn Morris
  0 siblings, 1 reply; 18+ messages in thread
From: Uwe Siart @ 2011-12-09  7:29 UTC (permalink / raw)
  To: 10254

In bibtex-mode I tried to set bibtex-dialect automatically via

,----
| ;; -*- bibtex-dialect: biblatex; -*-
`----

in the first line of a bib file. From "C-h v bibtex-dialect" I get

,----
| bibtex-dialect is a variable defined in `bibtex.el'.
| Its value is biblatex
| Original value was BibTeX
| Local in buffer siart.bib; global value is BibTeX
| 
|   This variable is a file local variable.
`----

as expected. However, when I type e.g. "C-c C-c" inside an entry where a
date field exists instead of a year field, I get the error that the
mandatory field year is missing. This would be correct for
bibtex-dialect BibTeX but not for biblatex.

If I then got to menu 'Entry-Types' and set bibtex-dialect via the menu,
everything is fine i.e. I get biblatex support as expected.


In GNU Emacs 24.0.92.1 (i386-mingw-nt5.1.2600)
 of 2011-12-07 on MARVIN
Windowing system distributor `Microsoft Corp.', version 5.1.2600
configured using `configure --with-gcc (4.6) --no-opt --cflags -ID:/devel/emacs/libs/libXpm-3.5.8/include -ID:/devel/emacs/libs/libXpm-3.5.8/src -ID:/devel/emacs/libs/libpng-dev_1.4.3-1/include -ID:/devel/emacs/libs/zlib-dev_1.2.5-2/include -ID:/devel/emacs/libs/giflib-4.1.4-1/include -ID:/devel/emacs/libs/jpeg-6b-4/include -ID:/devel/emacs/libs/tiff-3.8.2-1/include -ID:/devel/emacs/libs/gnutls-2.10.1/include --ldflags -LD:/devel/emacs/libs/gnutls-2.10.1/lib'

Important settings:
  value of $LC_ALL: nil
  value of $LC_COLLATE: nil
  value of $LC_CTYPE: nil
  value of $LC_MESSAGES: nil
  value of $LC_MONETARY: nil
  value of $LC_NUMERIC: nil
  value of $LC_TIME: nil
  value of $LANG: DEU
  value of $XMODIFIERS: nil
  locale-coding-system: cp1252
  default enable-multibyte-characters: t

Major mode: Lisp Interaction

Minor modes in effect:
  iswitchb-mode: t
  electric-pair-mode: t
  display-time-mode: t
  delete-selection-mode: t
  auto-insert-mode: t
  tooltip-mode: t
  mouse-wheel-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  column-number-mode: t
  line-number-mode: t
  transient-mark-mode: t

Recent input:
y <next> C-h v b i b t e x <tab> d i <tab> <return> 
C-x 1 <down> <down> <down> <down> <down> <down> <down> 
<down> <down> C-c C-c <down> <up> <prior> <prior> <prior> 
<prior> <prior> <prior> <prior> <prior> <prior> <prior> 
<prior> <prior> C-c m <menu-bar> <Entry-Types> <BibTeX 
dialect> <biblatex> <down> <down> <down> <down> <down> 
<down> <down> <down> <down> <down> <down> <down> <down> 
<down> <down> <down> <down> <down> <down> <down> <down> 
<down> <down> C-c C-c <down> <down> <down> <down> <down> 
<down> <down> <down> <down> <down> <down> <down> <down> 
<down> <down> C-c C-c C-x u <up> <up> <up> <up> <up> 
<up> C-x 5 b <return> M-x r e p o r t <tab> <retur
n>

Recent messages:
Loading electric...done
Loading iswitchb...done
For information about GNU Emacs and the GNU system, type C-h C-a.
Please type y, n, or !: y
Type C-x 1 to delete the help window.
bibtex-format-entry: Mandatory field `year' is missing
scroll-down-command: Beginning of buffer [10 times]
Menu-Bar mode enabled
bibtex-format-entry: Mandatory field `editor' is missing
Undo!

Load-path shadows:
None found.

Features:
(shadow sort rfc1345 quail gnus-util mail-extr message format-spec
rfc822 mml mml-sec mm-decode mm-bodies mm-encode mail-parse rfc2231
rfc2047 rfc2045 ietf-drums mm-util mail-prsvr mailabbrev mail-utils
gmm-utils mailheader emacsbug pp help-mode view latex easy-mmode
tex-style tex advice advice-preload bibtex regexp-opt iswitchb electric
time delsel cus-start cus-load autoinsert tex-site auto-loads
dired-sort-map server x-dict easymenu htmlize help-fns boxquote rect cl
paren edmacro kmacro time-date tooltip ediff-hook vc-hooks
lisp-float-type mwheel dos-w32 disp-table ls-lisp w32-win w32-vars
tool-bar dnd fontset image fringe lisp-mode register page menu-bar
rfn-eshadow timer select scroll-bar mouse jit-lock font-lock syntax
facemenu font-core frame cham georgian utf-8-lang misc-lang vietnamese
tibetan thai tai-viet lao korean japanese hebrew greek romanian slovak
czech european ethiopic indian cyrillic chinese case-table epa-hook
jka-cmpr-hook help simple abbrev minibuffer button faces cus-face files
text-properties overlay sha1 md5 base64 format env code-pages mule
custom widget hashtable-print-readable backquote make-network-process
multi-tty emacs)

-- 
Prof. Dr.-Ing. Uwe Siart
Lehrstuhl für Hochfrequenztechnik
Technische Universität München
Arcisstr. 21, 80333 München, Germany
E-Mail: uwe.siart@tum.de
Tel.:   +49.89.289.23374
Fax:    +49.89.289.23365





^ permalink raw reply	[flat|nested] 18+ messages in thread

* bug#10254: 24.0.92; Local variable bibtex-dialect has no effect
  2011-12-09  7:29 bug#10254: 24.0.92; Local variable bibtex-dialect has no effect Uwe Siart
@ 2011-12-10  7:43 ` Glenn Morris
  2011-12-10  9:12   ` Uwe Siart
  0 siblings, 1 reply; 18+ messages in thread
From: Glenn Morris @ 2011-12-10  7:43 UTC (permalink / raw)
  To: Uwe Siart; +Cc: 10254

Uwe Siart wrote:

> In bibtex-mode I tried to set bibtex-dialect automatically via
>
> ,----
> | ;; -*- bibtex-dialect: biblatex; -*-
> `----
>
> in the first line of a bib file.

C-h v bibtex-dialect says:

  During a session change it via `bibtex-set-dialect'.

which is perhaps not 100% clear, but means that if bibtex-mode is
already loaded (which it will be by the time local variables are
processed), you must either change the value with M-x customize or by
calling that function. Just using a setq is not enough. So to have a
buffer-local value you must use something like:

;; -*- eval: (bibtex-set-dialect 'biblatex) -*-





^ permalink raw reply	[flat|nested] 18+ messages in thread

* bug#10254: 24.0.92; Local variable bibtex-dialect has no effect
  2011-12-10  7:43 ` Glenn Morris
@ 2011-12-10  9:12   ` Uwe Siart
  2012-01-10  1:24     ` Glenn Morris
  0 siblings, 1 reply; 18+ messages in thread
From: Uwe Siart @ 2011-12-10  9:12 UTC (permalink / raw)
  To: Glenn Morris; +Cc: 10254

On 10 Dec 2011 at 2:43, Glenn Morris wrote:

> ;; -*- eval: (bibtex-set-dialect 'biblatex) -*-

Glenn, thank you for clarifying this. It works perfectly.

Maybe it's worth mentioning this in the docstring? Even when users 
recognize that bibtex-set-dialect is the way to go they may still not 
be able to figure out ;; -*- <what-needs-to-go-here-?> -*-.

-- 
Uwe






^ permalink raw reply	[flat|nested] 18+ messages in thread

* bug#10254: 24.0.92; Local variable bibtex-dialect has no effect
  2011-12-10  9:12   ` Uwe Siart
@ 2012-01-10  1:24     ` Glenn Morris
  2012-01-10 18:33       ` Roland Winkler
  2012-01-15  9:04       ` Roland Winkler
  0 siblings, 2 replies; 18+ messages in thread
From: Glenn Morris @ 2012-01-10  1:24 UTC (permalink / raw)
  To: Uwe Siart; +Cc: Roland Winkler, 10254


A better solution would be something like the following. However, it
seems that at present bibtex.el is simply not set up to handle a
buffer-local dialect. Eg none of the variables set by bibtex-set-dialect
(bibtex-entry-type etc) are buffer-local. So it won't work right if you
open multiple buffers with different dialects.


*** lisp/textmodes/bibtex.el	2012-01-05 09:46:05 +0000
--- lisp/textmodes/bibtex.el	2012-01-10 01:19:18 +0000
***************
*** 836,841 ****
--- 836,842 ----
    :type '(choice (const BibTeX)
                   (const biblatex)
                   (symbol :tag "Custom")))
+ ;;;###autoload(put 'bibtex-dialect 'safe-local-variable 'symbolp)
  
  (defcustom bibtex-no-opt-remove-re "\\`option"
    "If a field name matches this regexp, the prefix OPT is not removed.
***************
*** 3376,3382 ****
    (setq imenu-generic-expression
          (list (list nil bibtex-entry-head bibtex-key-in-head))
          imenu-case-fold-search t)
!   (bibtex-set-dialect bibtex-dialect))
  
  (defun bibtex-set-dialect (dialect)
    "Select BibTeX mode DIALECT.
--- 3377,3383 ----
    (setq imenu-generic-expression
          (list (list nil bibtex-entry-head bibtex-key-in-head))
          imenu-case-fold-search t)
!   (add-hook 'hack-local-variables-hook 'bibtex-hack-local-variables nil t))
  
  (defun bibtex-set-dialect (dialect)
    "Select BibTeX mode DIALECT.
***************
*** 3475,3480 ****
--- 3476,3486 ----
                                             t))
                                   bibtex-dialect-list))))))))
  
+ (defun bibtex-hack-local-variables ()
+   "BibTex mode adds this to `hack-local-variables-hook'."
+   ;; Respect any buffer-local setting of bibtex-dialect (bug#10254).
+   (bibtex-set-dialect bibtex-dialect))
+ 
  (defun bibtex-field-list (entry-type)
    "Return list of allowed fields for entry ENTRY-TYPE.
  More specifically, the return value is a cons pair (REQUIRED . OPTIONAL),






^ permalink raw reply	[flat|nested] 18+ messages in thread

* bug#10254: 24.0.92; Local variable bibtex-dialect has no effect
  2012-01-10  1:24     ` Glenn Morris
@ 2012-01-10 18:33       ` Roland Winkler
  2012-01-11  6:41         ` Uwe Siart
  2012-01-15  9:04       ` Roland Winkler
  1 sibling, 1 reply; 18+ messages in thread
From: Roland Winkler @ 2012-01-10 18:33 UTC (permalink / raw)
  To: Glenn Morris; +Cc: Uwe Siart, 10254

On Mon Jan 9 2012 Glenn Morris wrote:
> 
> A better solution would be something like the following. However, it
> seems that at present bibtex.el is simply not set up to handle a
> buffer-local dialect. Eg none of the variables set by bibtex-set-dialect
> (bibtex-entry-type etc) are buffer-local. So it won't work right if you
> open multiple buffers with different dialects.

To clarify the circumstances of the original bug report:

Do you want to use buffer-local values of bibtex-dialect because you
do have multiple BibTeX files, some of which use one BibTeX dialect,
others use another dialect? -- Such a scenario is somewhat
orthogonal to the general notion of BibTeX that should provide one
database that is used for all LaTeX documents. That's why the
current code was not set up to support such a scenario. Yet when I
think about it now, I can imagine more rare cases that would benefit
from buffer-local values of bibtex-dialect.

In any case, buffer-local calls of bibtex-set-dialect are not enough
to solve this problem but one also needs buffer-local values of the
variables set by bibtex-set-dialect.

Also, I do not consider this a bug. In my opinion, it's more a
missing feature. So with Emacs 24 being already in pretest I am
tempted to say it would be more appropriate to provide a proper fix
in the next release of Emacs. I'll look into this.

Roland





^ permalink raw reply	[flat|nested] 18+ messages in thread

* bug#10254: 24.0.92; Local variable bibtex-dialect has no effect
  2012-01-10 18:33       ` Roland Winkler
@ 2012-01-11  6:41         ` Uwe Siart
  2012-01-11 10:46           ` Roland Winkler
  0 siblings, 1 reply; 18+ messages in thread
From: Uwe Siart @ 2012-01-11  6:41 UTC (permalink / raw)
  To: Roland Winkler; +Cc: 10254

"Roland Winkler" <winkler@gnu.org> writes:

> Do you want to use buffer-local values of bibtex-dialect because you
> do have multiple BibTeX files, some of which use one BibTeX dialect,
> others use another dialect?

Exactly, yes.

> Such a scenario is somewhat orthogonal to the general notion of BibTeX
> that should provide one database that is used for all LaTeX documents.

Surely I use centrally managed bibfiles. They reside in
~/texmf/bibtex/bib/siart. Since I do not like one huge monolithic
bibfile my database is split across several files where each file is
dedicated to a certain topic. But with a bibfile local to a certain
document BibTeX is also much superior to filling {thebibliography} by
hand.

But this is not the point here. The point is that classical bibstyles
and biblatex are not compatible at bibfile level. A bibfile can only be
used either for bibstyles or for biblatex. In my case mostly due to the
different handling of the month and language fields.

It is IMO not a rare case that one has to use both biblatex and
bibstyles. If I need to implement a certain requirement for the
bibliography that can only be solved by biblatex (e.g. a particular
sorting scheme) I will need to create a bibfile for biblatex. On the
other hand I can not simply throw away all the achivements of classical
bibstyle. Moreover, if a publisher provides a template bibstyle I have
to use it. No way to convince a publisher to switch his workflow to
biblatex immediately.

So I am in a situation where I have to manage both bibtex dialects at
the same time in different files. I don't think that this is really
against the BibTeX paradigm. It's just that we now have both options
(bibstyle and biblatex) and they are not compatible.

> Also, I do not consider this a bug. In my opinion, it's more a missing
> feature.

I got your point and I fully agree. I never meant to decide whether it
is a bug or not. At the time when I filed a bug report I just observed
that setting a buffer-local variable had no effect while click in the
menue worked. This looked like a bug to me at that time.

-- 
Uwe





^ permalink raw reply	[flat|nested] 18+ messages in thread

* bug#10254: 24.0.92; Local variable bibtex-dialect has no effect
  2012-01-11  6:41         ` Uwe Siart
@ 2012-01-11 10:46           ` Roland Winkler
  2012-01-11 14:57             ` Uwe Siart
  0 siblings, 1 reply; 18+ messages in thread
From: Roland Winkler @ 2012-01-11 10:46 UTC (permalink / raw)
  To: uwe.siart; +Cc: 10254

On Wed Jan 11 2012 Uwe Siart wrote:
> It is IMO not a rare case that one has to use both biblatex and
> bibstyles. If I need to implement a certain requirement for the
> bibliography that can only be solved by biblatex (e.g. a particular
> sorting scheme) I will need to create a bibfile for biblatex. On the
> other hand I can not simply throw away all the achivements of classical
> bibstyle. Moreover, if a publisher provides a template bibstyle I have
> to use it. No way to convince a publisher to switch his workflow to
> biblatex immediately.
> 
> So I am in a situation where I have to manage both bibtex dialects at
> the same time in different files.

OK, this is what I was expecting when you said you do need to handle
different BibTeX files with different BibTeX dialects.

I'll sent here a patch and leave it to the Emacs pretest
administrators whether they want to install it now or later.
In any case, you can then install it locally.

Roland





^ permalink raw reply	[flat|nested] 18+ messages in thread

* bug#10254: 24.0.92; Local variable bibtex-dialect has no effect
  2012-01-11 10:46           ` Roland Winkler
@ 2012-01-11 14:57             ` Uwe Siart
  0 siblings, 0 replies; 18+ messages in thread
From: Uwe Siart @ 2012-01-11 14:57 UTC (permalink / raw)
  To: Roland Winkler; +Cc: 10254

"Roland Winkler" <winkler@gnu.org> writes:

> I'll sent here a patch and leave it to the Emacs pretest
> administrators whether they want to install it now or later.
> In any case, you can then install it locally.

Thanks a lot for your immediate help.

-- 
Uwe





^ permalink raw reply	[flat|nested] 18+ messages in thread

* bug#10254: 24.0.92; Local variable bibtex-dialect has no effect
  2012-01-10  1:24     ` Glenn Morris
  2012-01-10 18:33       ` Roland Winkler
@ 2012-01-15  9:04       ` Roland Winkler
  2012-01-16 14:14         ` Stefan Monnier
  1 sibling, 1 reply; 18+ messages in thread
From: Roland Winkler @ 2012-01-15  9:04 UTC (permalink / raw)
  To: Glenn Morris; +Cc: Uwe Siart, 10254

On Mon Jan 9 2012 Glenn Morris wrote:
> 
> A better solution would be something like the following. However, it
> seems that at present bibtex.el is simply not set up to handle a
> buffer-local dialect. Eg none of the variables set by bibtex-set-dialect
> (bibtex-entry-type etc) are buffer-local. So it won't work right if you
> open multiple buffers with different dialects.

Here is a patch that makes all relevant variables buffer-local.
By definition, it has a minor inconsistency with the old code.
Previously, interactively setting the variable buffer-dialect
affected all BibTeX buffers simultaneously. Now this variable is
buffer local. So setting it affects only the current buffer.

I leave it to the pretest adminstrators whether they want to install
the patch now or later. As discussed before, this patch is fairly
substantial and really introduces a new feature.


--- bibtex.el~	2011-12-14 04:23:17.000000000
+++ bibtex.el	2012-01-15 02:44:08.000000000
@@ -826,7 +826,9 @@
 
 (defcustom bibtex-dialect 'BibTeX
   "Current BibTeX dialect.  For allowed values see `bibtex-dialect-list'.
-During a session change it via `bibtex-set-dialect'."
+To interactively change the dialect for individual BibTeX files,
+use the command `bibtex-set-dialect'.  You may also use `bibtex-dialect'
+as a file local variable."
   :group 'bibtex
   :set '(lambda (symbol value)
           (set-default symbol value)
@@ -836,6 +838,8 @@
   :type '(choice (const BibTeX)
                  (const biblatex)
                  (symbol :tag "Custom")))
+(make-variable-buffer-local 'bibtex-dialect)
+(put 'bibtex-dialect 'safe-local-variable 'symbolp)
 
 (defcustom bibtex-no-opt-remove-re "\\`option"
   "If a field name matches this regexp, the prefix OPT is not removed.
@@ -1442,11 +1446,13 @@
 \f
 ;; Internal Variables
 
-(defvar bibtex-entry-alist bibtex-BibTeX-entry-alist
-  "Alist of currently active entry types.")
+(defvar bibtex-entry-alist nil
+  "Alist of currently active entry types.
+Initialized by `bibtex-set-dialect'.")
 
-(defvar bibtex-field-alist bibtex-BibTeX-field-alist
-  "Alist of currently active field types.")
+(defvar bibtex-field-alist nil
+  "Alist of currently active field types.
+Initialized by `bibtex-set-dialect'.")
 
 (defvar bibtex-field-braces-opt nil
   "Optimized value of `bibtex-field-braces-alist'.
@@ -3376,57 +3382,65 @@
   (setq imenu-generic-expression
         (list (list nil bibtex-entry-head bibtex-key-in-head))
         imenu-case-fold-search t)
-  (bibtex-set-dialect bibtex-dialect))
+  (add-hook 'hack-local-variables-hook 'bibtex-set-dialect nil t))
+
+(defun bibtex-entry-alist (dialect)
+  "Return entry-alist for DIALECT."
+  (let ((var (intern (format "bibtex-%s-entry-alist" dialect)))
+        entry-alist)
+    (if (boundp var)
+        (setq entry-alist (symbol-value var))
+      (error "BibTeX dialect `%s' undefined" dialect))
+    (if (not (consp (nth 1 (car entry-alist))))
+        ;; new format
+        entry-alist
+      ;; Convert old format of `bibtex-entry-field-alist'
+      (unless (get var 'entry-list-format)
+        (put var 'entry-list-format "pre-24")
+        (message "Old format of `%s' (pre GNU Emacs 24).
+Please convert to the new format."
+                 (if (eq (indirect-variable 'bibtex-entry-field-alist) var)
+                     'bibtex-entry-field-alist var))
+        (sit-for 3))
+      (let (lst)
+        (dolist (entry entry-alist)
+          (let ((fl (nth 1 entry)) req xref opt)
+            (dolist (field (copy-tree (car fl)))
+              (if (nth 3 field) (setcar (nthcdr 3 field) 0))
+              (if (or (not (nth 2 entry))
+                      (assoc-string (car field) (car (nth 2 entry)) t))
+                  (push field req)
+                (push field xref)))
+            (dolist (field (nth 1 fl))
+              (push field opt))
+            (push (list (car entry) nil (nreverse req)
+                        (nreverse xref) (nreverse opt))
+                  lst)))
+        (nreverse lst)))))
 
-(defun bibtex-set-dialect (dialect)
-  "Select BibTeX mode DIALECT.
+(defun bibtex-set-dialect (&optional dialect force)
+  "Select BibTeX DIALECT for current BibTeX file.
 This sets the variable `bibtex-dialect' which holds the currently active
-dialect.  Dialects are listed in `bibtex-dialect-list'."
+dialect.  Allowed dialects are listed in `bibtex-dialect-list'.
+If DIALECT is nil use current value of `bibtex-dialect'.
+If FORCE is non-nil set all dialect-dependent internal variables
+even if the dialect is not changed.
+To set the default dialect for all your BibTeX files, customize
+the value of `bibtex-dialect' accordingly in your init file."
   (interactive (list (intern (completing-read "Dialect: "
                                               (mapcar 'list bibtex-dialect-list)
                                               nil t))))
-  (unless (eq dialect (get 'bibtex-dialect 'dialect))
-    (put 'bibtex-dialect 'dialect dialect)
-    (setq bibtex-dialect dialect)
-
-  ;; Bind variables
-    (setq bibtex-entry-alist
-          (let ((var (intern (format "bibtex-%s-entry-alist" dialect)))
-                entry-alist)
-            (if (boundp var)
-                (setq entry-alist (symbol-value var))
-              (error "BibTeX dialect `%s' undefined" dialect))
-            (if (not (consp (nth 1 (car entry-alist))))
-                ;; new format
-                entry-alist
-              ;; Convert old format
-              (unless (get var 'entry-list-format)
-                (put var 'entry-list-format "pre-24")
-                (message "Old format of `%s' (pre GNU Emacs 24).
-Please convert to the new format."
-                         (if (eq (indirect-variable 'bibtex-entry-field-alist) var)
-                             'bibtex-entry-field-alist var))
-                (sit-for 3))
-              (let (lst)
-                (dolist (entry entry-alist)
-                  (let ((fl (nth 1 entry)) req xref opt)
-                    (dolist (field (copy-tree (car fl)))
-                      (if (nth 3 field) (setcar (nthcdr 3 field) 0))
-                      (if (or (not (nth 2 entry))
-                              (assoc-string (car field) (car (nth 2 entry)) t))
-                          (push field req)
-                        (push field xref)))
-                    (dolist (field (nth 1 fl))
-                      (push field opt))
-                    (push (list (car entry) nil (nreverse req)
-                                (nreverse xref) (nreverse opt))
-                          lst)))
-                (nreverse lst))))
+  (when (or force (and dialect (not (eq dialect bibtex-dialect))))
+    (if dialect (setq bibtex-dialect dialect))
+
+    ;; Bind internal (and local) variables
+    (setq bibtex-entry-alist (bibtex-entry-alist bibtex-dialect)
           bibtex-field-alist
-          (let ((var (intern (format "bibtex-%s-field-alist" dialect))))
+          (let ((var (intern (format "bibtex-%s-field-alist" bibtex-dialect))))
             (if (boundp var)
                 (symbol-value var)
-              (error "Field types for BibTeX dialect `%s' undefined" dialect)))
+              (error "Field types for BibTeX dialect `%s' undefined"
+                     bibtex-dialect)))
           bibtex-entry-type
           (concat "@[ \t]*\\(?:"
                   (regexp-opt (mapcar 'car bibtex-entry-alist)) "\\)")
@@ -3438,42 +3452,57 @@
           bibtex-entry-maybe-empty-head (concat bibtex-entry-head "?")
           bibtex-any-valid-entry-type
           (concat "^[ \t]*@[ \t]*\\(?:"
-                  (regexp-opt (append '("String" "Preamble")
-                                      (mapcar 'car bibtex-entry-alist))) "\\)"))
-    ;; Define entry commands
-    (dolist (elt bibtex-entry-alist)
-      (let* ((entry (car elt))
-             (fname (intern (concat "bibtex-" entry))))
-        (unless (fboundp fname)
-          (eval (list 'defun fname nil
-                      (format "Insert a new BibTeX @%s entry; see also `bibtex-entry'."
-                              entry)
-                      '(interactive "*")
-                      `(bibtex-entry ,entry))))))
-    ;; Define menu
-    ;; We use the same keymap for all BibTeX buffers.  So all these buffers
-    ;; have the same BibTeX dialect.  To define entry types buffer-locally,
-    ;; it would be necessary to give each BibTeX buffer a new keymap that
-    ;; becomes a child of `bibtex-mode-map'.  Useful??
-    (easy-menu-define
-      nil bibtex-mode-map "Entry-Types Menu in BibTeX mode"
-      (apply 'list "Entry-Types"
-             (append
-              (mapcar (lambda (entry)
-                        (vector (or (nth 1 entry) (car entry))
-                                (intern (format "bibtex-%s" (car entry))) t))
-                      bibtex-entry-alist)
-              `("---"
-                ["String" bibtex-String t]
-                ["Preamble" bibtex-Preamble t]
-                "---"
-                ,(append '("BibTeX dialect")
-                         (mapcar (lambda (dialect)
-                                   (vector (symbol-name dialect)
-                                           `(lambda () (interactive)
-                                              (bibtex-set-dialect ',dialect))
-                                           t))
-                                 bibtex-dialect-list))))))))
+                  (regexp-opt
+                   (append '("String" "Preamble")
+                           (mapcar 'car bibtex-entry-alist))) "\\)"))))
+
+(bibtex-set-dialect nil t)
+;; These internal variables are all set by `bibtex-set-dialect'
+(make-variable-buffer-local 'bibtex-entry-alist)
+(make-variable-buffer-local 'bibtex-field-alist)
+(make-variable-buffer-local 'bibtex-entry-type)
+(make-variable-buffer-local 'bibtex-entry-head)
+(make-variable-buffer-local 'bibtex-entry-maybe-empty-head)
+(make-variable-buffer-local 'bibtex-any-valid-entry-type)
+
+;; Entry commands and menus for BibTeX dialects
+(let ((select-map (make-sparse-keymap)))
+  ;; Submenu for selecting the dialect
+  (dolist (dialect (reverse bibtex-dialect-list))
+    (define-key select-map (vector dialect)
+      `(menu-item ,(symbol-name dialect)
+                  (lambda () (interactive) (bibtex-set-dialect ',dialect))
+                  :button (:radio . (eq bibtex-dialect ',dialect)))))
+  ;; We define a menu for each dialect.
+  ;; Then we select the menu we want via the :visible keyword
+  (dolist (dialect bibtex-dialect-list)
+    (let ((entry-alist (bibtex-entry-alist dialect))
+          (menu-map (make-sparse-keymap)))
+      (define-key menu-map [select]
+        `(menu-item "BibTeX dialect" ,select-map))
+      (define-key menu-map [nil-2] '(menu-item "--"))
+      (define-key menu-map [bibtex-preamble]
+        '(menu-item "Preamble" bibtex-Preamble))
+      (define-key menu-map [bibtex-String]
+        '(menu-item "String" bibtex-String))
+      (define-key menu-map [nil-1] '(menu-item "--"))
+      (dolist (elt (reverse entry-alist))
+        ;; Entry commands
+        (let* ((entry (car elt))
+               (fname (intern (format "bibtex-%s" entry))))
+          (unless (fboundp fname)
+            (eval (list 'defun fname nil
+                        (format "Insert a template for a @%s entry; see also `bibtex-entry'."
+                                entry)
+                        '(interactive "*")
+                        `(bibtex-entry ,entry))))
+          ;; Menu entries
+          (define-key menu-map (vector fname)
+            `(menu-item ,(or (nth 1 elt) (car elt)) ,fname))))
+      (define-key bibtex-mode-map
+        (vector 'menu-bar dialect)
+        `(menu-item "Entry-Types" ,menu-map
+                    :visible (eq bibtex-dialect ',dialect))))))
 
 (defun bibtex-field-list (entry-type)
   "Return list of allowed fields for entry ENTRY-TYPE.
@@ -3505,7 +3534,7 @@
     (cons required optional)))
 
 (defun bibtex-entry (entry-type)
-  "Insert a new BibTeX entry of type ENTRY-TYPE.
+  "Insert a template for a BibTeX entry of type ENTRY-TYPE.
 After insertion call the value of `bibtex-add-entry-hook' if that value
 is non-nil."
   (interactive





^ permalink raw reply	[flat|nested] 18+ messages in thread

* bug#10254: 24.0.92; Local variable bibtex-dialect has no effect
  2012-01-15  9:04       ` Roland Winkler
@ 2012-01-16 14:14         ` Stefan Monnier
  2012-01-16 22:21           ` Roland Winkler
  0 siblings, 1 reply; 18+ messages in thread
From: Stefan Monnier @ 2012-01-16 14:14 UTC (permalink / raw)
  To: Roland Winkler; +Cc: Uwe Siart, 10254

> +(make-variable-buffer-local 'bibtex-dialect)

I don't think you should force it to be buffer-local.  Just leave it as
a global setting by default, and just change the code so that if the
user decides to make it local to some buffer, the rest of the code
handles it properly.


        Stefan





^ permalink raw reply	[flat|nested] 18+ messages in thread

* bug#10254: 24.0.92; Local variable bibtex-dialect has no effect
  2012-01-16 14:14         ` Stefan Monnier
@ 2012-01-16 22:21           ` Roland Winkler
  2012-01-17  5:44             ` Uwe Siart
  2012-01-17 14:04             ` Stefan Monnier
  0 siblings, 2 replies; 18+ messages in thread
From: Roland Winkler @ 2012-01-16 22:21 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Uwe Siart, 10254

On Mon Jan 16 2012 Stefan Monnier wrote:
> > +(make-variable-buffer-local 'bibtex-dialect)
> 
> I don't think you should force it to be buffer-local.  Just leave it as
> a global setting by default, and just change the code so that if the
> user decides to make it local to some buffer, the rest of the code
> handles it properly.

This variable (and everything going with it) is new in Emacs 24. So
to some extent we have to speculate about "typical usage patterns"
of this variable.

Yet after having thought about this a bit more I tend to agree with
the OP that the need for a buffer-local binding of bibtex-dialect
may occur more often. I expect that users want to set the default
value of this variable in their init file. Yet when they want to set
this variable interactively (via the menu bar or the command
bibtex-set-dialect) I expect this to occur more often in a context
similar to the one that made the OP look into a file local binding:
one has got one BibTeX file that does not match the default binding
of bibtex-dialect so that one needs to change the buffer local value
of this variable.

On the other hand I cannot think of many scenarios where one might
want to change this variable interactively for all BibTeX buffers
one is working with.

Am I missing something?

Roland

PS: My patch is based on the assumption that interactively setting
bibtex-dialect changes all relevant variables only buffer-locally.
If one also wanted to support the possibility that the default value
can be changed interactively (thus affecting all BibTeX buffers)
this would require a few more lines of code. Yet as I tried to say,
I am not sure this would really be useful.





^ permalink raw reply	[flat|nested] 18+ messages in thread

* bug#10254: 24.0.92; Local variable bibtex-dialect has no effect
  2012-01-16 22:21           ` Roland Winkler
@ 2012-01-17  5:44             ` Uwe Siart
  2012-01-17 14:04             ` Stefan Monnier
  1 sibling, 0 replies; 18+ messages in thread
From: Uwe Siart @ 2012-01-17  5:44 UTC (permalink / raw)
  To: Roland Winkler; +Cc: 10254

"Roland Winkler" <winkler@gnu.org> writes:

> Yet after having thought about this a bit more I tend to agree with
> the OP that the need for a buffer-local binding of bibtex-dialect
> may occur more often. I expect that users want to set the default
> value of this variable in their init file. Yet when they want to set
> this variable interactively (via the menu bar or the command
> bibtex-set-dialect) I expect this to occur more often in a context
> similar to the one that made the OP look into a file local binding:
> one has got one BibTeX file that does not match the default binding
> of bibtex-dialect so that one needs to change the buffer local value
> of this variable.
>
> On the other hand I cannot think of many scenarios where one might
> want to change this variable interactively for all BibTeX buffers
> one is working with.
>
> Am I missing something?

This is as I understand it. The BibTeX dialect belongs to a certain file
just like the encoding. Hence it sounds like a good idea to me if it
could be set automatically via local variables.

Today we have the option to use either bibstyles or biblatex, depending
on the requirements of the document. IMO only few users will have a
"bibstyle-only" or a "biblatex-only" environment.

-- 
Uwe





^ permalink raw reply	[flat|nested] 18+ messages in thread

* bug#10254: 24.0.92; Local variable bibtex-dialect has no effect
  2012-01-16 22:21           ` Roland Winkler
  2012-01-17  5:44             ` Uwe Siart
@ 2012-01-17 14:04             ` Stefan Monnier
  2012-01-17 20:45               ` Roland Winkler
  1 sibling, 1 reply; 18+ messages in thread
From: Stefan Monnier @ 2012-01-17 14:04 UTC (permalink / raw)
  To: Roland Winkler; +Cc: Uwe Siart, 10254

>> > +(make-variable-buffer-local 'bibtex-dialect)
>> I don't think you should force it to be buffer-local.  Just leave it as
>> a global setting by default, and just change the code so that if the
>> user decides to make it local to some buffer, the rest of the code
>> handles it properly.

> This variable (and everything going with it) is new in Emacs 24. So
> to some extent we have to speculate about "typical usage patterns"
> of this variable.

I'd expect one "typical" usage is to have (setq bibtex-dialect 'biblatex)
in the .emacs file somewhere.  With your new code, the effect of this
setq will depend on whether bibtex.el is loaded before or after
executing the setq.
That's my main source of worry.

> value of this variable in their init file. Yet when they want to set
> this variable interactively (via the menu bar or the command

I have no opinion on whether the interactive commands set it globally or
buffer-locally, but that choice is orthogonal to the use of
make-variable-buffer-local (just call make-local-variable in those
commands if that's the behavior you're after).


        Stefan





^ permalink raw reply	[flat|nested] 18+ messages in thread

* bug#10254: 24.0.92; Local variable bibtex-dialect has no effect
  2012-01-17 14:04             ` Stefan Monnier
@ 2012-01-17 20:45               ` Roland Winkler
  2012-01-17 21:21                 ` Stefan Monnier
  0 siblings, 1 reply; 18+ messages in thread
From: Roland Winkler @ 2012-01-17 20:45 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Uwe Siart, 10254

On Tue Jan 17 2012 Stefan Monnier wrote:
> I'd expect one "typical" usage is to have (setq bibtex-dialect 'biblatex)
> in the .emacs file somewhere.  With your new code, the effect of this
> setq will depend on whether bibtex.el is loaded before or after
> executing the setq.
> That's my main source of worry.

I don't see a "normal" usage of bibtex.el where something in the
init file could result in an early loading of this file such that it
could matter where in the init file this variable is set. (The code
has only three autoload cookies.) In other words: under "normal"
circumstances the init file should be fully processed before
bibtex.el is loaded. Also, like other packages the existing code of
bibtex.el has more internal variables that would aquire wrong values
if user variables are somehow set too late after loading. That's
hard to avoid.

Kind of (un)related: just a few days ago I rearranged my init file
because it called appt-activate too early giving me rather strange
side effects. (I have not debugged details.)

> > value of this variable in their init file. Yet when they want to set
> > this variable interactively (via the menu bar or the command
> 
> I have no opinion on whether the interactive commands set it globally or
> buffer-locally, but that choice is orthogonal to the use of
> make-variable-buffer-local (just call make-local-variable in those
> commands if that's the behavior you're after).

I'll modify the patch such that one can choose whether one gets
local bindings or not.

In any case, I want to provide a command that *can* bind
bibtex-dialect buffer-locally because it's not completely trivial
that the global / local value of this user variable matches the
global / local values of various derived internal variables.

Roland





^ permalink raw reply	[flat|nested] 18+ messages in thread

* bug#10254: 24.0.92; Local variable bibtex-dialect has no effect
  2012-01-17 20:45               ` Roland Winkler
@ 2012-01-17 21:21                 ` Stefan Monnier
  2012-01-28  8:17                   ` Roland Winkler
  0 siblings, 1 reply; 18+ messages in thread
From: Stefan Monnier @ 2012-01-17 21:21 UTC (permalink / raw)
  To: Roland Winkler; +Cc: Uwe Siart, 10254

>> I'd expect one "typical" usage is to have (setq bibtex-dialect 'biblatex)
>> in the .emacs file somewhere.  With your new code, the effect of this
>> setq will depend on whether bibtex.el is loaded before or after
>> executing the setq.
>> That's my main source of worry.
> I don't see a "normal" usage of bibtex.el where something in the
> init file could result in an early loading of this file such that it
> could matter where in the init file this variable is set. (The code

All I'm saying is that using explicit make-local-variable calls when you
set the variable buffer-locally, instead of using a global
make-variable-buffer-local will eliminate this potential problem, no
matter how remote.


        Stefan





^ permalink raw reply	[flat|nested] 18+ messages in thread

* bug#10254: 24.0.92; Local variable bibtex-dialect has no effect
  2012-01-17 21:21                 ` Stefan Monnier
@ 2012-01-28  8:17                   ` Roland Winkler
  2012-01-28 14:05                     ` Chong Yidong
  0 siblings, 1 reply; 18+ messages in thread
From: Roland Winkler @ 2012-01-28  8:17 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Uwe Siart, 10254

On Tue Jan 17 2012 Stefan Monnier wrote:
> All I'm saying is that using explicit make-local-variable calls when you
> set the variable buffer-locally, instead of using a global
> make-variable-buffer-local will eliminate this potential problem, no
> matter how remote.

OK, here is a new version of the patch that uses by default a plain 

  (set var val)

to make all the relevant settings. But if bibtex-set-dialect is
called interactively or bibtex-dialect is already buffer-local (for
example, as a file-local variable), then it uses

  (set (make-local-variable var) val)

I think this should cover all possibilities.

If that's what you had in mind, the patch below could go into the
next pretest.


2012-01-28  Roland Winkler  <winkler@gnu.org>

	* textmodes/bibtex.el (bibtex-entry-alist): New function.
	(bibtex-set-dialect): Use it.  Either set global values of
	dialect-dependent variables or bind these variables buffer-locally
	(Bug#10254).
	(bibtex-mode): Call bibtex-set-dialect via
	hack-local-variables-hook.
	(bibtex-dialect): Update docstring.  Add
	safe-local-variable predicate.
	(bibtex-entry-alist, bibtex-field-alist): Initialize via
	bibtex-set-dialect.
	(bibtex-mode-map): Define menu for each dialect.
	(bibtex-entry): Fix docstring.


--- bibtex.el~	2012-01-20 17:11:00.000000000
+++ bibtex.el	2012-01-28 00:43:24.000000000
@@ -826,7 +826,7 @@
 
 (defcustom bibtex-dialect 'BibTeX
   "Current BibTeX dialect.  For allowed values see `bibtex-dialect-list'.
-During a session change it via `bibtex-set-dialect'."
+To interactively change the dialect use the command `bibtex-set-dialect'."
   :group 'bibtex
   :set '(lambda (symbol value)
           (set-default symbol value)
@@ -836,6 +836,7 @@
   :type '(choice (const BibTeX)
                  (const biblatex)
                  (symbol :tag "Custom")))
+(put 'bibtex-dialect 'safe-local-variable 'symbolp)
 
 (defcustom bibtex-no-opt-remove-re "\\`option"
   "If a field name matches this regexp, the prefix OPT is not removed.
@@ -1442,11 +1443,13 @@
 \f
 ;; Internal Variables
 
-(defvar bibtex-entry-alist bibtex-BibTeX-entry-alist
-  "Alist of currently active entry types.")
+(defvar bibtex-entry-alist nil
+  "Alist of currently active entry types.
+Initialized by `bibtex-set-dialect'.")
 
-(defvar bibtex-field-alist bibtex-BibTeX-field-alist
-  "Alist of currently active field types.")
+(defvar bibtex-field-alist nil
+  "Alist of currently active field types.
+Initialized by `bibtex-set-dialect'.")
 
 (defvar bibtex-field-braces-opt nil
   "Optimized value of `bibtex-field-braces-alist'.
@@ -3376,104 +3379,124 @@
   (setq imenu-generic-expression
         (list (list nil bibtex-entry-head bibtex-key-in-head))
         imenu-case-fold-search t)
-  (bibtex-set-dialect bibtex-dialect))
+  ;; Allow `bibtex-dialect' as a file-local variable.
+  (add-hook 'hack-local-variables-hook 'bibtex-set-dialect nil t))
 
-(defun bibtex-set-dialect (dialect)
-  "Select BibTeX mode DIALECT.
-This sets the variable `bibtex-dialect' which holds the currently active
-dialect.  Dialects are listed in `bibtex-dialect-list'."
+(defun bibtex-entry-alist (dialect)
+  "Return entry-alist for DIALECT."
+  (let ((var (intern (format "bibtex-%s-entry-alist" dialect)))
+        entry-alist)
+    (if (boundp var)
+        (setq entry-alist (symbol-value var))
+      (error "BibTeX dialect `%s' undefined" dialect))
+    (if (not (consp (nth 1 (car entry-alist))))
+        ;; new format
+        entry-alist
+      ;; Convert old format of `bibtex-entry-field-alist'
+      (unless (get var 'entry-list-format)
+        (put var 'entry-list-format "pre-24")
+        (message "Old format of `%s' (pre GNU Emacs 24).
+Please convert to the new format."
+                 (if (eq (indirect-variable 'bibtex-entry-field-alist) var)
+                     'bibtex-entry-field-alist var))
+        (sit-for 3))
+      (let (lst)
+        (dolist (entry entry-alist)
+          (let ((fl (nth 1 entry)) req xref opt)
+            (dolist (field (copy-tree (car fl)))
+              (if (nth 3 field) (setcar (nthcdr 3 field) 0))
+              (if (or (not (nth 2 entry))
+                      (assoc-string (car field) (car (nth 2 entry)) t))
+                  (push field req)
+                (push field xref)))
+            (dolist (field (nth 1 fl))
+              (push field opt))
+            (push (list (car entry) nil (nreverse req)
+                        (nreverse xref) (nreverse opt))
+                  lst)))
+        (nreverse lst)))))
+
+(defun bibtex-set-dialect (&optional dialect local)
+  "Select BibTeX DIALECT for editing BibTeX files.
+This sets the user variable `bibtex-dialect' as well as the dialect-dependent
+internal variables.  Allowed dialects are listed in `bibtex-dialect-list'.
+If DIALECT is nil use current value of `bibtex-dialect'.
+If LOCAL is non-nil make buffer-local bindings for these variables rather than
+setting the global values.  The dialect-dependent internal variables
+are also bound buffer-locally if `bibtex-dialect' is already buffer-local
+in the current buffer (for example, as a file-local variable).
+LOCAL is t for interactive calls."
   (interactive (list (intern (completing-read "Dialect: "
                                               (mapcar 'list bibtex-dialect-list)
-                                              nil t))))
-  (unless (eq dialect (get 'bibtex-dialect 'dialect))
-    (put 'bibtex-dialect 'dialect dialect)
-    (setq bibtex-dialect dialect)
-
-  ;; Bind variables
-    (setq bibtex-entry-alist
-          (let ((var (intern (format "bibtex-%s-entry-alist" dialect)))
-                entry-alist)
-            (if (boundp var)
-                (setq entry-alist (symbol-value var))
-              (error "BibTeX dialect `%s' undefined" dialect))
-            (if (not (consp (nth 1 (car entry-alist))))
-                ;; new format
-                entry-alist
-              ;; Convert old format
-              (unless (get var 'entry-list-format)
-                (put var 'entry-list-format "pre-24")
-                (message "Old format of `%s' (pre GNU Emacs 24).
-Please convert to the new format."
-                         (if (eq (indirect-variable 'bibtex-entry-field-alist) var)
-                             'bibtex-entry-field-alist var))
-                (sit-for 3))
-              (let (lst)
-                (dolist (entry entry-alist)
-                  (let ((fl (nth 1 entry)) req xref opt)
-                    (dolist (field (copy-tree (car fl)))
-                      (if (nth 3 field) (setcar (nthcdr 3 field) 0))
-                      (if (or (not (nth 2 entry))
-                              (assoc-string (car field) (car (nth 2 entry)) t))
-                          (push field req)
-                        (push field xref)))
-                    (dolist (field (nth 1 fl))
-                      (push field opt))
-                    (push (list (car entry) nil (nreverse req)
-                                (nreverse xref) (nreverse opt))
-                          lst)))
-                (nreverse lst))))
-          bibtex-field-alist
-          (let ((var (intern (format "bibtex-%s-field-alist" dialect))))
-            (if (boundp var)
-                (symbol-value var)
-              (error "Field types for BibTeX dialect `%s' undefined" dialect)))
-          bibtex-entry-type
-          (concat "@[ \t]*\\(?:"
-                  (regexp-opt (mapcar 'car bibtex-entry-alist)) "\\)")
-          bibtex-entry-head (concat "^[ \t]*\\("
-                                    bibtex-entry-type
-                                    "\\)[ \t]*[({][ \t\n]*\\("
-                                    bibtex-reference-key
-                                    "\\)")
-          bibtex-entry-maybe-empty-head (concat bibtex-entry-head "?")
-          bibtex-any-valid-entry-type
-          (concat "^[ \t]*@[ \t]*\\(?:"
-                  (regexp-opt (append '("String" "Preamble")
-                                      (mapcar 'car bibtex-entry-alist))) "\\)"))
-    ;; Define entry commands
-    (dolist (elt bibtex-entry-alist)
-      (let* ((entry (car elt))
-             (fname (intern (concat "bibtex-" entry))))
-        (unless (fboundp fname)
-          (eval (list 'defun fname nil
-                      (format "Insert a new BibTeX @%s entry; see also `bibtex-entry'."
-                              entry)
-                      '(interactive "*")
-                      `(bibtex-entry ,entry))))))
-    ;; Define menu
-    ;; We use the same keymap for all BibTeX buffers.  So all these buffers
-    ;; have the same BibTeX dialect.  To define entry types buffer-locally,
-    ;; it would be necessary to give each BibTeX buffer a new keymap that
-    ;; becomes a child of `bibtex-mode-map'.  Useful??
-    (easy-menu-define
-      nil bibtex-mode-map "Entry-Types Menu in BibTeX mode"
-      (apply 'list "Entry-Types"
-             (append
-              (mapcar (lambda (entry)
-                        (vector (or (nth 1 entry) (car entry))
-                                (intern (format "bibtex-%s" (car entry))) t))
-                      bibtex-entry-alist)
-              `("---"
-                ["String" bibtex-String t]
-                ["Preamble" bibtex-Preamble t]
-                "---"
-                ,(append '("BibTeX dialect")
-                         (mapcar (lambda (dialect)
-                                   (vector (symbol-name dialect)
-                                           `(lambda () (interactive)
-                                              (bibtex-set-dialect ',dialect))
-                                           t))
-                                 bibtex-dialect-list))))))))
+                                              nil t)) t))
+  (let ((setfun (if (or local (local-variable-p 'bibtex-dialect))
+                    (lambda (var val) (set (make-local-variable var) val))
+                  'set)))
+    (if dialect (funcall setfun 'bibtex-dialect dialect))
+
+    ;; Set internal variables
+    (funcall setfun 'bibtex-entry-alist (bibtex-entry-alist bibtex-dialect))
+    (funcall setfun 'bibtex-field-alist
+             (let ((var (intern (format "bibtex-%s-field-alist"
+                                        bibtex-dialect))))
+               (if (boundp var)
+                   (symbol-value var)
+                 (error "Field types for BibTeX dialect `%s' undefined"
+                        bibtex-dialect))))
+    (funcall setfun 'bibtex-entry-type
+             (concat "@[ \t]*\\(?:"
+                     (regexp-opt (mapcar 'car bibtex-entry-alist)) "\\)"))
+    (funcall setfun 'bibtex-entry-head
+             (concat "^[ \t]*\\(" bibtex-entry-type "\\)[ \t]*[({][ \t\n]*\\("
+                     bibtex-reference-key "\\)"))
+    (funcall setfun 'bibtex-entry-maybe-empty-head
+             (concat bibtex-entry-head "?"))
+    (funcall setfun 'bibtex-any-valid-entry-type
+             (concat "^[ \t]*@[ \t]*\\(?:"
+                     (regexp-opt
+                      (append '("String" "Preamble")
+                              (mapcar 'car bibtex-entry-alist))) "\\)"))))
+
+;; Entry commands and menus for BibTeX dialects
+;; We do not use `easy-menu-define' here because this gets confused
+;; if we want to have multiple versions of the "same" menu.
+(let ((select-map (make-sparse-keymap)))
+  ;; Submenu for selecting the dialect
+  (dolist (dialect (reverse bibtex-dialect-list))
+    (define-key select-map (vector dialect)
+      `(menu-item ,(symbol-name dialect)
+                  (lambda () (interactive) (bibtex-set-dialect ',dialect t))
+                  :button (:radio . (eq bibtex-dialect ',dialect)))))
+  ;; We define a menu for each dialect.
+  ;; Then we select the menu we want via the :visible keyword
+  (dolist (dialect bibtex-dialect-list)
+    (let ((entry-alist (bibtex-entry-alist dialect))
+          (menu-map (make-sparse-keymap)))
+      (define-key menu-map [select]
+        `(menu-item "BibTeX dialect" ,select-map))
+      (define-key menu-map [nil-2] '(menu-item "--"))
+      (define-key menu-map [bibtex-preamble]
+        '(menu-item "Preamble" bibtex-Preamble))
+      (define-key menu-map [bibtex-String]
+        '(menu-item "String" bibtex-String))
+      (define-key menu-map [nil-1] '(menu-item "--"))
+      (dolist (elt (reverse entry-alist))
+        ;; Entry commands
+        (let* ((entry (car elt))
+               (fname (intern (format "bibtex-%s" entry))))
+          (unless (fboundp fname)
+            (eval (list 'defun fname nil
+                        (format "Insert a template for a @%s entry; see also `bibtex-entry'."
+                                entry)
+                        '(interactive "*")
+                        `(bibtex-entry ,entry))))
+          ;; Menu entries
+          (define-key menu-map (vector fname)
+            `(menu-item ,(or (nth 1 elt) (car elt)) ,fname))))
+      (define-key bibtex-mode-map
+        (vector 'menu-bar dialect)
+        `(menu-item "Entry-Types" ,menu-map
+                    :visible (eq bibtex-dialect ',dialect))))))
 
 (defun bibtex-field-list (entry-type)
   "Return list of allowed fields for entry ENTRY-TYPE.
@@ -3505,7 +3528,7 @@
     (cons required optional)))
 
 (defun bibtex-entry (entry-type)
-  "Insert a new BibTeX entry of type ENTRY-TYPE.
+  "Insert a template for a BibTeX entry of type ENTRY-TYPE.
 After insertion call the value of `bibtex-add-entry-hook' if that value
 is non-nil."
   (interactive





^ permalink raw reply	[flat|nested] 18+ messages in thread

* bug#10254: 24.0.92; Local variable bibtex-dialect has no effect
  2012-01-28  8:17                   ` Roland Winkler
@ 2012-01-28 14:05                     ` Chong Yidong
  2012-01-28 18:13                       ` Roland Winkler
  0 siblings, 1 reply; 18+ messages in thread
From: Chong Yidong @ 2012-01-28 14:05 UTC (permalink / raw)
  To: Roland Winkler; +Cc: Uwe Siart, 10254

"Roland Winkler" <winkler@gnu.org> writes:

> OK, here is a new version of the patch that uses by default a plain 
>
>   (set var val)
>
> to make all the relevant settings. But if bibtex-set-dialect is
> called interactively or bibtex-dialect is already buffer-local (for
> example, as a file-local variable), then it uses
>
>   (set (make-local-variable var) val)
>
> I think this should cover all possibilities.
>
> If that's what you had in mind, the patch below could go into the
> next pretest.

Please go ahead and commit it.





^ permalink raw reply	[flat|nested] 18+ messages in thread

* bug#10254: 24.0.92; Local variable bibtex-dialect has no effect
  2012-01-28 14:05                     ` Chong Yidong
@ 2012-01-28 18:13                       ` Roland Winkler
  0 siblings, 0 replies; 18+ messages in thread
From: Roland Winkler @ 2012-01-28 18:13 UTC (permalink / raw)
  To: 10254-done

Version: 24.1

2012-01-28  Roland Winkler  <winkler@gnu.org>

	* textmodes/bibtex.el (bibtex-entry-alist): New function.
	(bibtex-set-dialect): Use it.  Either set global values of
	dialect-dependent variables or bind these variables buffer-locally
	(Bug#10254).
	(bibtex-mode): Call bibtex-set-dialect via
	hack-local-variables-hook.
	(bibtex-dialect): Update docstring.  Add
	safe-local-variable predicate.
	(bibtex-entry-alist, bibtex-field-alist): Initialize via
	bibtex-set-dialect.
	(bibtex-mode-map): Define menu for each dialect.
	(bibtex-entry): Fix docstring.






^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2012-01-28 18:13 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-12-09  7:29 bug#10254: 24.0.92; Local variable bibtex-dialect has no effect Uwe Siart
2011-12-10  7:43 ` Glenn Morris
2011-12-10  9:12   ` Uwe Siart
2012-01-10  1:24     ` Glenn Morris
2012-01-10 18:33       ` Roland Winkler
2012-01-11  6:41         ` Uwe Siart
2012-01-11 10:46           ` Roland Winkler
2012-01-11 14:57             ` Uwe Siart
2012-01-15  9:04       ` Roland Winkler
2012-01-16 14:14         ` Stefan Monnier
2012-01-16 22:21           ` Roland Winkler
2012-01-17  5:44             ` Uwe Siart
2012-01-17 14:04             ` Stefan Monnier
2012-01-17 20:45               ` Roland Winkler
2012-01-17 21:21                 ` Stefan Monnier
2012-01-28  8:17                   ` Roland Winkler
2012-01-28 14:05                     ` Chong Yidong
2012-01-28 18:13                       ` Roland Winkler

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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).