From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Ryan Kavanagh Newsgroups: gmane.emacs.bugs Subject: bug#36252: 26.1; bibtex-generate-autokey does not use use date field Date: Sun, 16 Jun 2019 16:23:30 -0400 Message-ID: <20190616202330.immdadcg24qedysq@zeta.rak.ac> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="u4b4fqvhgdoo6zu3" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="158774"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: NeoMutt/20180716 To: 36252@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Jun 16 22:24:12 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1hcbhC-000fAd-3U for geb-bug-gnu-emacs@m.gmane.org; Sun, 16 Jun 2019 22:24:10 +0200 Original-Received: from localhost ([::1]:42700 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hcbhB-0003gU-5D for geb-bug-gnu-emacs@m.gmane.org; Sun, 16 Jun 2019 16:24:09 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:53783) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hcbh5-0003gB-PC for bug-gnu-emacs@gnu.org; Sun, 16 Jun 2019 16:24:05 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hcbh4-0006U4-Bs for bug-gnu-emacs@gnu.org; Sun, 16 Jun 2019 16:24:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:56220) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hcbh4-0006Tv-6f for bug-gnu-emacs@gnu.org; Sun, 16 Jun 2019 16:24:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hcbh4-0003yl-1V for bug-gnu-emacs@gnu.org; Sun, 16 Jun 2019 16:24:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Ryan Kavanagh Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 16 Jun 2019 20:24:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 36252 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: submit@debbugs.gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.156071661915257 (code B ref -1); Sun, 16 Jun 2019 20:24:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 16 Jun 2019 20:23:39 +0000 Original-Received: from localhost ([127.0.0.1]:41531 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hcbgh-0003y0-9U for submit@debbugs.gnu.org; Sun, 16 Jun 2019 16:23:39 -0400 Original-Received: from mail-qk1-f172.google.com ([209.85.222.172]:43951) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hcbgf-0003xm-S0 for submit@debbugs.gnu.org; Sun, 16 Jun 2019 16:23:38 -0400 Original-Received: by mail-qk1-f172.google.com with SMTP id m14so4986554qka.10 for ; Sun, 16 Jun 2019 13:23:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:subject:message-id:mime-version :content-disposition:user-agent; bh=xfyce6vaOyn4zkv304V9Td3y6Y1looGYJY8jAqUNv88=; b=HmlBXY4wftoidEkybwP0NoYWopCDZPidK9H2zdxkD6fu/IYuLvRhKlmf9YceDKygKq /3xnOX030q0nFqioYjMUF4f9JDca2qK42iCB591vZC2qNjJdyCoTCfWfzNZIZha8OZQo MGw2hYF8B0V2Dr3tic7m20sDQ8XIQS1JpK0wQGExWwIWVEG29qvU9eiZ+WzAuoaajZ/V zs7QSTqGoF+YJPL1douWBQ2hw3VnOeM6ZbIjYBUR4giMP2y7ObSTMfgmDcfuPe9nb4re DLvMefj6MdOFAfzKJT61cS70AxIdRoY+yN56Dv0nZeQRuZIxT+5+J++gLMshZoIC3cFP BUGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:subject:message-id :mime-version:content-disposition:user-agent; bh=xfyce6vaOyn4zkv304V9Td3y6Y1looGYJY8jAqUNv88=; b=AWr840BMWgFbxGyby+gjk3VpNVq+QFeT/mkaVg3QQ5B8io9AuVpBuJuj4bUnUI5CLL 7eEV89BAZ9aeCIdf18u5+BEBRDmmJunTHYtlHZbm4T5sNUIKm8JE0t+1ncL7Yfcd4zJ9 3VGVranIleACUnQ5vgy7m+fqXW0OjY1T4Ap0raPXRfQIsbVokccDpmn7cG+XM/+FGSeq /HB8/pbfam0PMTibeiC5zOuPN2xOLBqRoN2lm+09sBmtMlyFHUiVWs6jSCEwbUm8m3Pe s1t1QhOkKnVXGCsngxPUFV3udqMq7PGqASoU3yKQe9NahG/6cqEQH+Syo8Qwi1iyxqkZ d2rw== X-Gm-Message-State: APjAAAUcmAgspLI6KIO6JAyA9bepwL58nOcdCMxj1W2lJSC+oz0Juaai bt655OeRhNPg+cXb4xbn9U8OAnXN X-Google-Smtp-Source: APXvYqxzFbgAMPau1a29r9GiF7hevjWEcwz49DN/EJ5aFUGKvFx4l7ovz/Bb4CfwVqc5/S3Ddgfjmg== X-Received: by 2002:a05:620a:16b2:: with SMTP id s18mr79704968qkj.323.1560716611678; Sun, 16 Jun 2019 13:23:31 -0700 (PDT) Original-Received: from zeta.rak.ac (c-98-239-128-52.hsd1.pa.comcast.net. [98.239.128.52]) by smtp.gmail.com with ESMTPSA id k55sm7886509qtf.68.2019.06.16.13.23.29 for (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sun, 16 Jun 2019 13:23:30 -0700 (PDT) Content-Disposition: inline X-message-flag: Please do NOT send HTML e-mail or MS Word attachments - use plain text instead X-GPG-ID: 0x8F7BF8FC4A11C97A X-GPG-Fingerprint: 4E46 9519 ED67 7734 268F BD95 8F7B F8FC 4A11 C97A X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.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" Xref: news.gmane.org gmane.emacs.bugs:160696 Archived-At: --u4b4fqvhgdoo6zu3 Content-Type: multipart/mixed; boundary="ebm2gq44lagwdwfv" Content-Disposition: inline --ebm2gq44lagwdwfv Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Package: emacs Version: 26.1 Tags: patch The bibtex.el package will automatically generate a key for a BibTeX entry when required. To do so, it extracts the year from the 'year' field. Instead of the 'year' field, the biblatex dialect uses the 'date' field to record the publication date. The bibtex-generate-autokey function should fallback to the date field when the year field is absent. This requires a bit of care because the 'date' field can contain an arbitrary date satisfying the "ISO8601-2 Extended Format Specification Level 1". Fortunately, a relatively simple regex can extract the year from all of the examples listed in the biblatex manual[0]. Please see attached for a patch adding support for the 'date' field. [0] http://mirrors.ibiblio.org/CTAN/macros/latex/exptl/biblatex/doc/biblate= x.pdf --=20 |)|/ Ryan Kavanagh | GPG: 4E46 9519 ED67 7734 268F |\|\ https://rak.ac | BD95 8F7B F8FC 4A11 C97A --ebm2gq44lagwdwfv Content-Type: text/x-diff; charset=utf-8 Content-Disposition: attachment; filename="0001-Fallback-to-date-field-when-year-field-is-absent-in-.patch" Content-Transfer-Encoding: quoted-printable =46rom 80224ef879ba34d637ed9c538d813799321b6a3f Mon Sep 17 00:00:00 2001 =46rom: Ryan Kavanagh Date: Sun, 16 Jun 2019 16:20:26 -0400 Subject: [PATCH] Fallback to date field when year field is absent in bibtex files The bibtex.el package automatically generates a key for a BibTeX entry when required. To do so, it extracts the year from the 'year' field. Instead of the 'year' field, the biblatex dialect uses the 'date' field to record the publication date. The bibtex-generate-autokey function should fallback to the date field when the year field is absent. --- lisp/textmodes/bibtex.el | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/lisp/textmodes/bibtex.el b/lisp/textmodes/bibtex.el index a560c2b097..62482e3ae8 100644 --- a/lisp/textmodes/bibtex.el +++ b/lisp/textmodes/bibtex.el @@ -2707,10 +2707,24 @@ and `bibtex-autokey-names-stretch'." (bibtex-autokey-abbrev name bibtex-autokey-name-length)))) =20 (defun bibtex-autokey-get-year () - "Return year field contents as a string obeying `bibtex-autokey-year-len= gth'." - (let ((yearfield (bibtex-autokey-get-field "year"))) - (substring yearfield (max 0 (- (length yearfield) - bibtex-autokey-year-length))))) + "Return year field contents as a string obeying `bibtex-autokey-year-len= gth'. +If the year field is absent, extract the year from a valid ISO8601-2 +Extended Format date in the date field and return it as a string obeying +`bibtex-autokey-year-length'." + (let ((yearfield (bibtex-autokey-get-field "year")) + (datefield (bibtex-autokey-get-field "date")) + (shortener (lambda (year) + (substring year (max 0 (- (length year) + bibtex-autokey-year-length)))))) + (if (string=3D "" yearfield) + (cond ((string-match "[./]*\\(-?[[:digit:]]+X*\\)\\([-/.[:digit:]:T~?%X]*= \\)" + datefield) + ;; Matches ISO8601-2 Extended Format specification level 1 + ;; examples listed in tables 3, 4, and 5 on pp. 38-40 of the + ;; biblatex package manual, version 3.12 + (funcall shortener (match-string 1 datefield))) + (t (error "Date field `%s' is incorrectly formed" datefield))) + (funcall shortener yearfield)))) =20 (defun bibtex-autokey-get-title () "Get title field contents up to a terminator. @@ -2795,8 +2809,10 @@ 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 + 2. If the year field is absent, extract the year from the date field + and truncate in the same manner. + 3. If the both fields (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 field of the crossreferenced entry instead. =20 --=20 2.20.1 --ebm2gq44lagwdwfv-- --u4b4fqvhgdoo6zu3 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQUzBAABCgAdFiEETkaVGe1ndzQmj72Vj3v4/EoRyXoFAl0GpT4ACgkQj3v4/EoR yXqhuSf/b69vbjJncLjZ+jagQol2ukonfYKe7wgNQjcJe1EvixBi+N0nz/V7+CVm +2KUiRjD9TUhQmz8O3zsMNgbLHaUFadvQGuO20WM2OIfikIBoMr2Kfv4QXmYuCaz j4harHB7BXYOq03idSzPbqu1WkDakKphjlBRJIdzo2EGrLbPcOu/gToa+96+rzav FCcLnrcVjQbe3gjA5HOYtTGkwP8VH+yeCGr3tuRc22OY+V+MR6QqZ/4Xphz+GoeL wJFHDSK9aUvkU4PPJfEWDrGR246i9edFXNxh39YSOiZWRvo0C3fffyLgUWV5PI9I RZatznzzRkKncrvGAOUUDkl3wFPG3iorsLMG5pThh/Itd9tQRwIWVB7ZvjRsbni4 35dSsRuCiLTQuE/wj520tDCue84KW5xOXbbypRCD56jFekpZceImwcdVtFE9wiAZ lTd0VG8ycY+UYM9KWL3fkkNcGGDpDEBtXO02/zy5FGgLNa0U9UVfgQq1jTC5b+uq nMp8BN9QHA0UW9Dzi1YF9YxdrweDPWBYZhJYLMPHfw755Kgm4zCwLHAnUvIOg+xO LpmNYDPH7xQbL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