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: Fri, 21 Apr 2017 19:49:23 +0200 Organization: Nautilus Entertainments Message-ID: <8760hxk5wc.fsf@metapensiero.it> References: <87o9w3ph9a.fsf@nautilus> <87mvbfvt63.fsf@metapensiero.it> 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 1492796986 12656 195.159.176.226 (21 Apr 2017 17:49:46 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 21 Apr 2017 17:49:46 +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 Fri Apr 21 19:49:42 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 1d1cgg-0003Dn-2T for ged-emacs-devel@m.gmane.org; Fri, 21 Apr 2017 19:49:42 +0200 Original-Received: from localhost ([::1]:60832 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d1cgl-0004HU-Vn for ged-emacs-devel@m.gmane.org; Fri, 21 Apr 2017 13:49:48 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:56473) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d1cgg-0004HD-7m for emacs-devel@gnu.org; Fri, 21 Apr 2017 13:49:43 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d1cgb-0001cL-Bz for emacs-devel@gnu.org; Fri, 21 Apr 2017 13:49:42 -0400 Original-Received: from [195.159.176.226] (port=40928 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d1cgb-0001bV-5L for emacs-devel@gnu.org; Fri, 21 Apr 2017 13:49:37 -0400 Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1d1cgS-0002x9-EJ for emacs-devel@gnu.org; Fri, 21 Apr 2017 19:49:28 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 64 Original-X-Complaints-To: usenet@blaine.gmane.org Cancel-Lock: sha1:TbZ7N+BlTtD2T90Ga7bj68andeE= 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:214195 Archived-At: Lele Gaifax writes: > 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 :) FYI, since a couple of days I'm using this override, that apparently fixes my issue: (defun copyright-update-year (replace noquery) ;; 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 (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")))) (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))))))))) It just saves and restore the point position found by `copyright-find-end': I tried to understand why the `save-excursion' isn't enough, but failed. All the best, 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.