From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Stephen Leake Newsgroups: gmane.emacs.devel Subject: fix for bug#29935 copyright-update inserts year at random places Date: Mon, 01 Jan 2018 17:29:27 -0600 Message-ID: <868tdh5fag.fsf@stephe-leake.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1514849296 2586 195.159.176.226 (1 Jan 2018 23:28:16 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 1 Jan 2018 23:28:16 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.90 (windows-nt) To: emacs-devel Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Jan 02 00:28:12 2018 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eW9V3-0008Tg-CF for ged-emacs-devel@m.gmane.org; Tue, 02 Jan 2018 00:28:09 +0100 Original-Received: from localhost ([::1]:47876 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eW9X0-0003hF-Pf for ged-emacs-devel@m.gmane.org; Mon, 01 Jan 2018 18:30:10 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:43226) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eW9WR-0003gu-JC for emacs-devel@gnu.org; Mon, 01 Jan 2018 18:29:36 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eW9WO-0007sH-Bc for emacs-devel@gnu.org; Mon, 01 Jan 2018 18:29:35 -0500 Original-Received: from smtp81.ord1d.emailsrvr.com ([184.106.54.81]:34290) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eW9WO-0007rT-78 for emacs-devel@gnu.org; Mon, 01 Jan 2018 18:29:32 -0500 Original-Received: from smtp3.relay.ord1d.emailsrvr.com (localhost [127.0.0.1]) by smtp3.relay.ord1d.emailsrvr.com (SMTP Server) with ESMTP id 89EE76005F for ; Mon, 1 Jan 2018 18:29:30 -0500 (EST) X-Auth-ID: board-president@tomahawk-creek-hoa.com Original-Received: by smtp3.relay.ord1d.emailsrvr.com (Authenticated sender: board-president-AT-tomahawk-creek-hoa.com) with ESMTPSA id 4BAF160056 for ; Mon, 1 Jan 2018 18:29:30 -0500 (EST) X-Sender-Id: board-president@tomahawk-creek-hoa.com Original-Received: from Takver4 (76-218-37-33.lightspeed.kscymo.sbcglobal.net [76.218.37.33]) (using TLSv1.2 with cipher AES256-GCM-SHA384) by 0.0.0.0:25 (trex/5.7.12); Mon, 01 Jan 2018 18:29:30 -0500 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 184.106.54.81 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:221521 Archived-At: 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