From: Stephen Berman <stephen.berman@gmx.net>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: emacs-devel@gnu.org
Subject: Re: New version of todo-mode.el (announcement + user guide)
Date: Mon, 17 Jun 2013 00:52:35 +0200 [thread overview]
Message-ID: <87bo75brd8.fsf@rosalinde.fritz.box> (raw)
In-Reply-To: <jwv61xeew2f.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Sat, 15 Jun 2013 20:44:03 -0400")
On Sat, 15 Jun 2013 20:44:03 -0400 Stefan Monnier <monnier@iro.umontreal.ca> wrote:
>> restore the proper display. But what happens between widening and
>> re-narrowing is different in the two situations (indicated below by the
>
> You could unify the two with something like
>
> (defvar diary-goto-entry-function
> (lambda (pos)
> (if (number-or-marker-p pos) (goto-char pos))
> (goto-char (point-min))
> (when (re-search-forward (format "%s.*\\(%s\\)"
> (regexp-quote (car locator))
> (regexp-quote (nth 1 locator)))
> nil t)
> (goto-char (match-beginning 1))))
> "Function called to jump to a diary entry.
> Called with one argument which can be either a simple buffer position,
> or a description of the form (FOO BAR) where FOO is some leading text
> and BAR is the actual text of the entry.")
>
> (defun diary-goto-entry (button)
> "Jump to the diary entry for the BUTTON at point."
> (let* ((locator (button-get button 'locator))
> (marker (car locator))
> (file (nth 1 locator))
> (place (cond
> ;; If marker pointing to diary location is valid, use that.
> ((and marker (marker-buffer marker))
> (cons (marker-buffer marker) marker))
> ;; Marker is invalid (eg buffer has been killed).
> ((and file (file-exists-p file))
> (cons (find-file-noselect file) (cddr locator)))
> (t (message "Unable to locate this diary entry") nil))))
> (when place
> (pop-to-buffer (car place))
> (funcall diary-goto-entry-function (cdr place)))))
>
Ok, thanks. So, you can use :around advice if you build the two types
of entry locating operations into the auxiliary function -- but not
without reimplementing diary-goto-entry accordingly. Note, however,
that FOO can't just be "some leading text" but really has to be the
entry's date string, i.e. (nth 2 locator) [(car locator) is a typo, as
is (nth 1 locator), that should be 3 instead of 1; also I think it's
cleaner to use (nth 2 pos) and (nth 3 pos) and in diary-goto-entry cons
file to locator instead of (cddr locator)], otherwise either the wrong
or no entry will be found. In other words, diary-goto-entry-function
can really only have that exact function as its value, so might be
better defined as a defconst.
>> Actually, I don't see why the first situation, using a valid marker, is
>> needed.
>
> I don't have any opinion on that part because I don't use this part of
> the diary.
So I think we now have three alternatives to choose from:
1. Keep diary-goto-entry as it is and add the variable
diary-goto-entry-function with default value 'diary-goto-entry, which
other packages can override (though the overriding function will
still have to contain the same entry locating operations).
2. Change diary-goto-entry as above and add the variable (or defconst)
diary-goto-entry-function, which other packages can modify with
:around advice.
3. If using a marker to locate the entry is not necessary, then we could
use the following somewhat simpler definitions (here, too, maybe the
defvar should be a defconst):
(defvar diary-goto-entry-function
(lambda (pos)
(let ((specifier (regexp-quote (nth 2 pos)))
(literal (regexp-quote (nth 3 pos))))
(goto-char (point-min))
(if (re-search-forward (format "%s.*\\(%s\\)" specifier literal) nil t)
(goto-char (match-beginning 1))))))
(defun diary-goto-entry (button)
"Jump to the diary entry for the BUTTON at point."
(let* ((locator (button-get button 'locator))
(file (cadr locator)))
(if (not (and (file-exists-p file) (find-file-other-window file)))
(message "Unable to locate this diary entry")
(when (eq major-mode (default-value 'major-mode)) (diary-mode))
(funcall diary-goto-entry-function locator))))
This works with :around advice according to my tests. Glenn, is there
some situation where it's necessary or highly advantageous to use a
marker to locate the diary entry?
If all three alternatives are equally viable, is there any reason to
prefer one over the others?
Steve Berman
next prev parent reply other threads:[~2013-06-16 22:52 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-09 23:31 New version of todo-mode.el (announcement + user guide) Stephen Berman
2013-06-10 13:24 ` Bastien
2013-06-10 14:35 ` Stephen Berman
2013-06-10 14:49 ` Bastien
2013-06-10 20:51 ` New version of todo-mode.el (code) Stephen Berman
2013-08-30 18:31 ` Jambunathan K
2013-09-08 21:09 ` Stephen Berman
2013-06-10 14:52 ` New version of todo-mode.el (announcement + user guide) Óscar Fuentes
2013-06-10 20:52 ` Stephen Berman
2013-06-11 0:20 ` Stefan Monnier
2013-06-11 18:36 ` Stephen Berman
2013-06-11 21:48 ` Stefan Monnier
2013-06-12 21:37 ` Stephen Berman
2013-06-13 1:06 ` Stefan Monnier
2013-06-13 20:53 ` Stephen Berman
2013-06-12 17:28 ` Glenn Morris
2013-06-12 21:26 ` Stefan Monnier
2013-06-12 21:37 ` Stephen Berman
2013-06-13 1:18 ` Stefan Monnier
2013-06-13 20:53 ` Stephen Berman
2013-06-14 0:21 ` Stefan Monnier
2013-06-14 21:37 ` Stephen Berman
2013-06-15 0:40 ` Glenn Morris
2013-06-15 1:49 ` Stefan Monnier
2013-06-15 12:52 ` Stephen Berman
2013-06-16 0:44 ` Stefan Monnier
2013-06-16 22:52 ` Stephen Berman [this message]
2013-06-17 0:37 ` Stefan Monnier
2013-06-17 19:50 ` Glenn Morris
2013-06-17 22:33 ` Stephen Berman
2013-06-12 18:30 ` Wolfgang Jenkner
2013-06-12 21:38 ` Stephen Berman
2013-06-13 1:24 ` Wolfgang Jenkner
2013-06-13 20:54 ` Stephen Berman
2013-06-13 10:59 ` Vitalie Spinu
2013-06-13 20:54 ` Stephen Berman
2013-08-31 3:55 ` Jambunathan K
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87bo75brd8.fsf@rosalinde.fritz.box \
--to=stephen.berman@gmx.net \
--cc=emacs-devel@gnu.org \
--cc=monnier@iro.umontreal.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).