From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: [PATCH] org-id-goto doesn't work if buffer is narrowed. Date: Sun, 25 Oct 2015 10:42:37 +0100 Message-ID: <877fmbb7xu.fsf@nicolasgoaziou.fr> References: <874mhh1u7s.fsf@gmx.us> <87oafpz65e.fsf@gmx.us> <87pp04zc1r.fsf@gmx.us> <87k2qbbaw3.fsf@nicolasgoaziou.fr> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:33295) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZqHnK-00062g-Jx for emacs-orgmode@gnu.org; Sun, 25 Oct 2015 05:40:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZqHnJ-0003ob-Iz for emacs-orgmode@gnu.org; Sun, 25 Oct 2015 05:40:54 -0400 Received: from relay3-d.mail.gandi.net ([2001:4b98:c:538::195]:45910) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZqHnJ-0003oX-Ck for emacs-orgmode@gnu.org; Sun, 25 Oct 2015 05:40:53 -0400 In-Reply-To: (Puneeth Chaganti's message of "Sun, 25 Oct 2015 14:40:23 +0530") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Puneeth Chaganti Cc: emacs-orgmode , Rasmus Puneeth Chaganti writes: > Thanks for your careful review and detailed comments. I've attached > an updated patch. Thank you. I have another suggestion about it. > +(defun org-id-show (id cmd) > + "Show an entry with id ID by buffer-switching using CMD. > +CMD is a function that takes a buffer or a string (buffer name) > +as an argument, which will be used to switch to the buffer > +containing the entry with id ID." > + (let ((m (org-id-find id 'marker))) > + (unless m > + (error "Cannot find entry with ID \"%s\"" id)) > + (unless (equal (current-buffer) (marker-buffer m)) > + (funcall cmd (marker-buffer m))) Nitpick: (eq (current-buffer) (marker-buffer m)) > + (when (let ((pos (marker-position m))) > + (or (< pos (point-min)) > + (> pos (point-max)))) > + (widen)) > + (goto-char m) > + (move-marker m nil) > + (org-show-context 'link-search))) If CMD raises an error, you have a dangling marker in the buffer, which is not a great idea. I suggest to wrap everything into a `unwind-protect' and add (set-marker m nil) as an unwindform, i.e., (let ((m (org-id-find id 'marker))) (unless m (error "Cannot find entry with ID \"%s\"" id)) (unwind-protect (progn (unless (eq (current-buffer) (marker-buffer m)) (funcall cmd (marker-buffer m))) (when (let ((pos (marker-position m))) (or (< pos (point-min)) (> pos (point-max)))) (widen)) (goto-char m) (org-show-context 'link-search)) (set-marker m nil))) Regards,