all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Francesco Potortì" <pot@gnu.org>
To: Lars Ingebrigtsen <larsi@gnus.org>
Cc: 44614@debbugs.gnu.org
Subject: bug#44614: 26.3; bibtex convert case undefined
Date: Sat, 14 Nov 2020 19:47:36 +0100	[thread overview]
Message-ID: <E1ke0aG-00GCSc-LE@tucano.isti.cnr.it> (raw)
In-Reply-To: <87v9e7yk2x.fsf@gnus.org> (larsi@gnus.org)

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






  reply	other threads:[~2020-11-14 18:47 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-13 11:05 bug#44614: 26.3; bibtex convert case undefined Francesco Potortì
2020-11-14 16:33 ` Lars Ingebrigtsen
2020-11-14 18:47   ` Francesco Potortì [this message]
2020-11-16 21:36     ` Lars Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=E1ke0aG-00GCSc-LE@tucano.isti.cnr.it \
    --to=pot@gnu.org \
    --cc=44614@debbugs.gnu.org \
    --cc=larsi@gnus.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.