Friday, June 26, 2009

anything.el for Maya document (continued)


For those who uses emacs for Maya programming :)

Internally it uses "find". It is not limited to Maya documents. you can search for documents in any directory (and its sub directories recursively).

Usage:
Type META-; (I made a shortcut that searches only Maya API documents)
See the movie in another blog entry.

Installation:
1) If you haven't installed anything.el install it.

2) Install w3m web browser for Emacs. I just executed


sudo yum install w3m-el

3) Add hohe2-anything-find.el in any directory.

4) Add this line to .emacs, (unless the directory path has been added already)

(add-to-list 'load-path "path/to/directory")
5) Add the following script to your .emacs file. (Change the paths to the document directories).

;;Additional anything config for Maya.
(hohe2-register-c-source-find
'hohe2-anything-c-source-find-mayaapi "Maya API" "/usr/autodesk/maya/docs/Maya8.5/en_US/API" 2)

(hohe2-register-c-source-find
'hohe2-anything-c-source-find-mayamel "Maya MEL" "/usr/autodesk/maya/docs/Maya8.5/en_US/Commands" 2)

(hohe2-register-c-source-find
'hohe2-anything-c-source-find-mayapython "Maya Python" "/usr/autodesk/maya/docs/Maya8.5/en_US/CommandsPython" 2)

(hohe2-register-c-source-find
'hohe2-anything-c-source-find-mayanode "Maya Node" "/usr/autodesk/maya/docs/Maya8.5/en_US/Nodes" 2)

(setq hohe2-anything-alternative-sources (list hohe2-anything-c-source-find-mayaapi
hohe2-anything-c-source-find-mayamel
hohe2-anything-c-source-find-mayapython
hohe2-anything-c-source-find-mayanode
))

(defun hohe2-anything-alternative ()
(interactive)
(anything hohe2-anything-alternative-sources);;)
)
(global-set-key (kbd "M-;") 'hohe2-anything-alternative)
6) Restart Emacs.

7) Enjoy programming if it works.

This is my development environment

2.6.29.4-167.fc11.i686.PAE #1 SMP Wed May 27 17:28:22 EDT 2009 i686 i686 i386 GNU/Linux
Gnome 2.26.2
GNU Emacs 22.3.1

No guarantee. Use it at your own risk.

hohe2-anything-find.el

(require 'w3m)
(require 'anything-config)


;;;; Find


(defun hohe2-register-c-source-find (config-symbol title-name find-dir min-required-chars)
"Register a new find configuration"
(set config-symbol
(list
`(name . ,title-name)
`(candidates . (lambda ()
(apply 'start-process "find-process" nil
(list
"find"
,find-dir
"-iname"
(concat "*" anything-pattern "*"))
)))
'(type . findfile)
`(requires-pattern . ,min-required-chars)
'(delayed))
)
)


(add-to-list 'anything-type-attributes
'(findfile (action
("Browse other window" . (lambda (c)
(select-window (frame-selected-window (make-frame)))
(w3m-browse-url (concat "file://" c))))
("Browse" . (lambda (c) (w3m-browse-url (concat "file://" c))))
("Browse with Firefox" . (lambda (c) (shell-command (concat "firefox file://" c))))
("Open as text" . find-file)
)))



(provide 'hohe2-anything-find)

Currently it assumes every document is HTML. I will modify the script so that it looks at the file extension to know how to open the file soon(er or later). If you modify part of the above code like this it opens the file as a text by default.
June 28 added. Done.

(add-to-list 'anything-type-attributes
'(findfile (action
("Open as text" . find-file)
("Browse other window" . (lambda (c)
(select-window (frame-selected-window (make-frame)))
(w3m-browse-url (concat "file://" c))))
("Browse" . (lambda (c) (w3m-browse-url (concat "file://" c))))
("Browse with Firefox" . (lambda (c) (shell-command (concat "firefox file://" c))))
)))

No comments: