summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2017-05-21 01:16:58 -0400
committerKyle Meyer <kyle@kyleam.com>2017-05-21 14:52:30 -0400
commit0de7ad043085cae5129b04dab8ed45f57b45ae44 (patch)
tree984c0c3466eba51064fa68f53d832e17ed286736
parent39b3f45a7db6f089f95de34d49f56132438d5648 (diff)
downloadorg-mode-0de7ad043085cae5129b04dab8ed45f57b45ae44.tar.gz
org-store-link: Don't roll C-u behavior into C-u C-u behavior
* lisp/org.el (org-store-link): When a double C-u prefix argument is given, do not reverse the meaning of the org-context-in-file-links option. * testing/lisp/test-org.el (test-org/store-link): Add tests. This allows the user to fall back to the core link storing functions without also reversing their org-context-in-file-links preference, because wanting to do the former does not mean a user also wants to do the latter. Reported-by: York Zhao <gtdplatform@gmail.com> <https://lists.gnu.org/archive/html/emacs-orgmode/2017-05/msg00254.html>
-rw-r--r--lisp/org.el13
-rw-r--r--testing/lisp/test-org.el77
2 files changed, 84 insertions, 6 deletions
diff --git a/lisp/org.el b/lisp/org.el
index c8bab87..da1420f 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -9921,9 +9921,10 @@ and then used in capture templates."
This link is added to `org-stored-links' and can later be inserted
into an Org buffer with `org-insert-link' (`\\[org-insert-link]').
-For some link types, a `\\[universal-argument]' prefix ARG is interpreted.
-For links to Usenet articles, ARG negates `org-gnus-prefer-web-links'.
-For file links, ARG negates `org-context-in-file-links'.
+For some link types, a `\\[universal-argument]' prefix ARG is interpreted. \
+A single
+`\\[universal-argument]' negates `org-context-in-file-links' for file links or
+`org-gnus-prefer-web-links' for links to Usenet articles.
A `\\[universal-argument] \\[universal-argument]' prefix ARG forces \
skipping storing functions that are not
@@ -10085,7 +10086,8 @@ active region."
(abbreviate-file-name
(buffer-file-name (buffer-base-buffer)))))
;; Add a context search string
- (when (org-xor org-context-in-file-links arg)
+ (when (org-xor org-context-in-file-links
+ (equal arg '(4)))
(let* ((element (org-element-at-point))
(name (org-element-property :name element)))
(setq txt (cond
@@ -10112,7 +10114,8 @@ active region."
(abbreviate-file-name
(buffer-file-name (buffer-base-buffer)))))
;; Add a context string.
- (when (org-xor org-context-in-file-links arg)
+ (when (org-xor org-context-in-file-links
+ (equal arg '(4)))
(setq txt (if (org-region-active-p)
(buffer-substring (region-beginning) (region-end))
(buffer-substring (point-at-bol) (point-at-eol))))
diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el
index 237d7aa..ebbea9b 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -2399,7 +2399,82 @@ http://article.gmane.org/gmane.emacs.orgmode/21459/"
(org-test-with-temp-text-in-file "#+NAME: foo\nParagraph"
(let ((file (buffer-file-name)))
(equal (format "[[file:%s::foo][foo]]" file)
- (org-store-link nil)))))))
+ (org-store-link nil))))))
+ ;; Store link to Org buffer, with context.
+ (should
+ (let ((org-stored-links nil)
+ (org-id-link-to-org-use-id nil)
+ (org-context-in-file-links t))
+ (org-test-with-temp-text-in-file "* h1"
+ (let ((file (buffer-file-name)))
+ (equal (format "[[file:%s::*h1][h1]]" file)
+ (org-store-link nil))))))
+ ;; Store link to Org buffer, without context.
+ (should
+ (let ((org-stored-links nil)
+ (org-id-link-to-org-use-id nil)
+ (org-context-in-file-links nil))
+ (org-test-with-temp-text-in-file "* h1"
+ (let ((file (buffer-file-name)))
+ (equal (format "[[file:%s][file:%s]]" file file)
+ (org-store-link nil))))))
+ ;; C-u prefix reverses `org-context-in-file-links' in Org buffer.
+ (should
+ (let ((org-stored-links nil)
+ (org-id-link-to-org-use-id nil)
+ (org-context-in-file-links nil))
+ (org-test-with-temp-text-in-file "* h1"
+ (let ((file (buffer-file-name)))
+ (equal (format "[[file:%s::*h1][h1]]" file)
+ (org-store-link '(4)))))))
+ ;; A C-u C-u does *not* reverse `org-context-in-file-links' in Org
+ ;; buffer.
+ (should
+ (let ((org-stored-links nil)
+ (org-id-link-to-org-use-id nil)
+ (org-context-in-file-links nil))
+ (org-test-with-temp-text-in-file "* h1"
+ (let ((file (buffer-file-name)))
+ (equal (format "[[file:%s][file:%s]]" file file)
+ (org-store-link '(16)))))))
+ ;; Store file link to non-Org buffer, with context.
+ (should
+ (let ((org-stored-links nil)
+ (org-context-in-file-links t))
+ (org-test-with-temp-text-in-file "one\n<point>two"
+ (fundamental-mode)
+ (let ((file (buffer-file-name)))
+ (equal (format "[[file:%s::one]]" file)
+ (org-store-link nil))))))
+ ;; Store file link to non-Org buffer, without context.
+ (should
+ (let ((org-stored-links nil)
+ (org-context-in-file-links nil))
+ (org-test-with-temp-text-in-file "one\n<point>two"
+ (fundamental-mode)
+ (let ((file (buffer-file-name)))
+ (equal (format "[[file:%s][file:%s]]" file file)
+ (org-store-link nil))))))
+ ;; C-u prefix reverses `org-context-in-file-links' in non-Org
+ ;; buffer.
+ (should
+ (let ((org-stored-links nil)
+ (org-context-in-file-links nil))
+ (org-test-with-temp-text-in-file "one\n<point>two"
+ (fundamental-mode)
+ (let ((file (buffer-file-name)))
+ (equal (format "[[file:%s::one]]" file)
+ (org-store-link '(4)))))))
+ ;; A C-u C-u does *not* reverse `org-context-in-file-links' in
+ ;; non-Org buffer.
+ (should
+ (let ((org-stored-links nil)
+ (org-context-in-file-links nil))
+ (org-test-with-temp-text-in-file "one\n<point>two"
+ (fundamental-mode)
+ (let ((file (buffer-file-name)))
+ (equal (format "[[file:%s][file:%s]]" file file)
+ (org-store-link '(16))))))))
;;; Node Properties