summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Guerry <bzg@altern.org>2014-05-28 10:21:11 +0200
committerBastien Guerry <bzg@altern.org>2014-05-28 10:21:11 +0200
commit500252abf34d003c020b73348d6ca13da5ce46c5 (patch)
treec5eabaf80d1ae3297a83b45a67975bd4df02f2fc
parent5fbdbb2bd51df774a0e254c17540d2f083d4e1ae (diff)
downloadorg-mode-500252abf34d003c020b73348d6ca13da5ce46c5.tar.gz
org.el (org-open-link-in-comment-or-property): Refactor into `org-open-at-point'
* org.el (org-open-link-in-comment-or-property): Delete. (org-open-at-point): Handle links in comments and property drawers. Update docstring.
-rw-r--r--lisp/org.el56
1 files changed, 27 insertions, 29 deletions
diff --git a/lisp/org.el b/lisp/org.el
index e62d043..64bbae4 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -10547,28 +10547,6 @@ 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)
@@ -10593,7 +10571,11 @@ is on a tag, call `org-tags-view' instead.
When optional argument REFERENCE-BUFFER is non-nil, it should
specify a buffer from where the link search should happen. This
-is used internally by `org-open-link-from-string'."
+is used internally by `org-open-link-from-string'.
+
+On top of syntactically correct links, this function will open
+the link at point in comments and the first link in a property
+drawer line."
(interactive "P")
;; On a code block, open block's results.
(unless (call-interactively #'org-babel-open-src-block-result)
@@ -10602,7 +10584,7 @@ is used internally by `org-open-link-from-string'."
(setq org-window-config-before-follow-link (current-window-configuration))
(org-remove-occur-highlights nil nil t)
(unless (run-hook-with-args-until-success 'org-open-at-point-functions)
- (let* ((context (org-element-context)) type)
+ (let* ((context (org-element-context)) type value)
;; On an unsupported type, check if point is contained within
;; a support one.
(while (and (not (memq (setq type (org-element-type context))
@@ -10610,14 +10592,30 @@ is used internally by `org-open-link-from-string'."
footnote-definition footnote-reference
node-property timestamp)))
(setq context (org-element-property :parent context))))
+ (setq value (org-element-property :value context))
(cond
;; Blank lines at the beginning of buffer: bail out.
((not context) (user-error "No link found"))
- ;; WARNING: Before checking for syntactically correct
- ;; contexts, we make two exceptions as we open links in
- ;; comments and properties.
- ((memq type '(comment node-property))
- (org-open-link-in-comment-or-property))
+ ;; Exception n°1: links in property drawers
+ ((eq type 'node-property)
+ (org-open-link-from-string
+ (and (string-match org-any-link-re value)
+ (match-string-no-properties 0 value))))
+ ;; Exception n°2: links in comments.
+ ((eq type 'comment)
+ (let ((string-rear (replace-regexp-in-string
+ "^[ \t]*# [ \t]*" ""
+ (buffer-substring (point) (line-beginning-position))))
+ (string-front (buffer-substring (point) (line-end-position))))
+ (with-temp-buffer
+ (let ((org-inhibit-startup t)) (org-mode))
+ (insert value)
+ (goto-char (point-min))
+ (when (and (search-forward string-rear nil t)
+ (search-forward string-front (line-end-position) t))
+ (goto-char (match-beginning 0))
+ (org-open-at-point)
+ (when (string= string-rear "") (forward-char))))))
;; On a headline or an inlinetask, but not on a timestamp,
;; a link, a footnote reference or on tags.
((and (memq type '(headline inlinetask))