Last time I blabbed about why anything.el
is rad, but left you hanging with just a few out-of-the-box implications or that rad-ness. This time, let’s use anything.el
to make our own anything.
The simplest anything.el
customization is making your own anything command. You’ll find an example of this in anything-config.el
.
[lisp gutter=”false”]
(defun my-anything ()
(interactive)
(anything-other-buffer
‘(anything-c-source-buffers
anything-c-source-file-name-history
anything-c-source-info-pages
anything-c-source-info-elisp
anything-c-source-man-pages
anything-c-source-locate
anything-c-source-emacs-commands)
"*my-anything*"))
[/lisp]
anything-other-buffer
is a simplified version of anything
that takes a list of sources for its first argument and a buffer name as its second. So M-x my-anything
now gives you an anything
selection buffer for all them sources there. You’ll find a wealth of pre-baked sources to choose from in anything-config.el
.
The next level of awesomeness comes when you create your own source, which is cheese easy. Do a C-h v
on anything-sources
. Here you’ll get a lengthy description of how to set one of these buggers up. I’ve made the world’s simplest, most contrived, and most stupidly named source below.
[lisp gutter=”false”]
(setf my-pretend-files-source
‘((name . "Name for My Source")
(candidates . ("a" "list" "of" "files"))
(type . file)))
[/lisp]
There are three mandatory keys: name
, candidates
, and either action
or type
. Here I’m pretending to be looking at a list of files, so my type is file
. Types provide common actions for things you’ll commonly be working with. They’re a shortcut to actually writing your own actions.
Now that we’ve got a source, let’s make an anything command that uses it.
[lisp gutter=”false”]
(defun anything-for-pretend-files ()
(interactive)
(anything-other-buffer ‘(my-pretend-files-source)
"*anything-select-buffer-name*"))
[/lisp]
Try out this custom command and hit tab on one of the items to see what you can get with the file
type. You can find a list of types with a C-h v
of anything-type-attributes
.
If you’re not using a type
, you’re using an action
. The action
key takes a list of alists, each of which maps one name string to one function. Something like this:
[lisp gutter=”false”]
(action . (("Action name" . (lambda (selection)
(do-some-crazy-shit-to selection)))))
[/lisp]
Of course, that lambda could be a function name. Let’s make a real action. A real stupid action!
[lisp gutter=”false”]
(setf things-to-say-source
‘((name . "Things To Say")
(candidates . ("Llama" "Guano" "Mochaccino" "Colostomy"))
(action . (("Say it!" .
(lambda (selection)
(message selection)))
("Spray it!" .
(lambda (selection)
(message (concat selection "thpppt"))))))))
(defun anything-things-to-say ()
(interactive)
(anything-other-buffer ‘(things-to-say-source)
"*anything things to say*"))
[/lisp]
“Say it!” is the default action, it’s what happens when we hit return
. “Spray it!” is an alternate action, which we can select by hitting tab
on an item. Remember that this action selection screen is another anything
screen, so you can arrow and C-n
, C-p
through it, but you can also just start typing what you want.
Next steps
Now these examples are collosally stewpid. What’s more, they use only a tiny fraction of the shite tonne of source options anything
‘ll take. If your curiosity is tingling, C-h v anything-sources
and prepare to have your amazement blown.
And if you’re really and truly rapt, tune in next time, when we’ll make a for real anything-project-files
source that lets you fly around the files of your gigantic, deeply nested project like an airbus on an eightball. It’ll be fun.
2 Responses to Anything.else