From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stephen Berman Newsgroups: gmane.emacs.devel Subject: Re: New version of todo-mode.el (announcement + user guide) Date: Mon, 17 Jun 2013 00:52:35 +0200 Message-ID: <87bo75brd8.fsf@rosalinde.fritz.box> References: <87k3m2275u.fsf@rosalinde.fritz.box> <8761xmxfnx.fsf@bzg.ath.cx> <87txl6ghjq.fsf@rosalinde.fritz.box> <87a9myggr7.fsf@wanadoo.es> <87sj0p8z99.fsf@rosalinde.fritz.box> <87mwqwpk98.fsf@rosalinde.fritz.box> <6emwqvxmpo.fsf@fencepost.gnu.org> <8761xjdn7t.fsf@rosalinde.fritz.box> <87txl1bula.fsf@rosalinde.fritz.box> <87obb874ru.fsf@rosalinde.fritz.box> <87y5abbkov.fsf@rosalinde.fritz.box> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1371423171 29010 80.91.229.3 (16 Jun 2013 22:52:51 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 16 Jun 2013 22:52:51 +0000 (UTC) Cc: emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Jun 17 00:52:50 2013 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UoLoW-0003VL-Nc for ged-emacs-devel@m.gmane.org; Mon, 17 Jun 2013 00:52:48 +0200 Original-Received: from localhost ([::1]:34823 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UoLoW-0001nw-Dz for ged-emacs-devel@m.gmane.org; Sun, 16 Jun 2013 18:52:48 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:39986) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UoLoQ-0001nn-JQ for emacs-devel@gnu.org; Sun, 16 Jun 2013 18:52:45 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UoLoN-0005qX-Rn for emacs-devel@gnu.org; Sun, 16 Jun 2013 18:52:42 -0400 Original-Received: from mout.gmx.net ([212.227.17.22]:58454) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UoLoN-0005pR-IA for emacs-devel@gnu.org; Sun, 16 Jun 2013 18:52:39 -0400 Original-Received: from mailout-de.gmx.net ([10.1.76.30]) by mrigmx.server.lan (mrigmx002) with ESMTP (Nemesis) id 0LxIeK-1UGvwV3il0-016zoC for ; Mon, 17 Jun 2013 00:52:37 +0200 Original-Received: (qmail invoked by alias); 16 Jun 2013 22:52:37 -0000 Original-Received: from i59F54CC2.versanet.de (EHLO rosalinde.fritz.box) [89.245.76.194] by mail.gmx.net (mp030) with SMTP; 17 Jun 2013 00:52:37 +0200 X-Authenticated: #20778731 X-Provags-ID: V01U2FsdGVkX18q1FNQ2IgqwCu2Rd041tQJX1uzhUzvKntNcnqvvx aiWOgVwd2NP59P In-Reply-To: (Stefan Monnier's message of "Sat, 15 Jun 2013 20:44:03 -0400") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) X-Y-GMX-Trusted: 0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 212.227.17.22 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 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-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:160475 Archived-At: On Sat, 15 Jun 2013 20:44:03 -0400 Stefan Monnier 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