Symfony project menus for Emacs
by Thomas Beutel
After reading the Productive Programmer, I was inspired to write a custom script to add Symfony menus to my Emacs editor. After some frustration (I find emacs LISP tough to grok), I finally figured it out. (script is below)
Anyway, here are a couple of pictures showing custom menus for a small project. This allows me to find and load module templates, action files, and models quickly and easily.
Â
Â
OK, I didn’t write the script in elisp. Instead, I use perl to generate the elisp code. To create the elisp code, I run this script at the root of the Symfony project.
#!/usr/bin/perl
$dir = `pwd`;
chomp $dir;Â Â Â
print qq{
;; menu.el - quick access menus for emacs editor
;; *** auto generated by bin/symenu ***
;; To use this menu, load into buffer and then ESC-X eval-buffer
;; T. Beutel
(defvar my-menu nil "my menu")
};
my $menus = qq{
 (easy-menu-define my-menu global-map "My own menu"
 '("Modules"
};
my $count = 0;
while(){
 ($module) = (m/ \/ ([^\/]+) \z /xms);
 $count++;
 print qq{
(defun $module-actions ()
 (interactive)
 (let (mybuffer)
 (setq mybuffer (find-file "$dir/apps/frontend/modules/$module/actions/actions.class.php"))
 )
)
};
$menus .= qq{
 ("$module"
 ["actions" $module-actions t]
};
while(){
 ($template,$success,$tmpl2) = (m/ \/ (?: ([^\/]+) (Success) | ([^\/]+) ) \.php \z /xms);
 $template ||= $tmpl2;
$count++;
 print qq{
(defun $module-$template ()
 (interactive)
 (let (mybuffer)
 (setq mybuffer (find-file "$dir/apps/frontend/modules/$module/templates/$template$success.php"))
 )
)
};
$menus .= qq{
 ["$template" $module-$template t]
};
}
$menus .= ")\n";
}
print $menus . "))\n";
# Models
my $menus = qq{
 (easy-menu-define my-menu global-map "My own menu"
 '("Models"
};
my $count = 0;
while(
){
 ($model) = (m/ \/ ([^\/]+) \.php \z /xms);
$count++;
 print qq{
(defun model-$model ()
 (interactive)
 (let (mybuffer)
 (setq mybuffer (find-file "$dir/lib/model/$model.php"))
 )
)
};
$menus .= qq{
 ["$model" model-$model t]
};
}
print $menus . "))\n";
Update: After I wrote my implementation, I found this pure elisp implementation that creates an even better symfony navigation: http://svn.tracfort.jp/svn/dino-symfony/emacs-symfony/emacs-symfony/symfony-navigation.el