@@ -226,6 +226,7 @@ get better filling in Doxygen comments."
226226 (?h . drupal-insert-hook)
227227 (?f . drupal-insert-function)
228228 (?m . drupal-module-name)
229+ (?e . drupal-drush-php-eval)
229230 (?t . drupal-wrap-string-in-t-function))
230231 " Map of mnemonic keys and functions for keyboard shortcuts.
231232See `drupal-mode-map' ." )
@@ -365,6 +366,19 @@ of the project)."
365366 (message " Clearing all caches...done " )))
366367 (message " Can't clear caches. No DRUPAL_ROOT and/or no drush command. " )))
367368
369+ (defun drupal-drush-php-eval ()
370+ " Evaluate active region with `drush php-eval'."
371+ (interactive )
372+ (when (and (use-region-p )
373+ drupal-rootdir
374+ drupal-drush-program)
375+ (let ((root drupal-rootdir)
376+ (code (buffer-substring (region-beginning ) (region-end ))))
377+ (with-temp-buffer-window " *drush php-eval*" nil nil
378+ (message " PHP eval... " )
379+ (call-process drupal-drush-program nil t nil (concat " --root=" (expand-file-name root)) " php-eval" code)
380+ (message " PHP eval...done " )))))
381+
368382
369383
370384; ; Make a menu keymap (with a prompt string)
@@ -391,6 +405,10 @@ of the project)."
391405(define-key drupal-mode-map
392406 [menu-bar drupal manual]
393407 '(" Drupal Mode manual" . drupal-mode-manual))
408+ (define-key drupal-mode-map
409+ [menu-bar drupal php-eval]
410+ '(menu-item " PHP Evaluate active region" drupal-drush-php-eval
411+ :enable (and (use-region-p ) drupal-rootdir drupal-drush-program)))
394412(define-key drupal-mode-map
395413 [menu-bar drupal insert-hook]
396414 '(" Insert hook implementation" . drupal-insert-hook))
0 commit comments