diff options
author | Bastien Guerry <bzg@altern.org> | 2014-05-26 17:42:58 +0200 |
---|---|---|
committer | Bastien Guerry <bzg@altern.org> | 2014-05-26 17:42:58 +0200 |
commit | b11570c2f165a46de7d4723b9d3a9fe10caf7546 (patch) | |
tree | 9affeb059f7b42190ea332f703d88bc53be0414b | |
parent | f768629404fbb9260a611823b1cc266d1407abc2 (diff) | |
download | org-mode-b11570c2f165a46de7d4723b9d3a9fe10caf7546.tar.gz |
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.
-rw-r--r-- | lisp/org.el | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/lisp/org.el b/lisp/org.el index 0ca5cc5..430d4bd 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. |