[Top][All Lists]

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

Re: Strange problem with emacs-lisp/copyright.el

From: Lele Gaifax
Subject: Re: Strange problem with emacs-lisp/copyright.el
Date: Fri, 21 Apr 2017 19:49:23 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux)

Lele Gaifax <address@hidden> 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

  (defun copyright-update-year (replace noquery)
    ;; This uses the match-data from copyright-find-copyright/end.
    (goto-char (match-end 1))
    (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
                  (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? "))))))
              (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)
                           (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.
                       (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.
address@hidden  |                 -- Fortunato Depero, 1929.

reply via email to

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