summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2020-02-19 18:21:46 +0100
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2020-02-19 18:42:50 +0100
commit0c55d3f42103d8b92727e87697feabf819831b6f (patch)
treea0db17d2dad668da27005ea7a8334dd599bb20a8
parent12c09be3a6aa629d055841739ebc1da0ae76cf26 (diff)
downloadorg-mode-0c55d3f42103d8b92727e87697feabf819831b6f.tar.gz
Remove special syntax from context in file links
* lisp/ol.el (org-link--clear-syntax-from-context): New function. (org-store-link): Use new function.
-rw-r--r--lisp/ol.el26
1 files changed, 20 insertions, 6 deletions
diff --git a/lisp/ol.el b/lisp/ol.el
index f3e3f2b..76454d2 100644
--- a/lisp/ol.el
+++ b/lisp/ol.el
@@ -748,6 +748,16 @@ White spaces are not significant."
"Trim STRING, pack contiguous white spaces, and return it."
(replace-regexp-in-string "[ \t\n]+" " " (org-trim string)))
+(defun org-link--clear-syntax-from-context (context)
+ "Remove special syntax from CONTEXT string and return it."
+ (while (cond ((and (string-prefix-p "(" context)
+ (string-suffix-p ")" context))
+ (setq context (substring context 1 -1)))
+ ((string-match "\\`[#*]+" context)
+ (setq context (substring context (match-end 0))))
+ (t nil)))
+ context)
+
;;; Public API
@@ -1631,11 +1641,14 @@ non-nil."
(name (org-element-property :name element))
(context
(cond
- ((org-link--context-from-region))
+ ((let ((region (org-link--context-from-region)))
+ (and region
+ (org-link--clear-syntax-from-context region))))
(name)
((org-before-first-heading-p)
- (org-link--squeeze-white-spaces
- (org-current-line-string)))
+ (org-link--clear-syntax-from-context
+ (org-link--squeeze-white-spaces
+ (org-current-line-string))))
(t (org-link-heading-search-string)))))
(when (org-string-nw-p context)
(setq cpltxt (format "%s::%s" cpltxt context))
@@ -1649,9 +1662,10 @@ non-nil."
(buffer-file-name (buffer-base-buffer)))))
;; Add a context search string.
(when (org-xor org-link-context-for-files (equal arg '(4)))
- (let ((context (or (org-link--context-from-region)
- (org-link--squeeze-white-spaces
- (org-current-line-string)))))
+ (let ((context (org-link--clear-syntax-from-context
+ (or (org-link--context-from-region)
+ (org-link--squeeze-white-spaces
+ (org-current-line-string))))))
;; Only use search option if there is some text.
(when (org-string-nw-p context)
(setq cpltxt (format "%s::%s" cpltxt context))