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." (switch-to-buffer-other-window (org-get-buffer-for-internal-link (current-buffer))) (org-mark-ring-push)) - (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))) (t (browse-url-at-point))))))) (move-marker org-open-link-marker nil)