emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Anders Waldenborg <anders@0x63.nu>
To: emacs-orgmode@gnu.org
Subject: PATCH Make org-open-at-point only ask once
Date: Sun, 28 Aug 2011 22:05:42 +0200	[thread overview]
Message-ID: <20110828200542.GS5700@0x63.nu> (raw)

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


If an org buffer is narrowed, and one tries to do org-open-at-point on
a link that points to outside of the restriction it asks: "No match -
create this as a new heading?". When answering no the buffer is
widened and the reseach is done, and if the link still can't be
resolved the question is asked again.

For nonexistant links this happens even if the buffer isn't narrowed -
one needs to answer "n" twice.

I also attached an alternate patch which (IMHO) simplifies the
implementation by hiding the hard work in a macro, and as a bonus it
only calls org-link-search once. But it is much more intrusive.


;; simple testcase to show the bug
  (insert "* A\n\n* B\n\n[[A]]")

[-- Attachment #2: org-open-at-point.patch --]
[-- Type: text/x-diff, Size: 1163 bytes --]

commit 54702f063ae2df48dec7f9feb80859a6b64002a4
Author: Anders Waldenborg <anders@0x63.nu>
Date:   Sat Aug 27 21:18:46 2011 +0200

    Make org-open-at-point only ask once whether new header should be created.
    When following "thisfile" links org-open-at-point is kind enough to
    retry org-link-search again after widening the buffer it can't be
    found. However org-link-search also asks the question "No match -
    create this as a new heading? (y or n)" when target can't be
    found. This means that the question is asked twice when following a
    nonexistent link and answering no.
    This is fixed by setting org-link-search-inhibit-query in first try,
    so only second invocation asks the question.

diff --git a/lisp/org.el b/lisp/org.el
index d63b854..781de88 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -9537,7 +9537,8 @@ application the system uses for this file type."
 			      ((equal arg '(16)) ''org-occur)
 			      (t nil))
-	    (condition-case nil (eval cmd)
+	    (condition-case nil (let ((org-link-search-inhibit-query t))
+				  (eval cmd))
 	      (error (progn (widen) (eval cmd))))))

[-- Attachment #3: org-open-at-point-alternate.patch --]
[-- Type: text/x-diff, Size: 1618 bytes --]

diff --git a/lisp/org-macs.el b/lisp/org-macs.el
index 13aff02..153a041 100644
--- a/lisp/org-macs.el
+++ b/lisp/org-macs.el
@@ -414,6 +414,24 @@ the value in cdr."
     (cons (list (car flat) (cadr flat))
          (org-make-parameter-alist (cddr flat)))))
+(defmacro org-widen-and-maybe-renarrow (&rest BODY)
+  "Widen buffer and evaluate body, and if point is outside
+the previously narrowed-to region after evaluation permanetly
+lift the restriction."
+  (declare (indent defun))
+  (org-with-gensyms (res pnt)
+    `(let ((,res)
+	   (,pnt))
+       (save-restriction
+	 (widen)
+	 (setq ,res ,@BODY)
+	 (setq ,pnt (point)))
+       (when (or (< ,pnt (point-min))
+		 (> ,pnt (point-max)))
+	 (widen)
+	 (goto-char ,pnt))
+       ,res)))
 (provide 'org-macs)
 ;;; org-macs.el ends here
diff --git a/lisp/org.el b/lisp/org.el
index d63b854..efe936e 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -9531,15 +9531,12 @@ application the system uses for this file type."
 	       (org-get-buffer-for-internal-link (current-buffer)))
-	  (let ((cmd `(org-link-search
-		       ,path
-		       ,(cond ((equal arg '(4)) ''occur)
-			      ((equal arg '(16)) ''org-occur)
-			      (t nil))
-		       ,pos)))
-	    (condition-case nil (eval cmd)
-	      (error (progn (widen) (eval cmd))))))
+	  (org-widen-and-maybe-renarrow
+	    (org-link-search path
+			     (cond ((equal arg '(4)) 'occur)
+				   ((equal arg '(16)) 'org-occur)
+				   (t nil))
+			     pos)))
   (move-marker org-open-link-marker nil)

             reply	other threads:[~2011-08-28 20:05 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-28 20:05 Anders Waldenborg [this message]
2011-08-29  7:14 ` PATCH Make org-open-at-point only ask once Nicolas Goaziou
2011-08-29  9:21   ` Anders Waldenborg
2011-08-29  9:36     ` Nicolas Goaziou
2011-08-29 10:53       ` Anders Waldenborg
2011-08-29 11:25         ` Nicolas Goaziou
2011-10-06  8:00 ` Carsten Dominik
2011-10-06  8:43   ` Anders Waldenborg
2011-10-06  8:54     ` Carsten Dominik
2011-10-06  9:51       ` Anders Waldenborg
2011-10-06  9:57         ` Carsten Dominik

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:

  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=20110828200542.GS5700@0x63.nu \
    --to=anders@0x63.nu \
    --cc=emacs-orgmode@gnu.org \


* 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


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).