From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kyle Meyer Subject: [PATCH] org-store-link: Don't roll C-u behavior into C-u C-u behavior Date: Sun, 21 May 2017 01:47:12 -0400 Message-ID: <87zie6yd5r.fsf@kyleam.com> References: <874lwfyw8j.fsf@kyleam.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:34665) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dCJi3-0003jp-2g for emacs-orgmode@gnu.org; Sun, 21 May 2017 01:47:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dCJhz-00005U-JX for emacs-orgmode@gnu.org; Sun, 21 May 2017 01:47:19 -0400 Received: from pb-smtp1.pobox.com ([64.147.108.70]:64351 helo=sasl.smtp.pobox.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dCJhz-00005B-9Y for emacs-orgmode@gnu.org; Sun, 21 May 2017 01:47:15 -0400 In-Reply-To: List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: York Zhao Cc: emacs-orgmode York Zhao writes: [...] > Seems to be a reasonable solution to me. So would you go ahead and make the > change, or, would more people need to agreed on this solution? If there are no objections within a few days, I'll apply the following patch to maint. -- >8 -- Subject: [PATCH] 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 --- lisp/org.el | 13 ++++---- testing/lisp/test-org.el | 77 +++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 84 insertions(+), 6 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index c8bab8712..da1420f66 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -9921,9 +9921,10 @@ (defun org-store-link (arg) 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 @@ (defun org-store-link (arg) (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 @@ (defun org-store-link (arg) (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 237d7aae4..ebbea9bb0 100644 --- a/testing/lisp/test-org.el +++ b/testing/lisp/test-org.el @@ -2399,7 +2399,82 @@ (ert-deftest test-org/store-link () (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\ntwo" + (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\ntwo" + (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\ntwo" + (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\ntwo" + (fundamental-mode) + (let ((file (buffer-file-name))) + (equal (format "[[file:%s][file:%s]]" file file) + (org-store-link '(16)))))))) ;;; Node Properties -- 2.13.0