emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* `org-store-link' to skip link storing functions without touching `org-context-in-file-links'
@ 2017-05-20 16:02 York Zhao
  2017-05-20 22:55 ` Kyle Meyer
  0 siblings, 1 reply; 6+ messages in thread
From: York Zhao @ 2017-05-20 16:02 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 851 bytes --]

Hi org-mode developers,

Recently I found it very useful to being able to store links linking to
source code in git repository. I used org-git-link.el for this purpose and
it works well.

However, the biggest problem I'm having now is that once I loaded
org-git-link.el, I'm forced to always store links linking to git repository
which is not always I want because I also need to be able to store links
linking to the files in the working directory instead of in the git
repository.

I'm aware of the 'C-u C-u' prefix of `org-store-link', however, by the
current design, using 'C-u C-u' negates `org-context-in-file-links', i.e.,
the link would be stored without embedding the text to search for.

Is it possible to make `org-store-link' able to skip the link storing
functions without touching `org-context-in-file-links'?


Thanks in advance,

York

[-- Attachment #2: Type: text/html, Size: 956 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: `org-store-link' to skip link storing functions without touching `org-context-in-file-links'
  2017-05-20 16:02 `org-store-link' to skip link storing functions without touching `org-context-in-file-links' York Zhao
@ 2017-05-20 22:55 ` Kyle Meyer
  2017-05-21  3:09   ` York Zhao
  0 siblings, 1 reply; 6+ messages in thread
From: Kyle Meyer @ 2017-05-20 22:55 UTC (permalink / raw)
  To: York Zhao, emacs-orgmode

York Zhao <gtdplatform@gmail.com> writes:

> However, the biggest problem I'm having now is that once I loaded
> org-git-link.el, I'm forced to always store links linking to git repository
> which is not always I want because I also need to be able to store links
> linking to the files in the working directory instead of in the git
> repository.
>
> I'm aware of the 'C-u C-u' prefix of `org-store-link', however, by the
> current design, using 'C-u C-u' negates `org-context-in-file-links', i.e.,
> the link would be stored without embedding the text to search for.

Yeah, org-store-link overloads ARG, and there seems to be an undesirable
interaction here.

> Is it possible to make `org-store-link' able to skip the link storing
> functions without touching `org-context-in-file-links'?

I think that, when negating org-context-in-file-links, the function
should check whether a single C-u was given rather than just checking if
ARG is non-nil.  If someone uses C-u C-u to fall back to core Org
functions, I don't see any reason to assume that they also want to
reverse their org-context-in-file-links preference.

-- 
Kyle

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: `org-store-link' to skip link storing functions without touching `org-context-in-file-links'
  2017-05-20 22:55 ` Kyle Meyer
@ 2017-05-21  3:09   ` York Zhao
  2017-05-21  5:47     ` [PATCH] org-store-link: Don't roll C-u behavior into C-u C-u behavior Kyle Meyer
  0 siblings, 1 reply; 6+ messages in thread
From: York Zhao @ 2017-05-21  3:09 UTC (permalink / raw)
  To: Kyle Meyer; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 1803 bytes --]

> Yeah, org-store-link overloads ARG

Exactly!

> I think that, when negating org-context-in-file-links, the function should
> check whether a single C-u was given rather than just checking if ARG is
> non-nil.

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 someone uses C-u C-u to fall back to core Org functions, I don't see
any
> reason to assume that they also want to reverse their
> org-context-in-file-links preference.

Maybe!


Thanks,

York


On Sat, May 20, 2017 at 6:55 PM, Kyle Meyer <kyle@kyleam.com> wrote:

> York Zhao <gtdplatform@gmail.com> writes:
>
> > However, the biggest problem I'm having now is that once I loaded
> > org-git-link.el, I'm forced to always store links linking to git
> repository
> > which is not always I want because I also need to be able to store links
> > linking to the files in the working directory instead of in the git
> > repository.
> >
> > I'm aware of the 'C-u C-u' prefix of `org-store-link', however, by the
> > current design, using 'C-u C-u' negates `org-context-in-file-links',
> i.e.,
> > the link would be stored without embedding the text to search for.
>
> Yeah, org-store-link overloads ARG, and there seems to be an undesirable
> interaction here.
>
> > Is it possible to make `org-store-link' able to skip the link storing
> > functions without touching `org-context-in-file-links'?
>
> I think that, when negating org-context-in-file-links, the function
> should check whether a single C-u was given rather than just checking if
> ARG is non-nil.  If someone uses C-u C-u to fall back to core Org
> functions, I don't see any reason to assume that they also want to
> reverse their org-context-in-file-links preference.
>
> --
> Kyle
>

[-- Attachment #2: Type: text/html, Size: 2494 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH] org-store-link: Don't roll C-u behavior into C-u C-u behavior
  2017-05-21  3:09   ` York Zhao
@ 2017-05-21  5:47     ` Kyle Meyer
  2017-05-21  6:59       ` Nicolas Goaziou
  0 siblings, 1 reply; 6+ messages in thread
From: Kyle Meyer @ 2017-05-21  5:47 UTC (permalink / raw)
  To: York Zhao; +Cc: emacs-orgmode

York Zhao <gtdplatform@gmail.com> 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 <gtdplatform@gmail.com>
<https://lists.gnu.org/archive/html/emacs-orgmode/2017-05/msg00254.html>
---
 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\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))))))))
 
 \f
 ;;; Node Properties
-- 
2.13.0

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] org-store-link: Don't roll C-u behavior into C-u C-u behavior
  2017-05-21  5:47     ` [PATCH] org-store-link: Don't roll C-u behavior into C-u C-u behavior Kyle Meyer
@ 2017-05-21  6:59       ` Nicolas Goaziou
  2017-05-21 18:57         ` Kyle Meyer
  0 siblings, 1 reply; 6+ messages in thread
From: Nicolas Goaziou @ 2017-05-21  6:59 UTC (permalink / raw)
  To: Kyle Meyer; +Cc: York Zhao, emacs-orgmode

Hello,

Kyle Meyer <kyle@kyleam.com> writes:

> If there are no objections within a few days, I'll apply the following
> patch to maint.

LGTM. Thank you.

Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] org-store-link: Don't roll C-u behavior into C-u C-u behavior
  2017-05-21  6:59       ` Nicolas Goaziou
@ 2017-05-21 18:57         ` Kyle Meyer
  0 siblings, 0 replies; 6+ messages in thread
From: Kyle Meyer @ 2017-05-21 18:57 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: York Zhao, emacs-orgmode

Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:

> Kyle Meyer <kyle@kyleam.com> writes:
>
>> If there are no objections within a few days, I'll apply the following
>> patch to maint.
>
> LGTM. Thank you.

Thanks for having a look.  Applied in 0de7ad043.

-- 
Kyle

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-05-21 18:57 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-20 16:02 `org-store-link' to skip link storing functions without touching `org-context-in-file-links' York Zhao
2017-05-20 22:55 ` Kyle Meyer
2017-05-21  3:09   ` York Zhao
2017-05-21  5:47     ` [PATCH] org-store-link: Don't roll C-u behavior into C-u C-u behavior Kyle Meyer
2017-05-21  6:59       ` Nicolas Goaziou
2017-05-21 18:57         ` Kyle Meyer

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).