emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Puneeth Chaganti <punchagan@gmail.com>
To: Rasmus <rasmus@gmx.us>
Cc: emacs-orgmode <emacs-orgmode@gnu.org>
Subject: Re: [PATCH] org-id-goto doesn't work if buffer is narrowed.
Date: Sun, 25 Oct 2015 08:42:33 +0530	[thread overview]
Message-ID: <CALnw1fRd-NMBW7VTVFTzP6io4qApU3Am1g=LdReJf_zxi1UaDg@mail.gmail.com> (raw)
In-Reply-To: <CALnw1fQc63_3yxiwwCywP4tSfHBdPBh9i9b2-u5g6ca=0E+U1w@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 684 bytes --]

Hi Rasmus,

On Sun, Oct 25, 2015 at 7:54 AM, Puneeth Chaganti <punchagan@gmail.com> wrote:
>
>> However, your patch doesn’t work for me in the following example, starting
>> from emacs -q, adding /tmp/test.org (with the below content) to my agenda
>> list and requiring org-id, org-narrow-to-subtree on foo, and then
>> org-open-at-point on the link
>
> I had patched `org-id-goto' and looks like clicking on links uses
> `org-id-open'.  I will resend a patch.  I wonder if these two
> functions can reuse common code.

Here is a patch that works for the case you describe.

The widening happens even if the target location is in a different
buffer, in this patch.

[-- Attachment #2: 0001-Widen-if-target-id-location-is-not-in-the-narrow.patch --]
[-- Type: text/x-patch, Size: 2997 bytes --]

From ba62042ff37c200d814567a79bcb999aef67581c Mon Sep 17 00:00:00 2001
From: Puneeth Chaganti <punchagan@muse-amuse.in>
Date: Sun, 25 Oct 2015 08:24:09 +0530
Subject: [PATCH] Widen if target id location is not in the narrow.

---
 lisp/org-id.el | 52 ++++++++++++++++++++++++++--------------------------
 1 file changed, 26 insertions(+), 26 deletions(-)

diff --git a/lisp/org-id.el b/lisp/org-id.el
index f86ef22..57d2414 100644
--- a/lisp/org-id.el
+++ b/lisp/org-id.el
@@ -292,13 +292,7 @@ It returns the ID of the entry.  If necessary, the ID is created."
   "Switch to the buffer containing the entry with id ID.
 Move the cursor to that entry in that buffer."
   (interactive "sID: ")
-  (let ((m (org-id-find id 'marker)))
-    (unless m
-      (error "Cannot find entry with ID \"%s\"" id))
-    (org-pop-to-buffer-same-window (marker-buffer m))
-    (goto-char m)
-    (move-marker m nil)
-    (org-show-context)))
+  (org-id-show id 'org-pop-to-buffer-same-window))
 
 ;;;###autoload
 (defun org-id-find (id &optional markerp)
@@ -634,6 +628,22 @@ optional argument MARKERP, return the position as a new marker."
 		(move-marker (make-marker) pos buf)
 	      (cons file pos))))))))
 
+(defun org-id-show (id cmd)
+  "Show an entry with id ID by buffer-switching using CMD."
+  (let ((m (org-id-find id 'marker)))
+    (unless m
+      (error "Cannot find entry with ID \"%s\"" id))
+    (if (not (equal (current-buffer) (marker-buffer m)))
+	(funcall cmd (marker-buffer m)))
+    (when (and (org-buffer-narrowed-p)
+	       (let ((pos (marker-position m)))
+		 (or (< pos (point-min))
+		     (> pos (point-max)))))
+      (widen))
+    (goto-char m)
+    (move-marker m nil)
+    (org-show-context)))
+
 ;; id link type
 
 ;; Calling the following function is hard-coded into `org-store-link',
@@ -659,25 +669,15 @@ optional argument MARKERP, return the position as a new marker."
 (defun org-id-open (id)
   "Go to the entry with id ID."
   (org-mark-ring-push)
-  (let ((m (org-id-find id 'marker))
-	cmd)
-    (unless m
-      (error "Cannot find entry with ID \"%s\"" id))
-    ;; Use a buffer-switching command in analogy to finding files
-    (setq cmd
-	  (or
-	   (cdr
-	    (assq
-	     (cdr (assq 'file org-link-frame-setup))
-	     '((find-file . switch-to-buffer)
-	       (find-file-other-window . switch-to-buffer-other-window)
-	       (find-file-other-frame . switch-to-buffer-other-frame))))
-	   'switch-to-buffer-other-window))
-    (if (not (equal (current-buffer) (marker-buffer m)))
-	(funcall cmd (marker-buffer m)))
-    (goto-char m)
-    (move-marker m nil)
-    (org-show-context)))
+  (let ((cmd (or
+	      (cdr
+	       (assq
+		(cdr (assq 'file org-link-frame-setup))
+		'((find-file . switch-to-buffer)
+		  (find-file-other-window . switch-to-buffer-other-window)
+		  (find-file-other-frame . switch-to-buffer-other-frame))))
+	      'switch-to-buffer-other-window)))
+    (org-id-show id cmd)))
 
 (org-add-link-type "id" 'org-id-open)
 
-- 
2.5.0


  reply	other threads:[~2015-10-25  3:12 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-23 15:11 [PATCH] org-id-goto doesn't work if buffer is narrowed Puneeth Chaganti
2015-10-23 15:27 ` Rasmus
2015-10-23 18:05   ` Puneeth Chaganti
2015-10-23 18:48     ` John Kitchin
2015-10-23 20:22     ` Rasmus
2015-10-24  5:29       ` Puneeth Chaganti
2015-10-24 11:33         ` John Kitchin
2015-10-24 11:49           ` Puneeth Chaganti
2015-10-24 11:57           ` Nicolas Goaziou
2015-10-24 12:47           ` Rasmus
2015-10-24 17:48             ` John Kitchin
2015-10-24 18:03               ` Rasmus
2015-10-25 11:11                 ` John Kitchin
2015-10-24 12:27         ` Rasmus
2015-10-25  2:24           ` Puneeth Chaganti
2015-10-25  3:12             ` Puneeth Chaganti [this message]
2015-10-25  8:38               ` Nicolas Goaziou
2015-10-25  9:10                 ` Puneeth Chaganti
2015-10-25  9:42                   ` Nicolas Goaziou
2015-10-25  9:57                     ` Puneeth Chaganti
2015-10-25 11:19             ` Rasmus
2015-10-26 14:14               ` Puneeth Chaganti
2015-10-23 19:59   ` Matt Lundin
2015-10-23 20:18     ` Rasmus

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.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CALnw1fRd-NMBW7VTVFTzP6io4qApU3Am1g=LdReJf_zxi1UaDg@mail.gmail.com' \
    --to=punchagan@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=rasmus@gmx.us \
    /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/org-mode.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).