Symfony project menus for Emacs
95
post-template-default,single,single-post,postid-95,single-format-standard,bridge-core-3.0.1,qodef-qi--no-touch,qi-addons-for-elementor-1.5.3,qode-page-transition-enabled,ajax_updown,page_not_loaded,,vertical_menu_enabled,side_area_uncovered_from_content,qode-theme-ver-28.7,qode-theme-bridge,disabled_footer_top,qode_header_in_grid,wpb-js-composer js-comp-ver-6.8.0,vc_responsive,elementor-default,elementor-kit-6

Symfony project menus for Emacs

Symfony project menus for Emacs

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.

 

symfonu modules in an emacs menu

 

lib/models in an emacs menu

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



Mastodon