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: Mon, 17 Apr 2017 19:29:56 +0200 Organization: Nautilus Entertainments Message-ID: <87mvbfvt63.fsf@metapensiero.it> References: <87o9w3ph9a.fsf@nautilus> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: blaine.gmane.org 1492450249 18964 195.159.176.226 (17 Apr 2017 17:30:49 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 17 Apr 2017 17:30:49 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Apr 17 19:30:43 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 1d0AU6-0004lL-BX for ged-emacs-devel@m.gmane.org; Mon, 17 Apr 2017 19:30:42 +0200 Original-Received: from localhost ([::1]:38021 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0AUC-0001dZ-30 for ged-emacs-devel@m.gmane.org; Mon, 17 Apr 2017 13:30:48 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:41775) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0ATZ-0001b9-Hk for emacs-devel@gnu.org; Mon, 17 Apr 2017 13:30:10 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d0ATW-0004vh-Af for emacs-devel@gnu.org; Mon, 17 Apr 2017 13:30:09 -0400 Original-Received: from [195.159.176.226] (port=55125 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d0ATW-0004v7-4b for emacs-devel@gnu.org; Mon, 17 Apr 2017 13:30:06 -0400 Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1d0ATN-0003tr-LW for emacs-devel@gnu.org; Mon, 17 Apr 2017 19:29:57 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 81 Original-X-Complaints-To: usenet@blaine.gmane.org Cancel-Lock: sha1:0OmhddRE+rAqv2Sku/vT1n17wPI= 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:214083 Archived-At: Some more details on the issue: I added two messages to the workhorse function, trying to spot where the "point" moves to the wrong location: (defun copyright-update-year (replace noquery) ;; This uses the match-data from copyright-find-copyright/end. (goto-char (match-end 1)) (copyright-find-end) ;; LELE (message "copyright-find-end says %d" (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 (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 ;; LELE (message "Updating copyright of %s at point %d" (buffer-file-name) (point)) (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)))))))) With this in place, I see the following messages when the error happens (I shortened the filenames for readability): Saving file /home/lele/[omissis]/grid/Custom.js... copyright-find-end says 277 Add 2017 to copyright? (y or n) y Updating copyright of /home/lele/[omissis]/grid/Custom.js at point 5912 Wrote ‘/home/lele/[omissis]/grid/Custom.js’ (11117 characters) Saving file /home/lele/[omissis]/data/MetaData.js... copyright-find-end says 288 Add 2017 to copyright? (y or n) y Updating copyright of /home/lele/[omissis]/data/MetaData.js at point 12155 Wrote ‘/home/lele/[omissis]/data/MetaData.js’ (27857 characters) As you can see, it seems that the (save-window-excursion ...) that asks confirmation restores the point where I left it before saving the buffer, not where (copyright-find-end) moved it. Does this bring any new information on the issue? I will try to store the point determined by copyright-find-end in a local variable and explicitly move there in the inner progn, but I'm obviously missing... the point :) Thank you, ciao, lele. -- 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.