Tassilo Horn <[EMAIL PROTECTED]> writes:
> [EMAIL PROTECTED] 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
filename)))))))
(or (anything-transform-file-actions actions candidate)
actions)))
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)
anything-transform-actions-file)
(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" .
load-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
filename))))))))))
Then, it's just a matter of appending additonal transformers to the
list.
What do you think?
--
Bill Clementson
_______________________________________________
gnu-emacs-sources mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/gnu-emacs-sources