emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] org-insert-link: allow ido usage when inserting links
@ 2012-09-14  9:21 tony day
  2012-09-14  9:39 ` Giovanni Ridolfi
  2012-09-22 16:17 ` Bastien
  0 siblings, 2 replies; 7+ messages in thread
From: tony day @ 2012-09-14  9:21 UTC (permalink / raw)
  To: emacs-orgmode

This time with patch inlined.

I had a look through and couldn't see an obvious reason why you can't use ido with org-insert-link, so here's a patch to enable it.

I haven't looked at using ido for editing links yet, but I figure org-capture would be a good pattern to do this.  The other thought here is to add an 'org:' link type so you can fire up ido just like org-capture (not sure what non-ido org-capture looks like).

This is my first patch, so please let me know if I'm not doing things right.

Tony

[PATCH] org-insert-link: allow ido usage when inserting links

* lisp/org.el (org-insert-link): added all-links to cleanly create prefix+stored links for use in ido
(org-i-read-file-name): new defun to allow ido to read a file: link if allowed

TINYCHANGE
---
 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.12

^ permalink raw reply related	[flat|nested] 7+ messages in thread
* [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; 7+ 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] 7+ messages in thread

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

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-14  9:21 [PATCH] org-insert-link: allow ido usage when inserting links tony day
2012-09-14  9:39 ` Giovanni Ridolfi
2012-09-22 16:17 ` Bastien
  -- strict thread matches above, loose matches on Subject: below --
2012-10-11  4:19 tony day
2012-10-11 12:23 ` Nicolas Goaziou
2012-10-12  3:56   ` tony day
2012-10-11 20:17 ` Samuel Wales

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