From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Roland Winkler" Newsgroups: gmane.emacs.bugs Subject: bug#10254: 24.0.92; Local variable bibtex-dialect has no effect Date: Sun, 15 Jan 2012 03:04:02 -0600 Message-ID: <20242.38530.735318.867329@gargle.gargle.HOWL> References: <844nxakxtd.fsf@tum.de> <4EE32275.26106.E38FFC3@uwe.siart.tum.de> <2rfwfoz6w2.fsf@fencepost.gnu.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1326618333 13278 80.91.229.12 (15 Jan 2012 09:05:33 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sun, 15 Jan 2012 09:05:33 +0000 (UTC) Cc: Uwe Siart , 10254@debbugs.gnu.org To: Glenn Morris Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Jan 15 10:05:27 2012 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1RmM1h-0002Nf-1u for geb-bug-gnu-emacs@m.gmane.org; Sun, 15 Jan 2012 10:05:21 +0100 Original-Received: from localhost ([::1]:55718 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RmM1g-0006co-3i for geb-bug-gnu-emacs@m.gmane.org; Sun, 15 Jan 2012 04:05:20 -0500 Original-Received: from eggs.gnu.org ([140.186.70.92]:42840) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RmM1c-0006ch-8p for bug-gnu-emacs@gnu.org; Sun, 15 Jan 2012 04:05:17 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RmM1a-0001J5-H3 for bug-gnu-emacs@gnu.org; Sun, 15 Jan 2012 04:05:16 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:34937) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RmM1a-0001Iw-Ec for bug-gnu-emacs@gnu.org; Sun, 15 Jan 2012 04:05:14 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1RmM2L-00078r-Kv for bug-gnu-emacs@gnu.org; Sun, 15 Jan 2012 04:06:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: "Roland Winkler" Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 15 Jan 2012 09:06:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 10254 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 10254-submit@debbugs.gnu.org id=B10254.132661831427397 (code B ref 10254); Sun, 15 Jan 2012 09:06:01 +0000 Original-Received: (at 10254) by debbugs.gnu.org; 15 Jan 2012 09:05:14 +0000 Original-Received: from localhost ([127.0.0.1]:57843 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1RmM1Z-00077p-TE for submit@debbugs.gnu.org; Sun, 15 Jan 2012 04:05:14 -0500 Original-Received: from fencepost.gnu.org ([140.186.70.10]:44117) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1RmM1X-00077h-5P for 10254@debbugs.gnu.org; Sun, 15 Jan 2012 04:05:12 -0500 Original-Received: from 82.red-80-32-229.staticip.rima-tde.net ([80.32.229.82]:41091 helo=regnitz) by fencepost.gnu.org with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1RmM0e-0006Ic-KO; Sun, 15 Jan 2012 04:04:20 -0500 In-Reply-To: <2rfwfoz6w2.fsf@fencepost.gnu.org> X-Mailer: VM 8.2 trial under 24.0.92.1 (x86_64-unknown-linux-gnu) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:55761 Archived-At: 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 @@ ;; 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