emacs-devel
[Top][All Lists]
Advanced

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

Re: New version of todo-mode.el (announcement + user guide)


From: Stephen Berman
Subject: Re: New version of todo-mode.el (announcement + user guide)
Date: Sat, 15 Jun 2013 14:52:16 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

On Fri, 14 Jun 2013 21:49:35 -0400 Stefan Monnier <address@hidden> wrote:

>> But it works when it's added at top-level.  Moreover, it turns out that
>> using :around isn't right, at least not without making it much more
>> complicated AFAICT.  It's much more straightforward to use :override.
>
> I don't see why, but it doesn't matter.

I'll try explaining anyway, since if you see a way to do it that I'm
overlooking, I'd like to know.  There are two situations that
diary-goto-entry handles (which entails two calls of the modified
function): where a valid marker points to the diary entry location, and
where there is no such marker.  When the entry comes from a todo file in
a live buffer, narrowing is in effect, so before finding the location,
the buffer has to be widened, and then afterwards narrowed again, to
restore the proper display.  But what happens between widening and
re-narrowing is different in the two situations (indicated below by the
arrows pointing to the code executed by the :around advice) and I see no
straightforward way to cover them both with a single :around advice.
(Note that widening just before the third goto-char, which would allow
the simple :around advice you suggested, is too late.)

(defun diary-goto-entry (button)
  "Jump to the diary entry for the BUTTON at point."
  (let* ((locator (button-get button 'locator))
         (marker (car locator))
         markbuf file opoint)
    ;; If marker pointing to diary location is valid, use that.
    (if (and marker (setq markbuf (marker-buffer marker)))
        (progn
          (pop-to-buffer markbuf)
1a=>      (when (eq major-mode 'todos-mode) (widen))
          (goto-char (marker-position marker))
1b=>      (todos-diary-goto-entry))
      ;; Marker is invalid (eg buffer has been killed).
      (or (and (setq file (cadr locator))
               (file-exists-p file)
               (find-file-other-window file)
               (progn
                 (when (eq major-mode (default-value 'major-mode)) (diary-mode))
2a=>             (when (eq major-mode 'todos-mode) (widen))
                 (goto-char (point-min))
                 (when (re-search-forward (format "%s.*\\(%s\\)"
                                                  (regexp-quote (nth 2 locator))
                                                  (regexp-quote (nth 3 
locator)))
                                          nil t)
                   (goto-char (match-beginning 1))
2b=>               (todos-diary-goto-entry))))
          (message "Unable to locate this diary entry")))))

Actually, I don't see why the first situation, using a valid marker, is
needed.  I suppose executing that code is quicker than doing a regexp
search, but I doubt it's noticeable, perhaps unless the file is really
huge.  If diary-goto-entry were changed to always search for the entry,
then the simple :around advice would be fine.  If it isn't changed, I
think using :override advice is the simplest alternative.

Steve Berman



reply via email to

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