unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#36252: 26.1; bibtex-generate-autokey does not use use date field
@ 2019-06-16 20:23 Ryan Kavanagh
  2019-07-06 14:52 ` Lars Ingebrigtsen
  2019-07-06 14:55 ` Lars Ingebrigtsen
  0 siblings, 2 replies; 15+ messages in thread
From: Ryan Kavanagh @ 2019-06-16 20:23 UTC (permalink / raw)
  To: 36252


[-- Attachment #1.1: Type: text/plain, Size: 953 bytes --]

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/biblatex.pdf

-- 
|)|/  Ryan Kavanagh      | GPG: 4E46 9519 ED67 7734 268F
|\|\  https://rak.ac     |      BD95 8F7B F8FC 4A11 C97A

[-- Attachment #1.2: 0001-Fallback-to-date-field-when-year-field-is-absent-in-.patch --]
[-- Type: text/x-diff, Size: 3114 bytes --]

From 80224ef879ba34d637ed9c538d813799321b6a3f Mon Sep 17 00:00:00 2001
From: Ryan Kavanagh <rak@debian.org>
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))))
 
 (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)))))
+  "Return year field contents as a string obeying `bibtex-autokey-year-length'.
+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= "" 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))))
 
 (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.
 
-- 
2.20.1


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 1873 bytes --]

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* bug#36252: 26.1; bibtex-generate-autokey does not use use date field
  2019-06-16 20:23 bug#36252: 26.1; bibtex-generate-autokey does not use use date field Ryan Kavanagh
@ 2019-07-06 14:52 ` Lars Ingebrigtsen
  2019-07-06 14:55 ` Lars Ingebrigtsen
  1 sibling, 0 replies; 15+ messages in thread
From: Lars Ingebrigtsen @ 2019-07-06 14:52 UTC (permalink / raw)
  To: Ryan Kavanagh; +Cc: 36252

Ryan Kavanagh <rak@debian.org> writes:

> 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 makes sense to me, but I'm not a bibtex user.  Anybody else that
can take a look at this patch?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#36252: 26.1; bibtex-generate-autokey does not use use date field
  2019-06-16 20:23 bug#36252: 26.1; bibtex-generate-autokey does not use use date field Ryan Kavanagh
  2019-07-06 14:52 ` Lars Ingebrigtsen
@ 2019-07-06 14:55 ` Lars Ingebrigtsen
  2019-07-15  0:34   ` Ryan Kavanagh
  1 sibling, 1 reply; 15+ messages in thread
From: Lars Ingebrigtsen @ 2019-07-06 14:55 UTC (permalink / raw)
  To: Ryan Kavanagh; +Cc: 36252

Ryan Kavanagh <rak@debian.org> writes:

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

(This reminds me -- Emacs should really have a parser that can parse all
ISO8601 variants.  There's parse-iso8601-time-string, but it only
handles the simplest of the formats...)

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#36252: 26.1; bibtex-generate-autokey does not use use date field
  2019-07-06 14:55 ` Lars Ingebrigtsen
@ 2019-07-15  0:34   ` Ryan Kavanagh
  2019-07-15  7:24     ` Lars Ingebrigtsen
  0 siblings, 1 reply; 15+ messages in thread
From: Ryan Kavanagh @ 2019-07-15  0:34 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 36252

[-- Attachment #1: Type: text/plain, Size: 755 bytes --]

On Sat, Jul 06, 2019 at 04:55:47PM +0200, Lars Ingebrigtsen wrote:
> (This reminds me -- Emacs should really have a parser that can parse
> all ISO8601 variants.  There's parse-iso8601-time-string, but it only
> handles the simplest of the formats...)

Perhaps that should be the first step, and then the committed fix to
this bug can just use that.

I've been using this patch since I submitted it and I've discovered a
slight bug in how date parsing works for bibtex files with this patch.
Please hold off on committing this patch until I've managed to narrow
down the bug and figure out where it is.

Thanks,
Ryan

-- 
|)|/  Ryan Kavanagh      | GPG: 4E46 9519 ED67 7734 268F
|\|\  https://rak.ac     |      BD95 8F7B F8FC 4A11 C97A

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 1873 bytes --]

^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#36252: 26.1; bibtex-generate-autokey does not use use date field
  2019-07-15  0:34   ` Ryan Kavanagh
@ 2019-07-15  7:24     ` Lars Ingebrigtsen
  2019-09-16 21:01       ` Lars Ingebrigtsen
  0 siblings, 1 reply; 15+ messages in thread
From: Lars Ingebrigtsen @ 2019-07-15  7:24 UTC (permalink / raw)
  To: Ryan Kavanagh; +Cc: 36252

Ryan Kavanagh <rak@debian.org> writes:

> On Sat, Jul 06, 2019 at 04:55:47PM +0200, Lars Ingebrigtsen wrote:
>> (This reminds me -- Emacs should really have a parser that can parse
>> all ISO8601 variants.  There's parse-iso8601-time-string, but it only
>> handles the simplest of the formats...)
>
> Perhaps that should be the first step, and then the committed fix to
> this bug can just use that.

I've implemented a proper iso8601 parser now, but hasn't merged with the
Emacs trunk yet because I haven't done the entire test suite yet.  It's
on the scratch/iso8601 branch if you want to check it out.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#36252: 26.1; bibtex-generate-autokey does not use use date field
  2019-07-15  7:24     ` Lars Ingebrigtsen
@ 2019-09-16 21:01       ` Lars Ingebrigtsen
  2020-08-10 11:01         ` Lars Ingebrigtsen
  0 siblings, 1 reply; 15+ messages in thread
From: Lars Ingebrigtsen @ 2019-09-16 21:01 UTC (permalink / raw)
  To: Ryan Kavanagh; +Cc: 36252

Lars Ingebrigtsen <larsi@gnus.org> writes:

> Ryan Kavanagh <rak@debian.org> writes:
>
>> On Sat, Jul 06, 2019 at 04:55:47PM +0200, Lars Ingebrigtsen wrote:
>>> (This reminds me -- Emacs should really have a parser that can parse
>>> all ISO8601 variants.  There's parse-iso8601-time-string, but it only
>>> handles the simplest of the formats...)
>>
>> Perhaps that should be the first step, and then the committed fix to
>> this bug can just use that.
>
> I've implemented a proper iso8601 parser now, but hasn't merged with the
> Emacs trunk yet because I haven't done the entire test suite yet.  It's
> on the scratch/iso8601 branch if you want to check it out.

The iso8601 parser is in the trunk now, so if you could rework your
patch based on that, that'd be nice.  The function to use is
`iso8601-parse'.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#36252: 26.1; bibtex-generate-autokey does not use use date field
  2019-09-16 21:01       ` Lars Ingebrigtsen
@ 2020-08-10 11:01         ` Lars Ingebrigtsen
  2020-09-14 15:02           ` Lars Ingebrigtsen
  0 siblings, 1 reply; 15+ messages in thread
From: Lars Ingebrigtsen @ 2020-08-10 11:01 UTC (permalink / raw)
  To: Ryan Kavanagh; +Cc: 36252

Lars Ingebrigtsen <larsi@gnus.org> writes:

> The iso8601 parser is in the trunk now, so if you could rework your
> patch based on that, that'd be nice.  The function to use is
> `iso8601-parse'.

Ryan, did you look into redoing this functionality with `iso8601-parse'?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#36252: 26.1; bibtex-generate-autokey does not use use date field
  2020-08-10 11:01         ` Lars Ingebrigtsen
@ 2020-09-14 15:02           ` Lars Ingebrigtsen
  2020-12-05  9:20             ` Patrick M. Niedzielski
  0 siblings, 1 reply; 15+ messages in thread
From: Lars Ingebrigtsen @ 2020-09-14 15:02 UTC (permalink / raw)
  To: Ryan Kavanagh; +Cc: 36252

Lars Ingebrigtsen <larsi@gnus.org> writes:

> Lars Ingebrigtsen <larsi@gnus.org> writes:
>
>> The iso8601 parser is in the trunk now, so if you could rework your
>> patch based on that, that'd be nice.  The function to use is
>> `iso8601-parse'.
>
> Ryan, did you look into redoing this functionality with `iso8601-parse'?

This was five weeks ago, and there was no response, so I'm closing this
bug report.  If progress can be made here, please respond to the debbugs
mail address, and we'll reopen the bug report.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#36252: 26.1; bibtex-generate-autokey does not use use date field
  2020-09-14 15:02           ` Lars Ingebrigtsen
@ 2020-12-05  9:20             ` Patrick M. Niedzielski
  2020-12-06  9:25               ` Colin Baxter
  2020-12-06 13:19               ` Lars Ingebrigtsen
  0 siblings, 2 replies; 15+ messages in thread
From: Patrick M. Niedzielski @ 2020-12-05  9:20 UTC (permalink / raw)
  To: Lars Ingebrigtsen, Ryan Kavanagh; +Cc: 36252

[-- Attachment #1: Type: text/plain, Size: 2247 bytes --]

Lars Ingebrigtsen <larsi@gnus.org> skribis:
> Lars Ingebrigtsen <larsi@gnus.org> writes: 
> 
> This was five weeks ago, and there was no response, so I'm 
> closing this bug report.  If progress can be made here, please 
> respond to the debbugs mail address, and we'll reopen the bug 
> report. 

I’d like to reopen this bug, and submit the attached patch which I 
believe fixes the issue. This patch teaches 
‘bibtex-generate-autokey’ to prefer an ISO8601-formatted ‘date’ 
field when present, and fall back to a ‘year’, and is implemented 
using Lars’ ISO8601 parsing functions.

Just some implementation notes: I don’t believe Ryan’s original 
patch works as documented when ‘bibtex-autokey-use-crossref’ is 
non-nil.  In this case, his patch would seem to prefer a 
crossref’d entry’s ‘year’ field to a local entry’s ‘date’ field. 
More concretely, with the following BibLaTeX,

  @misc{doe1995some,
    title = {Some work},
    author = {John Doe},
    year = {1995},
    date = {1995-01-01},
  } 

  @misc{,
    title = {Another work},
    author = {Anon Y. Mous},
    date = {1990-03-12},
    crossref = {entry1},
  }

When generating a key for entry2, the original patch would prefer 
using the year 1995 to the year 1990, which is unintuitive. The 
attached patch implements a different behavior instead, in which 
an entry’s own ‘year/date’ field are prefered to the crossref’d 
entry’s ‘year/date’ field. In the above case, 
‘bibtex-generate-autokey’ will generate a entry key with the year 
1990 rather than 1995.

Additionally, we prefer to use the ‘date’ field when present over 
the ‘year’ field. This behavior is probably more correct, since 
BibLaTeX deprecated the ‘year’ field in favor of its own ‘date’ 
field, which only should occur in BibLaTeX-flavor files. Note that 
this is a breaking change from the prior behavior, but only when 
an entry has incompatible ‘date’ and ‘year’ fields.  If a file is 
meant to support both BibTeX and BibLaTeX, the ‘date’ and ‘year’ 
fields should contain the same information.

The attached patch implements the above behavior.

Best,
Patrick


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Prefer-date-field-to-year-field-in-BibTex-entry.patch --]
[-- Type: text/x-diff, Size: 3221 bytes --]

From 26cb162d42e7fd234506a5f847fbfb73adb68105 Mon Sep 17 00:00:00 2001
From: "Patrick M. Niedzielski" <patrick@pniedzielski.net>
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


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* bug#36252: 26.1; bibtex-generate-autokey does not use use date field
  2020-12-05  9:20             ` Patrick M. Niedzielski
@ 2020-12-06  9:25               ` Colin Baxter
  2020-12-07  6:18                 ` Roland Winkler
  2020-12-06 13:19               ` Lars Ingebrigtsen
  1 sibling, 1 reply; 15+ messages in thread
From: Colin Baxter @ 2020-12-06  9:25 UTC (permalink / raw)
  To: 36252

Hello,
>>>>> Patrick M Niedzielski <patrick@pniedzielski.net> writes:

    > Lars Ingebrigtsen <larsi@gnus.org> skribis:
    >> Lars Ingebrigtsen <larsi@gnus.org> writes: This was five weeks
    >> ago, and there was no response, so I'm closing this bug report.
    >> If progress can be made here, please respond to the debbugs mail
    >> address, and we'll reopen the bug report.

    > I’d like to reopen this bug, and submit the attached patch which I
    > believe fixes the issue. This patch teaches
    > ‘bibtex-generate-autokey’ to prefer an ISO8601-formatted ‘date’
    > field when present, and fall back to a ‘year’, and is implemented
    > using Lars’ ISO8601 parsing functions.

    > Just some implementation notes: I don’t believe Ryan’s original
    > patch works as documented when ‘bibtex-autokey-use-crossref’ is
    > non-nil.  In this case, his patch would seem to prefer a
    > crossref’d entry’s ‘year’ field to a local entry’s ‘date’
    > field. More concretely, with the following BibLaTeX,

    >  @misc{doe1995some, title = {Some work}, author = {John Doe}, year
    > = {1995}, date = {1995-01-01}, } @misc{, title = {Another work},
    > author = {Anon Y. Mous}, date = {1990-03-12}, crossref = {entry1},
    > }

    > When generating a key for entry2, the original patch would prefer
    > using the year 1995 to the year 1990, which is unintuitive. The
    > attached patch implements a different behavior instead, in which
    > an entry’s own ‘year/date’ field are prefered to the crossref’d
    > entry’s ‘year/date’ field. In the above case,
    > ‘bibtex-generate-autokey’ will generate a entry key with the year
    > 1990 rather than 1995.

    > Additionally, we prefer to use the ‘date’ field when present over
    > the ‘year’ field. This behavior is probably more correct, since
    > BibLaTeX deprecated the ‘year’ field in favor of its own ‘date’
    > field, which only should occur in BibLaTeX-flavor files. Note that
    > this is a breaking change from the prior behavior, but only when
    > an entry has incompatible ‘date’ and ‘year’ fields.  If a file is
    > meant to support both BibTeX and BibLaTeX, the ‘date’ and ‘year’
    > fields should contain the same information.

I am a heavy user of bibtex, but I am puzzled over the 'date'
field. Publications have a 'year' ok, sometimes a 'month', but never
have I seen a 'day'. So how would a user enter (YYYY-MM-DD)? Is it
perhaps the date of entry of the record in to the file? Sorry to butt
in, but I am curious.

Best wishes,

Colin Baxter.






^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#36252: 26.1; bibtex-generate-autokey does not use use date field
  2020-12-05  9:20             ` Patrick M. Niedzielski
  2020-12-06  9:25               ` Colin Baxter
@ 2020-12-06 13:19               ` Lars Ingebrigtsen
  2020-12-07  6:20                 ` Roland Winkler
  1 sibling, 1 reply; 15+ messages in thread
From: Lars Ingebrigtsen @ 2020-12-06 13:19 UTC (permalink / raw)
  To: Patrick M. Niedzielski; +Cc: Ryan Kavanagh, 36252, Roland Winkler

Patrick M. Niedzielski <patrick@pniedzielski.net> writes:

> I’d like to reopen this bug, and submit the attached patch which I
> believe fixes the issue.

OK, reopened.

> This patch teaches ‘bibtex-generate-autokey’ to prefer an
> ISO8601-formatted ‘date’ field when present, and fall back to a
> ‘year’, and is implemented using Lars’ ISO8601 parsing functions.

Looks reasonable to me.  I've added Roland to the Cc's; perhaps he has
some comments.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#36252: 26.1; bibtex-generate-autokey does not use use date field
  2020-12-06  9:25               ` Colin Baxter
@ 2020-12-07  6:18                 ` Roland Winkler
  0 siblings, 0 replies; 15+ messages in thread
From: Roland Winkler @ 2020-12-07  6:18 UTC (permalink / raw)
  To: Colin Baxter; +Cc: 36252

On Sun Dec 6 2020 Colin Baxter wrote:
> I am a heavy user of bibtex, but I am puzzled over the 'date'
> field. Publications have a 'year' ok, sometimes a 'month', but never
> have I seen a 'day'. So how would a user enter (YYYY-MM-DD)? Is it
> perhaps the date of entry of the record in to the file? Sorry to butt
> in, but I am curious.

ISO8601 permits dates like YYYY, YYYY-MM, and YYYY-MM-DD.  I agree,
the last format is likely rare in the context of citations.  This
smells to me as if internally biblatex relies on a canned library
handling iso8601 formats.





^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#36252: 26.1; bibtex-generate-autokey does not use use date field
  2020-12-06 13:19               ` Lars Ingebrigtsen
@ 2020-12-07  6:20                 ` Roland Winkler
  2020-12-07 15:14                   ` Lars Ingebrigtsen
  2020-12-11 15:04                   ` Roland Winkler
  0 siblings, 2 replies; 15+ messages in thread
From: Roland Winkler @ 2020-12-07  6:20 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: Patrick M. Niedzielski, Ryan Kavanagh, 36252

[-- Attachment #1: message body text --]
[-- Type: text/plain, Size: 1390 bytes --]

On Sun Dec 6 2020 Lars Ingebrigtsen wrote:
> Looks reasonable to me.  I've added Roland to the Cc's; perhaps he
> has some comments.

[Thank you Lars, I haven't subscribed to the bug-gnu-emacs mailing
list.  Lately bug reports for bibtex.el seem to be popular.  Can you
please drop me a note if you see more bug reports for bibtex.el?
Thanks!]

A few days ago I installed in master a related patch that I had
lying around for some time.  I believe it addresses the question of
searching the date and year field in a cleaner way by passing a list
of field names to bibtex-text-in-field.  But I didn't know the new
iso8601 library.  So that's the main purpose of the new patch
attached below.  (This patch is against the current version of
bibtex.el in master.)

Out of curiosity, I also checked Oren Patashnik's old documentation
of the BibTeX year field.  It says that "standard styles can handle
any year whose last four nonpunctuation characters are numerals,
such as '(about 1984)'."  This must be very rare.  But now this
should be handled correctly, too.  (I only use old-fashioned
BibTeX.  But I believe biblatex promises backward compatibility for
the BibTeX year field.)

Regarding the docstring of bibtex-generate-autokey: I am not sure
this is the right place to elaborate on iso8601.  bibtex.el assumes
throughout that users are familiar with valid values for different
fields.


[-- Attachment #2: bibtex-2.patch --]
[-- Type: application/octet-stream, Size: 2345 bytes --]

diff -u bibtex.el~ bibtex.el
--- bibtex.el~	2020-12-04 13:58:30.422037809 -0600
+++ bibtex.el	2020-12-06 23:31:14.519240467 -0600
@@ -40,6 +40,8 @@
 
 ;;; Code:
 
+(require 'iso8601)
+
 \f
 ;; User Options:
 
@@ -2761,12 +2763,16 @@
 
 (defun bibtex-autokey-get-year ()
   "Return year field contents as a string obeying `bibtex-autokey-year-length'."
-  (let ((yearfield (bibtex-autokey-get-field '("year" "date"))))
-    ;; biblatex date field has format yyyy-mm-dd
-    (if (< 4 (length yearfield))
-        (setq yearfield (substring yearfield 0 4)))
-    (substring yearfield (max 0 (- (length yearfield)
-                                   bibtex-autokey-year-length)))))
+  (let* ((str (bibtex-autokey-get-field '("date" "year"))) ; possibly ""
+         (year (or (and (iso8601-valid-p str)
+                        (let ((year (decoded-time-year (iso8601-parse str))))
+                          (and year (number-to-string year))))
+                   ;; BibTeX permits a year field "(about 1984)", where only
+                   ;; the last four nonpunctuation characters must be numerals.
+                   (and (string-match "\\([0-9][0-9][0-9][0-9]\\)[^[:alnum:]]*\\'" str)
+                        (match-string 1 str))
+                   (user-error "Year or date field `%s' invalid" str))))
+    (substring year (max 0 (- (length year) bibtex-autokey-year-length)))))
 
 (defun bibtex-autokey-get-title ()
   "Get title field contents up to a terminator.
@@ -2849,12 +2855,12 @@
 
 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 date or year field to the rightmost
+    `bibtex-autokey-year-length' digits (useful values are 2 and 4).
+ 2. If both the year and date fields 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

^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#36252: 26.1; bibtex-generate-autokey does not use use date field
  2020-12-07  6:20                 ` Roland Winkler
@ 2020-12-07 15:14                   ` Lars Ingebrigtsen
  2020-12-11 15:04                   ` Roland Winkler
  1 sibling, 0 replies; 15+ messages in thread
From: Lars Ingebrigtsen @ 2020-12-07 15:14 UTC (permalink / raw)
  To: Roland Winkler; +Cc: Patrick M. Niedzielski, Ryan Kavanagh, 36252

"Roland Winkler" <winkler@gnu.org> writes:

> On Sun Dec 6 2020 Lars Ingebrigtsen wrote:
>> Looks reasonable to me.  I've added Roland to the Cc's; perhaps he
>> has some comments.
>
> [Thank you Lars, I haven't subscribed to the bug-gnu-emacs mailing
> list.  Lately bug reports for bibtex.el seem to be popular.  Can you
> please drop me a note if you see more bug reports for bibtex.el?
> Thanks!]

Sure; I'm just slowly working my way through old bug reports, which is
why you're seeing more of these now.  :-)  I'll keep Cc-ing you on the
bibtex stuff.

> A few days ago I installed in master a related patch that I had
> lying around for some time.  I believe it addresses the question of
> searching the date and year field in a cleaner way by passing a list
> of field names to bibtex-text-in-field.  But I didn't know the new
> iso8601 library.  So that's the main purpose of the new patch
> attached below.  (This patch is against the current version of
> bibtex.el in master.)

Looks good to me.

> Regarding the docstring of bibtex-generate-autokey: I am not sure
> this is the right place to elaborate on iso8601.  bibtex.el assumes
> throughout that users are familiar with valid values for different
> fields.

Yup.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#36252: 26.1; bibtex-generate-autokey does not use use date field
  2020-12-07  6:20                 ` Roland Winkler
  2020-12-07 15:14                   ` Lars Ingebrigtsen
@ 2020-12-11 15:04                   ` Roland Winkler
  1 sibling, 0 replies; 15+ messages in thread
From: Roland Winkler @ 2020-12-11 15:04 UTC (permalink / raw)
  To: Lars Ingebrigtsen, Patrick M. Niedzielski, Ryan Kavanagh,
	36252-done

On Mon Dec 7 2020 Roland Winkler wrote:
> A few days ago I installed in master a related patch that I had
> lying around for some time.  I believe it addresses the question
> of searching the date and year field in a cleaner way by passing a
> list of field names to bibtex-text-in-field.  But I didn't know
> the new iso8601 library.  So that's the main purpose of the new
> patch attached below.

Installed as commit 4a700a2f79d5cca64602b7cad30d6485cfe0e449.

Closing.





^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2020-12-11 15:04 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-06-16 20:23 bug#36252: 26.1; bibtex-generate-autokey does not use use date field Ryan Kavanagh
2019-07-06 14:52 ` Lars Ingebrigtsen
2019-07-06 14:55 ` Lars Ingebrigtsen
2019-07-15  0:34   ` Ryan Kavanagh
2019-07-15  7:24     ` Lars Ingebrigtsen
2019-09-16 21:01       ` Lars Ingebrigtsen
2020-08-10 11:01         ` Lars Ingebrigtsen
2020-09-14 15:02           ` Lars Ingebrigtsen
2020-12-05  9:20             ` Patrick M. Niedzielski
2020-12-06  9:25               ` Colin Baxter
2020-12-07  6:18                 ` Roland Winkler
2020-12-06 13:19               ` Lars Ingebrigtsen
2020-12-07  6:20                 ` Roland Winkler
2020-12-07 15:14                   ` Lars Ingebrigtsen
2020-12-11 15:04                   ` Roland Winkler

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).