[Top][All Lists]

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

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

From: billclem
Subject: Re: ;;; anything.el --- open anything
Date: Thu, 26 Jul 2007 21:16:27 -0000
User-agent: G2/1.0

Tassilo Horn <address@hidden> writes:

> address@hidden writes:
> Hi Bill,
>> Actually, the macro should be:
>> (defmacro anything-add-to-actions (var action)
>>   `(setq ,var (cons (car ,var)
>>                  (append
>>                   (cdr ,var)
>>                   (list ',action)))))
> Yep, that looks nice. I made some little changes, so that multiple
> evaluations don't add an action several times and added documentation.
> Thanks a lot,

Thanks for adding it to anything-config.el - that's one less thing I
need to have in my .emacs file! ;-)

I've also had a look at the default transform functions in
anything-config.el. Since this is an area where there is likely to be
a lot of customizations, it might be better to provide a default
function that is more easy to customize. For example, the default
anything-transform-file-actions function provides a single new action
for elisp files. If I want to add another action to the transformer
(say, the Mac-specific one in my previous post) but still keep the
default elisp transformer, I can write something like this:

(defun bc-anything-transform-file-actions (actions candidate)
  "Append my custom actions to the default list of actions.

Currently a \"Load Emacs Lisp File\" will be appended if the file
is an emacs lisp file and my \"Open File with default Tool\" will
be appended if the computer is a Mac."
  (when (listp actions)

    (if (string= "darwin" (symbol-name system-type))
        (setq actions (append actions
                              '(("Open File with default Tool" .
                                 (lambda (filename)
                                   (call-process "/usr/bin/open" nil 0 nil 

    (or (anything-transform-file-actions actions candidate)

However, this starts to get pretty messy if I want to use other
transformers that other people write.

An alternative would be to provide (in anything-config.el) a
"standard" transformer function for a "type" and some example
transforms that others can model their transforms after. For example,
for the file transforms:

(defvar anything-transform-actions-file nil "Transforms for files.")

(defun anything-transform-file-actions (actions candidate)
  "Append useful actions to the list of actions."
  (when (and (listp actions)
    (loop for func in anything-transform-actions-file
          do (setq actions (or (funcall func actions candidate) actions))
          finally (return actions))))

(setq anything-transform-actions-file
      (append anything-transform-actions-file
              '((lambda (actions candidate)
                  (if (or (string= (file-name-extension candidate) "el")
                          (string= (file-name-extension candidate) "elc"))
                      (append actions '(("Load Emacs Lisp File" . 

(setq anything-transform-actions-file
      (append anything-transform-actions-file
              '((lambda (actions candidate)
                  (if (string= "darwin" (symbol-name system-type))
                      (append actions
                              '(("Open File with default Tool" .
                                 (lambda (filename)
                                   (call-process "/usr/bin/open" nil 0 nil 

Then, it's just a matter of appending additonal transformers to the

What do you think?

Bill Clementson

reply via email to

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