From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Patrick M. Niedzielski Newsgroups: gmane.emacs.bugs Subject: bug#36252: 26.1; bibtex-generate-autokey does not use use date field Date: Sat, 05 Dec 2020 09:20:52 +0000 Message-ID: <87im9gpq17.fsf@pniedzielski.net> References: <20190616202330.immdadcg24qedysq@zeta.rak.ac> <871rz3dxfw.fsf@mouse.gnus.org> <20190715003421.qrb65bynacpxca2k@zeta.rak.ac> <87k1a8q7ld.fsf@gnus.org> <87sgcu7oja.fsf@gnus.org> <87pn6o766s.fsf@gnus.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="27386"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 36252@debbugs.gnu.org To: Lars Ingebrigtsen , Ryan Kavanagh Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Dec 05 19:34:24 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 1klcNy-0006xO-Cc for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 05 Dec 2020 19:34:22 +0100 Original-Received: from localhost ([::1]:50922 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1klcNx-0005BJ-FK for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 05 Dec 2020 13:34:21 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:41430) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1klcNf-00050o-4i for bug-gnu-emacs@gnu.org; Sat, 05 Dec 2020 13:34:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:36684) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1klcNd-0004Aa-UG for bug-gnu-emacs@gnu.org; Sat, 05 Dec 2020 13:34:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1klcNd-0000qo-Qs for bug-gnu-emacs@gnu.org; Sat, 05 Dec 2020 13:34:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Patrick M. Niedzielski Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 05 Dec 2020 18:34:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 36252 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: moreinfo Original-Received: via spool by 36252-submit@debbugs.gnu.org id=B36252.16071932313238 (code B ref 36252); Sat, 05 Dec 2020 18:34:01 +0000 Original-Received: (at 36252) by debbugs.gnu.org; 5 Dec 2020 18:33:51 +0000 Original-Received: from localhost ([127.0.0.1]:48226 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1klcNS-0000q9-Ig for submit@debbugs.gnu.org; Sat, 05 Dec 2020 13:33:50 -0500 Original-Received: from tocharian.pniedzielski.net ([138.197.203.133]:40680) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1klTkY-0007m0-Ai for 36252@debbugs.gnu.org; Sat, 05 Dec 2020 04:21:09 -0500 Original-Received: from localhost (c-71-233-244-237.hsd1.ma.comcast.net [71.233.244.237]) by tocharian.pniedzielski.net (Postfix) with ESMTPSA id 4F9F02365D; Sat, 5 Dec 2020 09:21:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=pniedzielski.net; s=2019; t=1607160060; bh=elN6g8f5xI/DV88MvOdLQ9czYE8lY7x8ociS28PyLqs=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=k/YiSHpJmCW+H0r4hcCq9bvmCAXgc2lAKGZzFeprNH/DEDeh1pJ7Nn+DUm7nexjgx npU3KBSigc9HTYpccM6TTmZUfC3Y3oiuLfOcvegZ8RuZnsKqPCl3l7gRDgOBWSeSom wnThSQ4vadAiNQX/a3eirT4s2wzu7VhqKsJUkMDoYV/0vIx/EC/0Wjv8TBOsoAcmgB pjF1PYMuHORjnWoNgNPKT2qbDHJ15EM5u8I38rYDySBdKCMgF2o+o8zH/Gc7g50Iu8 d1adzxNh4BAQFs5x5m3tUpXkYqhS+eFwUy29Kv5Lx/ZeU+KAygo8lzt/9vSiHueMCu cHr1AUAY0Os4A== In-Reply-To: <87pn6o766s.fsf@gnus.org> X-Mailman-Approved-At: Sat, 05 Dec 2020 13:33:49 -0500 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:195045 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable Lars Ingebrigtsen skribis: > Lars Ingebrigtsen writes:=20 >=20 > This was five weeks ago, and there was no response, so I'm=20 > closing this bug report. If progress can be made here, please=20 > respond to the debbugs mail address, and we'll reopen the bug=20 > report.=20 I=E2=80=99d like to reopen this bug, and submit the attached patch which I= =20 believe fixes the issue. This patch teaches=20 =E2=80=98bibtex-generate-autokey=E2=80=99 to prefer an ISO8601-formatted = =E2=80=98date=E2=80=99=20 field when present, and fall back to a =E2=80=98year=E2=80=99, and is imple= mented=20 using Lars=E2=80=99 ISO8601 parsing functions. Just some implementation notes: I don=E2=80=99t believe Ryan=E2=80=99s orig= inal=20 patch works as documented when =E2=80=98bibtex-autokey-use-crossref=E2=80= =99 is=20 non-nil. In this case, his patch would seem to prefer a=20 crossref=E2=80=99d entry=E2=80=99s =E2=80=98year=E2=80=99 field to a local = entry=E2=80=99s =E2=80=98date=E2=80=99 field.=20 More concretely, with the following BibLaTeX, @misc{doe1995some, title =3D {Some work}, author =3D {John Doe}, year =3D {1995}, date =3D {1995-01-01}, }=20 @misc{, title =3D {Another work}, author =3D {Anon Y. Mous}, date =3D {1990-03-12}, crossref =3D {entry1}, } When generating a key for entry2, the original patch would prefer=20 using the year 1995 to the year 1990, which is unintuitive. The=20 attached patch implements a different behavior instead, in which=20 an entry=E2=80=99s own =E2=80=98year/date=E2=80=99 field are prefered to th= e crossref=E2=80=99d=20 entry=E2=80=99s =E2=80=98year/date=E2=80=99 field. In the above case,=20 =E2=80=98bibtex-generate-autokey=E2=80=99 will generate a entry key with th= e year=20 1990 rather than 1995. Additionally, we prefer to use the =E2=80=98date=E2=80=99 field when presen= t over=20 the =E2=80=98year=E2=80=99 field. This behavior is probably more correct, s= ince=20 BibLaTeX deprecated the =E2=80=98year=E2=80=99 field in favor of its own = =E2=80=98date=E2=80=99=20 field, which only should occur in BibLaTeX-flavor files. Note that=20 this is a breaking change from the prior behavior, but only when=20 an entry has incompatible =E2=80=98date=E2=80=99 and =E2=80=98year=E2=80=99= fields. If a file is=20 meant to support both BibTeX and BibLaTeX, the =E2=80=98date=E2=80=99 and = =E2=80=98year=E2=80=99=20 fields should contain the same information. The attached patch implements the above behavior. Best, Patrick --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Prefer-date-field-to-year-field-in-BibTex-entry.patch >From 26cb162d42e7fd234506a5f847fbfb73adb68105 Mon Sep 17 00:00:00 2001 From: "Patrick M. Niedzielski" Date: Sun, 29 Nov 2020 02:09:47 +0000 Subject: [PATCH] Prefer date field to year field in BibTex entry The bibtex.el package contains functionality to automatically generate a key for a BibTeX entry using author/editor, year, and title information in the entry. The BibLaTeX dialect has deprecated the 'year' field (and 'month') in favor of an ISO8601-formatted 'date' field. This patch teaches the 'bibtex-generate-autokey' function to prefer a 'date' field when present, and fall back to a 'year' field for bibtex compatibility. --- lisp/textmodes/bibtex.el | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/lisp/textmodes/bibtex.el b/lisp/textmodes/bibtex.el index c9e21e58f6..fe468d261d 100644 --- a/lisp/textmodes/bibtex.el +++ b/lisp/textmodes/bibtex.el @@ -2751,10 +2751,16 @@ and `bibtex-autokey-names-stretch'." (bibtex-autokey-abbrev name bibtex-autokey-name-length)))) (defun bibtex-autokey-get-year () - "Return year field contents as a string obeying `bibtex-autokey-year-length'." - (let ((yearfield (bibtex-autokey-get-field "year"))) - (substring yearfield (max 0 (- (length yearfield) - bibtex-autokey-year-length))))) + "If date field exists, return year component of the ISO8601-formatted +date field contents as a string obeying `bibtex-autokey-year-length'. +Otherwise, return year field contents as a string obeying +`bibtex-autokey-year-length'." + (let* ((yearfield (bibtex-autokey-get-field "year\\|date")) + (dateyear (if (iso8601-valid-p yearfield) + (decoded-time-year (iso8601-parse yearfield)) + nil)) + (year (if dateyear (number-to-string dateyear) ""))) + (substring year (max 0 (- (length year) bibtex-autokey-year-length))))) (defun bibtex-autokey-get-title () "Get title field contents up to a terminator. @@ -2837,12 +2843,16 @@ The name part: The year part: 1. Build the year part of the key by truncating the content of the year - field to the rightmost `bibtex-autokey-year-length' digits (useful - values are 2 and 4). - 2. If the year field (or any other field required to generate the key) - is absent, but the entry has a valid crossref field and - `bibtex-autokey-use-crossref' is non-nil, use the field of the - crossreferenced entry instead. + component of the ISO8601-formatted date field to the rightmost + `bibtex-autokey-year-length' digits (useful values are 2 and 4). + 2. If the date field is absent, but the entry has a year field, build the + year part of the key by truncating the year field to the rightmost + `bibtex-autokey-year-length' digits. + 3. If both the year field and the date field (or any other field + required to generate the key) are absent, but the entry has a + valid crossref field and `bibtex-autokey-use-crossref' is + non-nil, use the date or year field of the crossreferenced entry + instead. The title part 1. Change the content of the title field according to -- 2.29.2 --=-=-=--