From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Francesco =?UTF-8?Q?Potort=C3=AC?= Newsgroups: gmane.emacs.bugs Subject: bug#44614: 26.3; bibtex convert case undefined Date: Sat, 14 Nov 2020 19:47:36 +0100 Message-ID: References: <87v9e7yk2x.fsf@gnus.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="14337"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 44614@debbugs.gnu.org To: Lars Ingebrigtsen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Nov 14 19:48:18 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ke0av-0003b2-6y for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 14 Nov 2020 19:48:17 +0100 Original-Received: from localhost ([::1]:40504 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ke0at-0004pi-P9 for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 14 Nov 2020 13:48:15 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:45668) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ke0af-0004pY-T6 for bug-gnu-emacs@gnu.org; Sat, 14 Nov 2020 13:48:01 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:40483) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ke0af-00011K-JB for bug-gnu-emacs@gnu.org; Sat, 14 Nov 2020 13:48:01 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ke0af-0000N8-IV for bug-gnu-emacs@gnu.org; Sat, 14 Nov 2020 13:48:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Francesco =?UTF-8?Q?Potort=C3=AC?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 14 Nov 2020 18:48:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 44614 X-GNU-PR-Package: emacs Original-Received: via spool by 44614-submit@debbugs.gnu.org id=B44614.16053796611403 (code B ref 44614); Sat, 14 Nov 2020 18:48:01 +0000 Original-Received: (at 44614) by debbugs.gnu.org; 14 Nov 2020 18:47:41 +0000 Original-Received: from localhost ([127.0.0.1]:52029 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ke0aL-0000MZ-6s for submit@debbugs.gnu.org; Sat, 14 Nov 2020 13:47:41 -0500 Original-Received: from smtp-clients1.isti.cnr.it ([146.48.28.36]:46370) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ke0aJ-0000MP-4u for 44614@debbugs.gnu.org; Sat, 14 Nov 2020 13:47:39 -0500 Original-Received: from tucano.isti.cnr.it (tucano.isti.cnr.it [146.48.81.102]) (Authenticated sender: pot) by smtp-clients1.isti.cnr.it (Postfix) with ESMTPSA id 213D5B0833; Sat, 14 Nov 2020 19:47:36 +0100 (CET) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.102.4 at smtp-out.isti.cnr.it Original-Received: from pot by tucano.isti.cnr.it with local (Exim 4.94) (envelope-from ) id 1ke0aG-00GCSc-LE; Sat, 14 Nov 2020 19:47:36 +0100 In-reply-to: <87v9e7yk2x.fsf@gnus.org> (larsi@gnus.org) X-fingerprint: 4B02 6187 5C03 D6B1 2E31 7666 09DF 2DC9 BE21 6115 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:193322 Archived-At: >> An old version of bibtex.el (last copyright 1997) uniquified cases based >> on the bibtex-unify-case-convert variable, which is now removed. >> >> This is unfortunate, and in my opinion a bug. > >I tried to poke around to see whether there's any reason the variable >was removed, but I can't find any mention of it in the Emacs tree, so >it's possible that the in-tree version of bibtex.el never had the >variable? Mh. I found a very old version that i had set aside with the name bibtex.el.orig, which does not contain that variable, so it may well be that I had introduced that variable myself as a local change with the aim of pushing it in the Emacs tree but then I forgot to do that. It was a long time ago, so I may well have forgotten. Anyway, here is my patch, which I think does not make any harm. It changes the behaviour slightly in what I consider it being a more consistent way. When unifying is requested, in the default case, which is 'identity, if an unknown field is found it is not unified (rather than being downcased as it is now): only known fields are unified to the known case. Note that the last hunk is only a change of 'if' with 'when', it is big because of reindentation and just a matter of aesthetics (or clarity). *** bibtex-2019.el 2020-11-13 11:54:34.000000000 +0100 --- bibtex.el 2020-11-14 19:05:48.000000000 +0100 *************** *** 89,92 **** --- 89,103 ---- (put 'bibtex-include-OPTkey 'risky-local-variable t) + (defcustom bibtex-unify-case-convert 'identity + "*Function called when unifying case on entry and field names. + This variable is buffer-local." + :group 'bibtex + :type '(choice (const :tag "Same case as in `bibtex-field-alist'" identity) + (const :tag "Downcase" downcase) + (const :tag "Capitalize" capitalize) + (const :tag "Upcase" upcase) + (function :tag "Conversion function"))) + (make-variable-buffer-local 'bibtex-unify-case-convert) + (defcustom bibtex-user-optional-fields '(("annote" "Personal annotation (ignored)")) *************** *** 123,127 **** delimiters Change delimiters according to variables `bibtex-field-delimiters' and `bibtex-entry-delimiters'. ! unify-case Change case of entry types and field names. braces Enclose parts of field entries by braces according to `bibtex-field-braces-alist'. --- 134,139 ---- delimiters Change delimiters according to variables `bibtex-field-delimiters' and `bibtex-entry-delimiters'. ! unify-case Change case of entry and field names according to ! `bibtex-unify-case-convert'. braces Enclose parts of field entries by braces according to `bibtex-field-braces-alist'. *************** *** 2309,2313 **** (when (memq 'unify-case format) (delete-region beg-type end-type) ! (insert (car entry-list))) ;; update left entry delimiter --- 2321,2325 ---- (when (memq 'unify-case format) (delete-region beg-type end-type) ! (insert (funcall bibtex-unify-case-convert (car entry-list)))) ;; update left entry delimiter *************** *** 2510,2523 **** ;; unify case of field name ! (if (memq 'unify-case format) ! (let ((fname (car (assoc-string field-name ! default-field-list t)))) ! (if fname ! (progn ! (delete-region beg-name end-name) ! (goto-char beg-name) ! (insert fname)) ! ;; there are no rules we could follow ! (downcase-region beg-name end-name)))) ;; update point --- 2522,2533 ---- ;; unify case of field name ! (when (memq 'unify-case format) ! (let ((fname (car (assoc-string field-name ! default-field-list t))) ! (curname (buffer-substring beg-name end-name))) ! (delete-region beg-name end-name) ! (goto-char beg-name) ! (insert (funcall bibtex-unify-case-convert ! (or fname curname))))) ;; update point *************** *** 2525,2554 **** ;; check whether all required fields are present ! (if (memq 'required-fields format) ! (let ((alt-expect (make-vector num-alt nil)) ! (alt-found (make-vector num-alt 0))) ! (dolist (fname req-field-list) ! (cond ((setq idx (nth 3 fname)) ! ;; t if field has alternative flag ! (bibtex-vec-push alt-expect idx (car fname)) ! (if (member-ignore-case (car fname) field-list) ! (bibtex-vec-incr alt-found idx))) ! ((not (member-ignore-case (car fname) field-list)) ! ;; If we use the crossref field, a required field ! ;; can have the OPT prefix. So if it was empty, ! ;; we have deleted by now. Nonetheless we can ! ;; move point on this empty field. ! (setq error-field-name (car fname)) ! (error "Mandatory field `%s' is missing" (car fname))))) ! (dotimes (idx num-alt) ! (cond ((= 0 (aref alt-found idx)) ! (setq error-field-name (car (last (aref alt-fields idx)))) ! (error "Alternative mandatory field `%s' is missing" ! (aref alt-expect idx))) ! ((< 1 (aref alt-found idx)) ! (setq error-field-name (car (last (aref alt-fields idx)))) ! (error "Alternative fields `%s' are defined %s times" ! (aref alt-expect idx) ! (length (aref alt-fields idx)))))))) ;; update comma after last field --- 2535,2564 ---- ;; check whether all required fields are present ! (when (memq 'required-fields format) ! (let ((alt-expect (make-vector num-alt nil)) ! (alt-found (make-vector num-alt 0))) ! (dolist (fname req-field-list) ! (cond ((setq idx (nth 3 fname)) ! ;; t if field has alternative flag ! (bibtex-vec-push alt-expect idx (car fname)) ! (if (member-ignore-case (car fname) field-list) ! (bibtex-vec-incr alt-found idx))) ! ((not (member-ignore-case (car fname) field-list)) ! ;; If we use the crossref field, a required field ! ;; can have the OPT prefix. So if it was empty, ! ;; we have deleted by now. Nonetheless we can ! ;; move point on this empty field. ! (setq error-field-name (car fname)) ! (error "Mandatory field `%s' is missing" (car fname))))) ! (dotimes (idx num-alt) ! (cond ((= 0 (aref alt-found idx)) ! (setq error-field-name (car (last (aref alt-fields idx)))) ! (error "Alternative mandatory field `%s' is missing" ! (aref alt-expect idx))) ! ((< 1 (aref alt-found idx)) ! (setq error-field-name (car (last (aref alt-fields idx)))) ! (error "Alternative fields `%s' are defined %s times" ! (aref alt-expect idx) ! (length (aref alt-fields idx)))))))) ;; update comma after last field