[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ;;; anything.el --- open anything

From: Tassilo Horn
Subject: Re: ;;; anything.el --- open anything
Date: Fri, 20 Jul 2007 18:54:06 +0200
User-agent: Gnus/5.110007 (No Gnus v0.7) Emacs/22.1.50 (gnu/linux)

"address@hidden" <address@hidden> writes:

> On Jul 20, 12:05 pm, Tassilo Horn <address@hidden> wrote:
>> Hey Tamas,
>> this patch adds a new buffer type with actions to switch or pop to it,
>> just displaying it or killing it.
> Thanks! I added it to the code.


And here's a bit more. With this patch (against the current emacs wiki
version, I got it 5 mins ago) it's possible to open completions of type
file with an external tool. The external tools are completed like in
eshell, but with the advantage, that the calculation is only performed
once. It can be disabled completely by the user if she sets
`anything-external-commands-list' to a list of completions,
e.g. '("gimp" "xpdf" "gv").

This allows the user to use anything.el as application starter (best
used with the locate source).

And another thing: Would you mind setting up a repository for
anything.el, possibly with git, darcs or another distributed version
control system? I think it has a lot of potential, attracts many new
developers and would ease managing and distributing patchsets. The emacs
wiki file could then be used as a stable version.

If you don't have an account on some server, I'd be happy to set up an
account for you on


--8<---------------cut here---------------start------------->8---
diff -u /home/heimdall/elisp/anything.el.orig /home/heimdall/elisp/anything.el
--- /home/heimdall/elisp/anything.el.orig       2007-07-20 18:38:59.000000000 
+++ /home/heimdall/elisp/anything.el    2007-07-20 18:40:06.000000000 +0200
@@ -58,7 +58,7 @@
 ;; This is only an example. Customize it to your own taste!
 (defvar anything-sources `(((name . "Buffers")
                             (candidates . anything-buffer-list)
-                           (type . buffer))
+                            (type . buffer))
                            ((name . "File Name History")
                             (candidates . file-name-history)
@@ -187,6 +187,50 @@
   character typed, only if the user hesitates a bit.")
+(defvar anything-external-commands-list nil
+  "A list of all external commands the user can execute. If this
+variable is not set by the user, it will be calculated
+(defun anything-external-commands-list-1 ()
+  "Returns a list of all external commands the user can execute.
+If `anything-external-commands-list' is non-nil it will return
+its contents. Else it calculates all external commands and sets
+The code is ripped out of `eshell-complete-commands-list'."
+  (if anything-external-commands-list
+      anything-external-commands-list
+    (setq anything-external-commands-list
+          (let* ((paths (split-string (getenv "PATH") path-separator))
+                 (cwd (file-name-as-directory
+                       (expand-file-name default-directory)))
+                 (path "") (comps-in-path ())
+                 (file "") (filepath "") (completions ()))
+            ;; Go thru each path in the search path, finding completions.
+            (while paths
+              (setq path (file-name-as-directory
+                          (expand-file-name (or (car paths) ".")))
+                    comps-in-path
+                    (and (file-accessible-directory-p path)
+                         (file-name-all-completions "" path)))
+              ;; Go thru each completion found, to see whether it should be
+              ;; used, e.g. see if it's executable.
+              (while comps-in-path
+                (setq file (car comps-in-path)
+                      filepath (concat path file))
+                (if (and (not (member file completions))
+                         (or (string-equal path cwd)
+                             (not (file-directory-p filepath)))
+                         (file-executable-p filepath))
+                    (setq completions (cons file completions)))
+                (setq comps-in-path (cdr comps-in-path)))
+              (setq paths (cdr paths)))
+            completions))))
 ;; This value is only provided as an example. Customize it to your own
 ;; taste!
 (defvar anything-type-actions
@@ -194,12 +238,19 @@
              ("Delete File" . (lambda (file)
                                 (if (y-or-n-p (format "Really delete file %s? "
-                                    (delete-file file))))))
+                                    (delete-file file))))
+             ("Open File with external Tool" .
+              (lambda (file)
+                (start-process "anything-open-file-externally"
+                               nil
+                               (completing-read "Program: "
+                               file)))))
     (buffer . (("Switch to Buffer" . switch-to-buffer)
                ("Pop to Buffer"    . pop-to-buffer)
                ("Display Buffer"   . display-buffer)
                ("Kill Buffer"      . kill-buffer))))
-"A list of (TYPE . ACTION) pairs specifying actions for sources
+  "A list of (TYPE . ACTION) pairs specifying actions for sources
   which have no action defined. See the `action' attribute of
   `anything-sources' for possible action values.")
@@ -294,8 +345,12 @@
                                      (push (symbol-name a) 
                      (sort commands 'string-lessp))) 
-    (action . (lambda (command-name) 
-                (call-interactively (intern command-name)))))
+    (action . (("Execute Command" . (lambda (command-name) 
+                                      (call-interactively
+                                       (intern command-name))))
+               ("Describe Command" . (lambda (command-name)
+                                       (describe-function
+                                        (intern command-name)))))))
   "Source for completing and invoking Emacs commands.")

Diff finished.  Fri Jul 20 18:40:27 2007
--8<---------------cut here---------------end--------------->8---

reply via email to

[Prev in Thread] Current Thread [Next in Thread]