unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: "Roland Winkler" <winkler@gnu.org>
To: Lars Ingebrigtsen <larsi@gnus.org>
Cc: "Patrick M. Niedzielski" <patrick@pniedzielski.net>,
	Ryan Kavanagh <rak@debian.org>,
	36252@debbugs.gnu.org
Subject: bug#36252: 26.1; bibtex-generate-autokey does not use use date field
Date: Mon, 7 Dec 2020 00:20:54 -0600	[thread overview]
Message-ID: <51654.98578.572978.24525@gargle.gargle.HOWL> (raw)
In-Reply-To: <87360jdqck.fsf@gnus.org>

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

  reply	other threads:[~2020-12-07  6:20 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2020-12-07 15:14                   ` Lars Ingebrigtsen
2020-12-11 15:04                   ` Roland Winkler

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=51654.98578.572978.24525@gargle.gargle.HOWL \
    --to=winkler@gnu.org \
    --cc=36252@debbugs.gnu.org \
    --cc=larsi@gnus.org \
    --cc=patrick@pniedzielski.net \
    --cc=rak@debian.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 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).