Skip to content

Commit b7f50ec

Browse files
committed
Detecting version shouldn't fail on non-files.
1 parent 571f945 commit b7f50ec

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

drupal-mode.el

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -196,18 +196,20 @@ should save your files with unix style end of line."
196196
(if drupal-version
197197
drupal-version
198198
(dolist (file '("modules/system/system.module" "includes/bootstrap.inc" "core/includes/bootstrap.inc"))
199-
(let ((dir (locate-dominating-file buffer-file-name file)))
200-
(when dir
201-
(with-current-buffer (find-file-noselect (concat dir file) t)
202-
(save-excursion
203-
(goto-char (point-min))
204-
(when (re-search-forward "\\(define('VERSION',\\|const VERSION =\\) +'\\(.+\\)'" nil t)
205-
(dir-locals-set-class-variables 'drupal-class `((nil . ((drupal-version . ,(match-string-no-properties 2))))))
206-
(dir-locals-set-directory-class dir 'drupal-class)))
207-
(setq drupal-version (match-string-no-properties 2))
208-
)
209-
(hack-local-variables))))
210-
drupal-version))
199+
(let ((here (or buffer-file-name dired-directory)))
200+
(when here
201+
(let ((dir (locate-dominating-file here file)))
202+
(when dir
203+
(with-current-buffer (find-file-noselect (concat dir file) t)
204+
(save-excursion
205+
(goto-char (point-min))
206+
(when (re-search-forward "\\(define('VERSION',\\|const VERSION =\\) +'\\(.+\\)'" nil t)
207+
(dir-locals-set-class-variables 'drupal-class `((nil . ((drupal-version . ,(match-string-no-properties 2))))))
208+
(dir-locals-set-directory-class dir 'drupal-class)))
209+
(setq drupal-version (match-string-no-properties 2))
210+
)))
211+
(hack-local-variables)
212+
drupal-version)))))
211213

212214
(defun drupal-major-version (&optional version)
213215
"Return major version number of version string.

0 commit comments

Comments
 (0)