From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Lele Gaifax Newsgroups: gmane.emacs.devel Subject: Re: Strange problem with emacs-lisp/copyright.el Date: Tue, 31 Oct 2017 19:14:02 +0100 Organization: Nautilus Entertainments Message-ID: <87d153mbh1.fsf@metapensiero.it> References: <87o9w3ph9a.fsf@nautilus> <87mvbfvt63.fsf@metapensiero.it> <8760hxk5wc.fsf@metapensiero.it> <87fugz5bmo.fsf@gnu.org> <874lxezvnv.fsf@metapensiero.it> <8737cj63wt.fsf@metapensiero.it> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1509473679 18711 195.159.176.226 (31 Oct 2017 18:14:39 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 31 Oct 2017 18:14:39 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.90 (gnu/linux) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Oct 31 19:14:35 2017 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 1e9b3U-000400-M7 for ged-emacs-devel@m.gmane.org; Tue, 31 Oct 2017 19:14:28 +0100 Original-Received: from localhost ([::1]:46826 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e9b3b-00022r-VW for ged-emacs-devel@m.gmane.org; Tue, 31 Oct 2017 14:14:35 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:54580) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e9b3Q-00021D-VL for emacs-devel@gnu.org; Tue, 31 Oct 2017 14:14:26 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e9b3M-0001Mt-NC for emacs-devel@gnu.org; Tue, 31 Oct 2017 14:14:24 -0400 Original-Received: from [195.159.176.226] (port=53294 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e9b3M-0001Lm-B0 for emacs-devel@gnu.org; Tue, 31 Oct 2017 14:14:20 -0400 Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1e9b34-0001hG-Ms for emacs-devel@gnu.org; Tue, 31 Oct 2017 19:14:02 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 181 Original-X-Complaints-To: usenet@blaine.gmane.org Cancel-Lock: sha1:3HU1N7f5QYBJ+QNIAz2ZoLMV2bk= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 195.159.176.226 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:219834 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Hi all, this is just to properly end the thread [1], and ask whether I should open an issue, or add an annotation to the existing (but not exactly the same) issue #7179 [2], or what. Back in April I applied Johan Bockgård's suggestion and since then I haven't seen the reported problem again: >> Johan Bockgård writes: >> >>> >>> Does it work correctly if you change >>> >>> (switch-to-buffer (current-buffer)) >>> ;; Fixes some point-moving oddness (bug#2209). >>> (save-excursion >>> (y-or-n-p (if replace >>> >>> to >>> >>> (save-excursion >>> (switch-to-buffer (current-buffer)) >>> (y-or-n-p (if replace >>> >>> ? To summarize, I shuffled just a couple of lines: the attached `diff -u` does not make that clear, but hopefully the following `diff -u --ignore-space-change` gives a better idea since it ignores the indentation changes: --- copyright-orig.el 2017-10-31 18:54:20.957330092 +0100 +++ copyright.el 2017-10-31 18:55:11.624754452 +0100 @@ -181,19 +181,22 @@ ;; This uses the match-data from copyright-find-copyright/end. (goto-char (match-end 1)) (copyright-find-end) + (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 + (save-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? ")))))) + (progn + (goto-char copyright-end) (if replace (replace-match copyright-current-year t t nil 3) (let ((size (save-excursion (skip-chars-backward "0-9")))) @@ -218,7 +221,7 @@ (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) thanks&bye, lele. [1] http://lists.gnu.org/archive/html/emacs-devel/2017-04/msg00271.html [2] https://debbugs.gnu.org/cgi/bugreport.cgi?bug=7179 --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=copyright.el.patch --- copyright-orig.el 2017-10-31 18:54:20.957330092 +0100 +++ copyright.el 2017-10-31 18:55:11.624754452 +0100 @@ -181,44 +181,47 @@ ;; 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? ")))))) - (if replace - (replace-match copyright-current-year t t nil 3) - (let ((size (save-excursion (skip-chars-backward "0-9")))) - (if (and (eq (% (- (string-to-number copyright-current-year) - (string-to-number (buffer-substring - (+ (point) size) - (point)))) - 100) - 1) - (or (eq (char-after (+ (point) size -1)) ?-) - (eq (char-after (+ (point) size -2)) ?-))) - ;; This is a range so just replace the end part. - (delete-char size) - ;; Insert a comma with the preferred number of spaces. - (insert - (save-excursion - (if (re-search-backward "[0-9]\\( *, *\\)[0-9]" - (line-beginning-position) t) - (match-string 1) - ", "))) - ;; If people use the '91 '92 '93 scheme, do that as well. - (if (eq (char-after (+ (point) size -3)) ?') - (insert ?'))) - ;; Finally insert the new year. - (insert (substring copyright-current-year size))))))) + (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 + (save-excursion + (switch-to-buffer (current-buffer)) + ;; Fixes some point-moving oddness (bug#2209). + (y-or-n-p (if replace + (concat "Replace copyright year(s) by " + copyright-current-year "? ") + (concat "Add " copyright-current-year + " to copyright? ")))))) + (progn + (goto-char copyright-end) + (if replace + (replace-match copyright-current-year t t nil 3) + (let ((size (save-excursion (skip-chars-backward "0-9")))) + (if (and (eq (% (- (string-to-number copyright-current-year) + (string-to-number (buffer-substring + (+ (point) size) + (point)))) + 100) + 1) + (or (eq (char-after (+ (point) size -1)) ?-) + (eq (char-after (+ (point) size -2)) ?-))) + ;; This is a range so just replace the end part. + (delete-char size) + ;; Insert a comma with the preferred number of spaces. + (insert + (save-excursion + (if (re-search-backward "[0-9]\\( *, *\\)[0-9]" + (line-beginning-position) t) + (match-string 1) + ", "))) + ;; If people use the '91 '92 '93 scheme, do that as well. + (if (eq (char-after (+ (point) size -3)) ?') + (insert ?'))) + ;; Finally insert the new year. + (insert (substring copyright-current-year size))))))))) ;;;###autoload (defun copyright-update (&optional arg interactivep) --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit -- 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. --=-=-=--