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: Thu, 13 Jun 2013 22:53:53 +0200 Message-ID: <87txl1bula.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> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1371156847 4950 80.91.229.3 (13 Jun 2013 20:54:07 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 13 Jun 2013 20:54:07 +0000 (UTC) Cc: emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Jun 13 22:54:06 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 1UnEX0-00008q-IU for ged-emacs-devel@m.gmane.org; Thu, 13 Jun 2013 22:54:06 +0200 Original-Received: from localhost ([::1]:60044 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UnEX0-00067m-9N for ged-emacs-devel@m.gmane.org; Thu, 13 Jun 2013 16:54:06 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:45232) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UnEWu-00067Y-C5 for emacs-devel@gnu.org; Thu, 13 Jun 2013 16:54:03 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UnEWr-0004dw-HE for emacs-devel@gnu.org; Thu, 13 Jun 2013 16:54:00 -0400 Original-Received: from mout.gmx.net ([212.227.15.15]:63001) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UnEWr-0004dj-7d for emacs-devel@gnu.org; Thu, 13 Jun 2013 16:53:57 -0400 Original-Received: from mailout-de.gmx.net ([10.1.76.31]) by mrigmx.server.lan (mrigmx001) with ESMTP (Nemesis) id 0LbOHk-1U2bIk1FQg-00ktCO for ; Thu, 13 Jun 2013 22:53:56 +0200 Original-Received: (qmail invoked by alias); 13 Jun 2013 20:53:55 -0000 Original-Received: from i59F57A13.versanet.de (EHLO rosalinde.fritz.box) [89.245.122.19] by mail.gmx.net (mp031) with SMTP; 13 Jun 2013 22:53:55 +0200 X-Authenticated: #20778731 X-Provags-ID: V01U2FsdGVkX19EVVZO3sZEyQ366dj/YHZDepKfTpXp+Ow903JlQh R2gEtY3iSsRYP9 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.15.15 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:160419 Archived-At: On Wed, 12 Jun 2013 21:18:29 -0400 Stefan Monnier wrote: >> Thanks for the go-ahead. I do agree with you that a hook would be >> better and in fact gave it some thought, but couldn't see how to do it >> using an existing hook. I didn't consider adding a new hook, and I'm >> not sure I what that should be. The problem is, after the button is >> clicked in the Fancy Diary display, if the todo file is in a buffer, it >> will probably be narrowed, so it has to be widened before going to the >> position of the marker, and then it has to be narrowed again afterwards >> to get the proper display. So either there have to be two hooks >> sandwiching the goto-char for the marker, or the latter has to be passed >> to the hook function. Neither really seems much better than the ad hoc >> patch I posted, but it's not unlikely I'm overlooking a better >> alternative. If you have any ideas, I'm all ears. > > I think a way to do this is with a diary-goto-marker-function hook. > The default value could be `goto-char'. And your todo-mode can change > it via something like: > > (add-function :around diary-goto-marker-function > (lambda (orig-fun &rest args) > (when (derived-mode-p 'todo-mode) (widen)) > (apply orig-fun args) > (todos-diary-goto-entry))) Thank you for this excellent "advice" ;-). It works very nicely -- except for one wrinkle: after loading todos.el (which requires 'diary-lib) I have to eval diary-goto-entry (or load diary-lib) again in order for the advice to take effect. Without doing that it's as if the advice were not activated. But I see nothing about activating advice in nadvice.el. Here's what I added to diary-lib.el: (defvar diary-goto-location-function 'goto-char "Function called by `diary-goto-entry' to jump to a diary entry. Major modes that require special handling of the source file of the diary entry can assign a suitable function to this variable.") (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) ;; If marker pointing to diary location is valid, use that. (if (and marker (setq markbuf (marker-buffer marker))) (progn (pop-to-buffer markbuf) (funcall diary-goto-location-function (marker-position marker))) ;; 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)) (goto-char (point-min)) (if (re-search-forward (format "%s.*\\(%s\\)" (regexp-quote (nth 2 locator)) (regexp-quote (nth 3 locator))) nil t) (funcall diary-goto-location-function (match-beginning 1))))) (message "Unable to locate this diary entry"))))) and here's what I added to todos-mode: (define-derived-mode todos-mode special-mode "Todos" "Major mode for displaying, navigating and editing Todo lists. \\{todos-mode-map}" ;; other initializations ... (add-function :around diary-goto-location-function (lambda (orig-fun &rest args) (when (derived-mode-p 'todos-mode) (widen)) (apply orig-fun args) (todos-diary-goto-entry)))) What am I doing wrong? Steve Berman