[erlang-questions] Weblog post on Emacs/erlang-mode/Distel
Tue May 29 19:24:33 CEST 2007
Erik Stenman <> writes:
> Bill Clementson wrote:
>> Being new to Erlang, I would appreciate any comments/suggestions
>> on ways experienced Erlang users "tweak" their .emacs files for
>> Erlang use.
> Most Erlang projects I work on have a file structure like:
> | |-doc
> | |-include
> | |-src
> I use the following functions to find keywords in all src files in the project.
> It requires some basic unix commands and assumes you are using subversion,
> it works for me, but it might not work for you.
> ;;; Find in erlang project dirs
> (defun kfind-at (path word)
> (grep-find (concat "find " path (concat " -name '.svn' -prune -o -name '*~' -prune -o -name '*html' -prune -o -type f -print0 | xargs -0 -e grep -n -e " word))))
> (defun kfind (word)
> (interactive "MFind: ")
> (car (split-string (buffer-file-name) "lib"))
> I bind it to keys like:
> (global-set-key (quote ) 'next-error) ;; C-.
> (global-set-key (quote ) 'previous-error) ;; C-,
> (setq ctrl-z-map (make-keymap))
> (global-set-key "\C-z" ctrl-z-map)
> (global-set-key "\C-zf" 'kfind)
> Then, when I am in a buffer of some file in project/lib/appX/src/
> I can do C-zf frotz to find all uses of frotz, and I can move through
> the result with C-. and C-,
> It might seem useless when you have M-. to jump to a function definition,
> but after the first time you have used it to answer a question like
> "Where is the atom "frotz" used?"
> you will never go back.
Yes, I can see how your find function would be useful with a standard
project directory structure. Unfortunately, I work on a number of
different open source and commercial projects and can't depend on the
directory structure or the vc software being consistent, so I took the
liberty to make a couple of mods to your function:
;; Find in project source files
(defvar bc-project-dir nil "Start directory for FIND's")
(defun bc-find-at (path word)
"Search source (ignore VC dirs, backups, docs)"
(grep-find (concat "find " path (concat " -name '.svn' -prune -o \
-name 'CVS' -prune -o \
-name '_darcs' -prune -o \
-name '*~' -prune -o \
-name 'doc' -prune -o \
-type f -print0 \
| xargs -0 grep -n -e " word))))
(defun bc-find (word)
(interactive "MFind: ")
(or bc-project-dir ".")
(global-set-key "\C-." 'next-error)
(global-set-key "\C-," 'previous-error)
(global-set-key "\C-cs" 'bc-find)
If working in a particular project tree, you can set the
'bc-project-dir' variable to the "root directory" for the project and
any searches will be done starting from there (find will ignore any
Subversion, Darcs, or CVS directories as well as any Emacs backup
files and "doc" directories). If no 'bc-project-dir' variable is
specified, searches will be done from the current directory.
Thanks for your tip!
More information about the erlang-questions