emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

fix for bug#29935 copyright-update inserts year at random places


From: Stephen Leake
Subject: fix for bug#29935 copyright-update inserts year at random places
Date: Mon, 01 Jan 2018 17:29:27 -0600
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.90 (windows-nt)

I filed bug#29935 because copyright-update sometimes inserts the new
year at random places (happy new year! :).

This was discussed last April, but no bug report was filed, and both
master and emacs-26 still have the bug: see
https://lists.gnu.org/archive/html/emacs-devel/2017-10/msg00848.html

I improved the fix posted there; see below.

Ok to commit to emacs-26?

http://debbugs.gnu.org/cgi/bugreport.cgi?bug=29935
diff --git a/lisp/emacs-lisp/copyright.el b/lisp/emacs-lisp/copyright.el
index 69c5ebd45d..dcbee62af6 100644
--- a/lisp/emacs-lisp/copyright.el
+++ b/lisp/emacs-lisp/copyright.el
@@ -181,19 +181,22 @@ copyright-update-year
   ;; This uses the match-data from copyright-find-copyright/end.
   (goto-char (match-end 1))
   (copyright-find-end)
-  (setq copyright-current-year (format-time-string "%Y"))
-  (unless (string= (buffer-substring (- (match-end 3) 2) (match-end 3))
-                  (substring copyright-current-year -2))
-    (if (or noquery
-           (save-window-excursion
-             (switch-to-buffer (current-buffer))
-             ;; Fixes some point-moving oddness (bug#2209).
-             (save-excursion
-               (y-or-n-p (if replace
-                             (concat "Replace copyright year(s) by "
-                                     copyright-current-year "? ")
-                           (concat "Add " copyright-current-year
-                                   " to copyright? "))))))
+  (let ((copyright-end (point)))
+    (setq copyright-current-year (format-time-string "%Y"))
+    (unless (string= (buffer-substring (- (match-end 3) 2) (match-end 3))
+                    (substring copyright-current-year -2))
+      (if (or noquery
+             (save-window-excursion
+               ;; Fixes some point-moving oddness (bug#2209, bug#29935).
+               (save-excursion
+                 (switch-to-buffer (current-buffer))
+                  ;; Ensure the copyright line is displayed.
+                  (goto-char copyright-end)
+                 (y-or-n-p (if replace
+                               (concat "Replace copyright year(s) by "
+                                       copyright-current-year "? ")
+                             (concat "Add " copyright-current-year
+                                     " to copyright? "))))))
        (if replace
            (replace-match copyright-current-year t t nil 3)
          (let ((size (save-excursion (skip-chars-backward "0-9"))))
@@ -218,7 +221,8 @@ copyright-update-year
              (if (eq (char-after (+ (point) size -3)) ?')
                  (insert ?')))
            ;; Finally insert the new year.
-           (insert (substring copyright-current-year size)))))))
+           (insert (substring copyright-current-year size))))
+        ))))
 
 ;;;###autoload
 (defun copyright-update (&optional arg interactivep)

-- 
-- Stephe



reply via email to

[Prev in Thread] Current Thread [Next in Thread]