unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#53597: copyright-fix-years generates incorrect years ranges
@ 2022-01-28  8:18 Lele Gaifax
  2022-01-28 14:23 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 2+ messages in thread
From: Lele Gaifax @ 2022-01-28  8:18 UTC (permalink / raw)
  To: 53597

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

Hi,

I'm attaching a patch that describes and hopefully cures the problem I found
in copyright-fix-years.

All the best,
ciao, lele.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fix-copyright-fix-years-use-a-dash-to-separate-years.patch --]
[-- Type: text/x-diff, Size: 2838 bytes --]

From 6b924868878d17974f0d289c6f9b6318bfc455ec Mon Sep 17 00:00:00 2001
From: Lele Gaifax <lele@metapensiero.it>
Date: Fri, 28 Jan 2022 08:41:51 +0100
Subject: [PATCH] Fix copyright-fix-years, use a dash to separate years in a
 range

Commit 7a46fa9c751f7c3147cd9b27fe84c1ce25419d3b, allowing en-dash as
years separator, changed the way the years range is composed taking the
separator from the `sep' variable instead of always using an hardwired
hyphen. Since the code explicitly avoid to touch (that is, extend)
existing ranges, that `sep' variable is almost always a space, or
whatever character precedes the last parsed year, thus generating a
range like "2020 2022" instead of "2020-2022".

* lisp/emacs-lisp/copyright.el (copyright-fix-years): Always use an dash
to separate years in a range.

* test/lisp/emacs-lisp/copyright-tests.el (with-copyright-fix-years-test):
(copyright-fix-years-tests--data):
(text-copyright-fix-years): New test cases.
---
 lisp/emacs-lisp/copyright.el            |  2 +-
 test/lisp/emacs-lisp/copyright-tests.el | 20 ++++++++++++++++++++
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/lisp/emacs-lisp/copyright.el b/lisp/emacs-lisp/copyright.el
index 6b60097782..e5087672ae 100644
--- a/lisp/emacs-lisp/copyright.el
+++ b/lisp/emacs-lisp/copyright.el
@@ -313,7 +313,7 @@ copyright-fix-years
 			   (> prev-year first-year))
 		  (goto-char range-end)
 		  (delete-region range-start range-end)
-		  (insert (format "%c%d" sep prev-year))
+		  (insert (format "-%d" prev-year))
 		  (goto-char p))
 		(setq first-year year
 		      range-start (point)))))
diff --git a/test/lisp/emacs-lisp/copyright-tests.el b/test/lisp/emacs-lisp/copyright-tests.el
index abb0913a0d..b00d697aa6 100644
--- a/test/lisp/emacs-lisp/copyright-tests.el
+++ b/test/lisp/emacs-lisp/copyright-tests.el
@@ -72,5 +72,25 @@ copyright-tests--data
              (buffer-string))
            "Copyright 2021 FSF\nCopyright 2021, 2022 FSF\n")))
 
+(defmacro with-copyright-fix-years-test (orig result)
+  `(let ((copyright-year-ranges t))
+     (with-temp-buffer
+       (insert ,orig)
+       (copyright-fix-years)
+       (should (equal (buffer-string) ,result)))))
+
+(defvar copyright-fix-years-tests--data
+  '((";; Copyright (C) 2008, 2010, 2012"
+     . ";; Copyright (C) 2008, 2010, 2012")
+    (";; Copyright (C) 2008, 2009, 2010, 2013, 2014, 2015, 2016, 2018"
+     . ";; Copyright (C) 2008-2010, 2013-2016, 2018")
+    (";; Copyright (C) 2008-2010, 2011, 2015, 2016, 2017"
+     . ";; Copyright (C) 2008-2010, 2011, 2015-2017")))
+
+(ert-deftest text-copyright-fix-years ()
+  "Test basics of \\[copyright-fix-years]."
+  (dolist (test copyright-fix-years-tests--data)
+    (with-copyright-fix-years-test (car test) (cdr test))))
+
 (provide 'copyright-tests)
 ;;; copyright-tests.el ends here
-- 
2.34.1


[-- Attachment #3: Type: text/plain, Size: 211 bytes --]


-- 
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
lele@metapensiero.it  |                 -- Fortunato Depero, 1929.

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

* bug#53597: copyright-fix-years generates incorrect years ranges
  2022-01-28  8:18 bug#53597: copyright-fix-years generates incorrect years ranges Lele Gaifax
@ 2022-01-28 14:23 ` Lars Ingebrigtsen
  0 siblings, 0 replies; 2+ messages in thread
From: Lars Ingebrigtsen @ 2022-01-28 14:23 UTC (permalink / raw)
  To: Lele Gaifax; +Cc: 53597

Lele Gaifax <lele@metapensiero.it> writes:

> I'm attaching a patch that describes and hopefully cures the problem I found
> in copyright-fix-years.

Thanks; pushed to Emacs 29.

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





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

end of thread, other threads:[~2022-01-28 14:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-28  8:18 bug#53597: copyright-fix-years generates incorrect years ranges Lele Gaifax
2022-01-28 14:23 ` Lars Ingebrigtsen

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