emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] org-insert-link: allow ido usage when inserting links
@ 2012-10-11  4:19 tony day
  2012-10-11 12:23 ` Nicolas Goaziou
  2012-10-11 20:17 ` Samuel Wales
  0 siblings, 2 replies; 5+ messages in thread
From: tony day @ 2012-10-11  4:19 UTC (permalink / raw)
  To: emacs-orgmode


From a8f301277e15bc786fa63bbcce3ba1afb85c46aa Mon Sep 17 00:00:00 2001
From: Tony Day <zygomega@gmail.com>
Date: Mon, 10 Sep 2012 13:54:38 +1000
Subject: [PATCH 41/41] org-insert-link: allow ido usage when inserting links

* lisp/org.el (org-insert-link): added all-links to cleanly create prefix+st
(org-i-read-file-name): new defun to allow ido to read a file: link if allowed
---
 lisp/org.el |   39 +++++++++++++++++++++++++--------------
 1 file changed, 25 insertions(+), 14 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index 1c18d70..a918cfc 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -9397,7 +9397,7 @@ be used as the default description."
 	 tmphist ; byte-compile incorrectly complains about this
 	 (link link-location)
 	 (abbrevs org-link-abbrev-alist-local)
-	 entry file all-prefixes auto-desc)
+	 entry file all-links all-prefixes auto-desc)
     (cond
      (link-location) ; specified by arg, just use it.
      ((org-in-regexp org-bracket-link-regexp 1)
@@ -9443,19 +9443,19 @@ Use TAB to complete link prefixes, then RET for type-specific completion support
 				 org-link-types))
       (unwind-protect
 	  (progn
+	    (setq all-links (append
+			     (mapcar 'car org-stored-links)
+			     (mapcar 'cadr org-stored-links)
+			     (mapcar (lambda (x) (concat x ":"))
+				     all-prefixes)))
+	    (setq all-links (delete nil all-links))
 	    (setq link
-		  (let ((org-completion-use-ido nil)
-			(org-completion-use-iswitchb nil))
-		    (org-completing-read
-		     "Link: "
-		     (append
-		      (mapcar (lambda (x) (list (concat x ":")))
-			      all-prefixes)
-		      (mapcar 'car org-stored-links)
-		      (mapcar 'cadr org-stored-links))
-		     nil nil nil
-		     'tmphist
-		     (caar org-stored-links))))
+		  (org-completing-read
+		   "Link: "
+		   all-links
+		   nil nil nil
+		   'tmphist
+		   (caar org-stored-links)))
 	    (if (not (string-match "\\S-" link))
 		(error "No link selected"))
 	    (mapc (lambda(l)
@@ -9542,7 +9542,7 @@ Use TAB to complete link prefixes, then RET for type-specific completion support
 (defun org-file-complete-link (&optional arg)
   "Create a file link using completion."
   (let (file link)
-    (setq file (read-file-name "File: "))
+    (setq file (org-i-read-file-name "File: "))
     (let ((pwd (file-name-as-directory (expand-file-name ".")))
 	  (pwd1 (file-name-as-directory (abbreviate-file-name
 					 (expand-file-name ".")))))
@@ -9560,6 +9560,17 @@ Use TAB to complete link prefixes, then RET for type-specific completion support
        (t (setq link (concat "file:" file)))))
     link))
 
+(defun org-i-read-file-name (&rest args)
+  "Read-file-name using `ido-mode' speedup if available."
+  (org-without-partial-completion
+   (if (and org-completion-use-ido
+            (fboundp 'ido-read-file-name)
+            (boundp 'ido-mode) ido-mode
+            (listp (second args)))
+       (let ((ido-enter-matching-directory nil))
+         (apply 'ido-read-file-name args))
+     (apply 'read-file-name args))))
+
 (defun org-completing-read (&rest args)
   "Completing-read with SPACE being a normal character."
   (let ((enable-recursive-minibuffers t)
-- 
1.7.9.6 (Apple Git-31.1)

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

* Re: [PATCH] org-insert-link: allow ido usage when inserting links
  2012-10-11  4:19 [PATCH] org-insert-link: allow ido usage when inserting links tony day
@ 2012-10-11 12:23 ` Nicolas Goaziou
  2012-10-12  3:56   ` tony day
  2012-10-11 20:17 ` Samuel Wales
  1 sibling, 1 reply; 5+ messages in thread
From: Nicolas Goaziou @ 2012-10-11 12:23 UTC (permalink / raw)
  To: tony day; +Cc: emacs-orgmode

Hello,

tony day <zygomega@gmail.com> writes:

Thanks for submitting a patch. Here are a few comments.

> From a8f301277e15bc786fa63bbcce3ba1afb85c46aa Mon Sep 17 00:00:00 2001
> From: Tony Day <zygomega@gmail.com>
> Date: Mon, 10 Sep 2012 13:54:38 +1000
> Subject: [PATCH 41/41] org-insert-link: allow ido usage when inserting
> links
> * lisp/org.el (org-insert-link): added all-links to cleanly create prefix+st
> (org-i-read-file-name): new defun to allow ido to read a file: link if
> allowed

Entries should end with a period (not the title, though). Also, if you
haven't signed FSF papers yet, you should append "TINYCHANGE" on a line
on its own.

> ---
>  lisp/org.el |   39 +++++++++++++++++++++++++--------------
>  1 file changed, 25 insertions(+), 14 deletions(-)
>
> diff --git a/lisp/org.el b/lisp/org.el
> index 1c18d70..a918cfc 100644
> --- a/lisp/org.el
> +++ b/lisp/org.el
> @@ -9397,7 +9397,7 @@ be used as the default description."
>  	 tmphist ; byte-compile incorrectly complains about this
>  	 (link link-location)
>  	 (abbrevs org-link-abbrev-alist-local)
> -	 entry file all-prefixes auto-desc)
> +	 entry file all-links all-prefixes auto-desc)
>      (cond
>       (link-location) ; specified by arg, just use it.
>       ((org-in-regexp org-bracket-link-regexp 1)
> @@ -9443,19 +9443,19 @@ Use TAB to complete link prefixes, then RET for type-specific completion support
>  				 org-link-types))
>        (unwind-protect
>  	  (progn
> +	    (setq all-links (append
> +			     (mapcar 'car org-stored-links)
> +			     (mapcar 'cadr org-stored-links)
> +			     (mapcar (lambda (x) (concat x ":"))
> +				     all-prefixes)))
> +	    (setq all-links (delete nil all-links))

This should be (delq nil all-links).

>  	    (setq link
> -		  (let ((org-completion-use-ido nil)
> -			(org-completion-use-iswitchb nil))
> -		    (org-completing-read
> -		     "Link: "
> -		     (append
> -		      (mapcar (lambda (x) (list (concat x ":")))
> -			      all-prefixes)
> -		      (mapcar 'car org-stored-links)
> -		      (mapcar 'cadr org-stored-links))
> -		     nil nil nil
> -		     'tmphist
> -		     (caar org-stored-links))))
> +		  (org-completing-read
> +		   "Link: "
> +		   all-links
> +		   nil nil nil
> +		   'tmphist
> +		   (caar org-stored-links)))

I don't see the interest of this change nor how it is related to
allowing ido usage to insert links. Can

  (append
    (mapcar (lambda (x) (list (concat x ":"))) all-prefixes)
            (mapcar 'car org-stored-links)
            (mapcar 'cadr org-stored-links))

contain nil values?

If so, adding a (delq nil (append ...)) should be enough. This should be
a separate patch anyway.

> +(defun org-i-read-file-name (&rest args)
> +  "Read-file-name using `ido-mode' speedup if available."
> +  (org-without-partial-completion
> +   (if (and org-completion-use-ido
> +            (fboundp 'ido-read-file-name)
> +            (boundp 'ido-mode) ido-mode
> +            (listp (second args)))
> +       (let ((ido-enter-matching-directory nil))
> +         (apply 'ido-read-file-name args))
> +     (apply 'read-file-name args))))

Ok. There are a couple of places where this could be used
(`org-file-complete-link' for example). You should describe ARGS in the
docstring, though (writing, at least, that they refer to arguments from
`read-file-name').

Also, I'm not sure about the name. `completing-read' became
`org-icompleting-read'. Shouldn't `read-file-name' become
`org-iread-file-name'? 


Regards,

-- 
Nicolas Goaziou

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

* Re: [PATCH] org-insert-link: allow ido usage when inserting links
  2012-10-11  4:19 [PATCH] org-insert-link: allow ido usage when inserting links tony day
  2012-10-11 12:23 ` Nicolas Goaziou
@ 2012-10-11 20:17 ` Samuel Wales
  2012-10-11 23:21   ` link creation, ido usage, and headers tony day
  1 sibling, 1 reply; 5+ messages in thread
From: Samuel Wales @ 2012-10-11 20:17 UTC (permalink / raw)
  To: tony day; +Cc: emacs-orgmode

Slighly different from this, I wonder if anybody has anything similar:

I have blog entries with a :Live-URL: property.  What I'd like is to
use ido to complete on the header that contains that property, and
create a link with the value of that property as the URL and the
header offered as default for the description.

Maybe this is too different?

-- 
The Kafka Pandemic: http://thekafkapandemic.blogspot.com

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

* link creation, ido usage, and headers
  2012-10-11 20:17 ` Samuel Wales
@ 2012-10-11 23:21   ` tony day
  0 siblings, 0 replies; 5+ messages in thread
From: tony day @ 2012-10-11 23:21 UTC (permalink / raw)
  To: Samuel Wales; +Cc: emacs-orgmode

Hi Sam,

On 12 Oct 2012, at 07:17, Samuel Wales <samologist@gmail.com> wrote:

> Slighly different from this, I wonder if anybody has anything similar:
> 
> I have blog entries with a :Live-URL: property.  What I'd like is to
> use ido to complete on the header that contains that property, and
> create a link with the value of that property as the URL and the
> header offered as default for the description.
> 
> Maybe this is too different?
> 

Not too different.  Expanding the org-insert-link types to include headers was on my todo list (somewhere).  I think much of the functionality you need is already in the org-refile process.  In particular, the help for org-refile-targets says:

#+begin_quote
  A specification of how to find candidate refile targets.  This may be
  any of:
  - a cons cell (:tag . "TAG") to identify refile targets by a tag.
    This tag has to be present in all target headlines, inheritance will
    not be considered.
 #+end_quote
  
Rerouting the org refile technology to the link tech may be a one liner, or may be hard.  Others will have a better sense of the scope.

Tony

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

* Re: [PATCH] org-insert-link: allow ido usage when inserting links
  2012-10-11 12:23 ` Nicolas Goaziou
@ 2012-10-12  3:56   ` tony day
  0 siblings, 0 replies; 5+ messages in thread
From: tony day @ 2012-10-12  3:56 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: emacs-orgmode



On 11 Oct 2012, at 23:23, Nicolas Goaziou <n.goaziou@gmail.com> wrote:

> Thanks for submitting a patch. Here are a few comments.

Hi Nicolas, thanks for taking the time to go through the code.  I will resubmit the patch in a separate mail (I didn't know whether I could respond to your suggestions and submit a new patch in the same mail).

> Entries should end with a period (not the title, though). Also, if you
> haven't signed FSF papers yet, you should append "TINYCHANGE" on a line
> on its own.

I have signed the FSF papers and they have been processed.

> I don't see the interest of this change nor how it is related to
> allowing ido usage to insert links. Can
> 
>  (append
>    (mapcar (lambda (x) (list (concat x ":"))) all-prefixes)
>            (mapcar 'car org-stored-links)
>            (mapcar 'cadr org-stored-links))
> 
> contain nil values?
> 
> If so, adding a (delq nil (append ...)) should be enough. This should be
> a separate patch anyway.

The problem is actualy the list bit, which causes a bug when using ido (but not when using normal completion).

Having gone through it again, I don't think the append can contain nil values, so I removed that bit.

> Shouldn't `read-file-name' become
> `org-iread-file-name'? 

Agreed and changed.

I don't think the patch can be split into two - the bug from list is only a bug if ido is used.

Here's some test code it case it helps:

- unit test
    #+begin_src emacs-lisp
      ;;(setq org-stored-links nil)
      (setq org-stored-links 
            '((#("file:~/stuff/org/bugz.org::*current debugging" 28 35 (fontified t org-category "bugz" line-prefix #("*" 0 1 (face org-hide)) wrap-prefix #("    " 0 4 (face org-indent)) face org-level-2) 36 45 (fontified t org-category "bugz" line-prefix #("*" 0 1 (face org-hide)) wrap-prefix #("    " 0 4 (face org-indent)) face org-level-2)) "current debugging")))
      ;;(setq org-stored-links
      ;;      '((#("file:~/stuff/org/bugz.org::*test link 2" 28 32 (fontified t line-prefix #("**" 0 2 (face org-hide)) wrap-prefix #("      " 0 6 (face org-indent)) face org-level-3) 33 37 (fontified t line-prefix #("**" 0 2 (face org-hide)) wrap-prefix #("      " 0 6 (face org-indent)) face org-level-3) 38 39 (fontified t line-prefix #("**" 0 2 (face org-hide)) wrap-prefix #("      " 0 6 (face org-indent)) face org-level-3)) "test link 2") (#("file:~/stuff/org/bugz.org::*test link 1" 28 32 (fontified t line-prefix #("**" 0 2 (face org-hide)) wrap-prefix #("      " 0 6 (face org-indent)) face org-level-3) 33 37 (fontified t line-prefix #("**" 0 2 (face org-hide)) wrap-prefix #("      " 0 6 (face org-indent)) face org-level-3) 38 39 (fontified t line-prefix #("**" 0 2 (face org-hide)) wrap-prefix #("      " 0 6 (face org-indent)) face org-level-3)) "test link 1")))
      (setq abbrevs org-link-abbrev-alist-local)
      (setq all-prefixes (append org-link-types
                                 (mapcar 'car abbrevs)
                                 (mapcar 'car org-link-abbrev-alist)))
      (setq all-links (append
                       (mapcar 'cadr org-stored-links)
                       (mapcar (lambda (x) (concat x ":"))
                               all-prefixes)
                       (mapcar 'car org-stored-links)))
      ;;(setq all-links (delete nil all-links))
      (print (loop for link in all-links
                   collect
                   (list link)))  
       
  #+end_src


Tony

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

end of thread, other threads:[~2012-10-12  3:56 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-11  4:19 [PATCH] org-insert-link: allow ido usage when inserting links tony day
2012-10-11 12:23 ` Nicolas Goaziou
2012-10-12  3:56   ` tony day
2012-10-11 20:17 ` Samuel Wales
2012-10-11 23:21   ` link creation, ido usage, and headers tony day

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).