Skip to content

Commit 1e06f39

Browse files
committed
Added `drupal-drush-cache-clear'.
The function will run drush to clear all Drupal caches. Put it in the Drupal menu and on C-c d c.
1 parent 83ee02f commit 1e06f39

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

drupal-mode.el

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ According to http://drupal.org/coding-standards#indenting."
118118
(defvar drupal-mode-map
119119
(let ((map (make-sparse-keymap)))
120120
(define-key map "\C-cdf" 'drupal-search-documentation)
121+
(define-key map "\C-cdc" 'drupal-drush-cache-clear)
121122
map)
122123
"Keymap for `drupal-mode'")
123124

@@ -179,6 +180,23 @@ According to http://drupal.org/coding-standards#indenting."
179180
(interactive)
180181
(info "drupal-mode"))
181182

183+
(defun drupal-drush-cache-clear ()
184+
"Clear all Drupal caches.
185+
Runs `drush cache-clear all'. Depends on `drupal-drush-program'
186+
pointing to Drush and depends on the buffer being part of a
187+
Drupal project (that means `drupal-rootdir' being set to the root
188+
of the project)."
189+
(interactive)
190+
(if (and drupal-rootdir
191+
drupal-drush-program)
192+
(let ((root drupal-rootdir))
193+
(with-temp-buffer
194+
(cd-absolute root)
195+
(message "Clearing all caches...")
196+
(call-process drupal-drush-program nil nil nil "cache-clear" "all")
197+
(message "Clearing all caches...done")))
198+
(message "Can't clear caches. No DRUPALROOT and/or no drush command.")))
199+
182200

183201

184202
;; Make a menu keymap (with a prompt string)
@@ -197,6 +215,10 @@ According to http://drupal.org/coding-standards#indenting."
197215
(define-key drupal-mode-map
198216
[menu-bar drupal search-documentation]
199217
'("Search documentation" . drupal-search-documentation))
218+
(define-key drupal-mode-map
219+
[menu-bar drupal cache-clear]
220+
'(menu-item "Clear all caches" drupal-drush-cache-clear
221+
:enable (and drupal-rootdir drupal-drush-program)))
200222

201223

202224

0 commit comments

Comments
 (0)