From b11570c2f165a46de7d4723b9d3a9fe10caf7546 Mon Sep 17 00:00:00 2001 From: Bastien Guerry Date: Mon, 26 May 2014 17:42:58 +0200 Subject: [PATCH] Fix regression: allow to open a link in a comment or a property line * org.el (org-open-link-in-comment-or-property): New function. (org-open-at-point): Use it. See http://thread.gmane.org/gmane.emacs.orgmode/84300/focus=84300 for the follow-up of a discussion on whether links should be supported in comments and properties. --- lisp/org.el | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/lisp/org.el b/lisp/org.el index 0ca5cc5ed..430d4bda9 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -10547,6 +10547,28 @@ Functions in this hook must return t if they identify and follow a link at point. If they don't find anything interesting at point, they must return nil.") +(defun org-open-link-in-comment-or-property () + "Open the link at point in a comment or in a property." + (let* ((comment-or-prop "\\s-*# \\|[ \t]*:[^:]+:[ \t]*") + (string-rear + (replace-regexp-in-string + comment-or-prop "" + (buffer-substring (point) (line-beginning-position)))) + (string-front + (replace-regexp-in-string + comment-or-prop "" + (buffer-substring (point) (line-end-position)))) + (value (org-element-property :value (org-element-at-point)))) + (with-temp-buffer + (let ((org-inhibit-startup t)) (org-mode)) + (insert value) + (goto-char (point-min)) + (while (and (re-search-forward (regexp-quote string-rear) nil t) + (re-search-forward (regexp-quote string-front) nil t)) + (goto-char (match-beginning 0)) + (org-open-at-point) + (when (string= string-rear "") (forward-char)))))) + (defvar org-link-search-inhibit-query nil) ;; dynamically scoped (defvar clean-buffer-list-kill-buffer-names) ; Defined in midnight.el (defun org-open-at-point (&optional arg reference-buffer) @@ -10588,7 +10610,12 @@ is used internally by `org-open-link-from-string'." footnote-reference timestamp))) (setq context (org-element-property :parent context)))) (cond - ;; Unsupported context: return an error. + ;; WARNING: Before checking for syntactically correct + ;; contexts, we make two exceptions as we open links in + ;; comments and properties. + ((or (org-at-comment-p) (org-at-property-p)) + (org-open-link-in-comment-or-property)) + ;; Now check for context where link opening is not supported. ((not context) (user-error "No link found")) ;; On a headline or an inlinetask, but not on a timestamp, ;; a link, a footnote reference or on tags.