Skip to content

Commit 85dabbf

Browse files
committed
Refactored a lot of code.
1 parent 0a5c953 commit 85dabbf

File tree

1 file changed

+66
-31
lines changed

1 file changed

+66
-31
lines changed

drupal-mode.el

Lines changed: 66 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -44,69 +44,94 @@
4444
:prefix "drupal-"
4545
:group 'languages)
4646

47+
4748
(defgroup drupal-drush nil
4849
"Drush configuration."
4950
:prefix "drupal-drush-"
5051
:group 'drupal)
5152

52-
;; Should we offer to change line endings if needed?
53+
5354
(defcustom drupal-convert-line-ending 'ask
54-
"Should we offer to change line endings if needed?.
55-
According to http://drupal.org/coding-standards#indenting."
55+
"Whether line endings is converted to a single newline (\\n).
56+
If `Always' always convert line endings.
57+
If `Never' never convert line endings.
58+
If `Ask' ask the user whether to convert line endings.
59+
60+
Drupal coding standards states that all text files should end in
61+
a single newline (\\n)."
5662
:type `(choice
5763
:tag " we offer to change line endings if needed?"
5864
(const :tag "Always" t)
5965
(const :tag "Never" nil)
6066
(const :tag "Ask" ask))
61-
:link '(url-link "http://drupal.org/coding-standards#indenting")
67+
:link '(url-link :tag "drupal.org" "http://drupal.org/coding-standards#indenting")
6268
:group 'drupal)
63-
(make-variable-buffer-local 'drupal-convert-line-ending)
6469

65-
;; Should we delete trailing white space?
66-
(defcustom drupal-delete-trailing-whitespace t
67-
"Should we delete trailing white space?.
68-
According to http://drupal.org/coding-standards#indenting."
70+
71+
(defcustom drupal-delete-trailing-whitespace 'always
72+
"Whether to delete all the trailing whitespace across Drupal buffers.
73+
All whitespace after the last non-whitespace character in a line is deleted.
74+
This respects narrowing, created by C-x n n and friends.
75+
A formfeed is not considered whitespace by this function.
76+
77+
If `Always' delete trailing whitespace across drupal mode buffers.
78+
If `Never' never delete trailing whitespace across drupal mode buffers.
79+
If `Default' do what the global setting is.
80+
81+
Drupal coding standards states that lines should have no trailing
82+
whitespace at the end."
6983
:type `(choice
70-
:tag " we offer to delete trailing whitespace."
71-
(const :tag "Always" t)
72-
(const :tag "Never" nil))
73-
:link '(url-link "http://drupal.org/coding-standards#indenting")
84+
:tag "Whether to delete all the trailing whitespace."
85+
(const :tag "Always" always)
86+
(const :tag "Default" default)
87+
(const :tag "Never" never))
88+
:link '(url-link :tag "drupal.org" "http://drupal.org/coding-standards#indenting")
7489
:group 'drupal)
75-
(make-variable-buffer-local 'drupal-delete-trailing-whitespace)
7690

77-
;; Where to lookup symbols
91+
7892
(defcustom drupal-search-url "http://api.drupal.org/api/search/%v/%s"
7993
"The URL to search the Drupal API.
8094
%v is the Drupal major version.
8195
%s is the search term."
8296
:type '(choice (const :tag "Api.drupal.org" "http://api.drupal.org/api/search/%v/%s")
8397
(const :tag "Api.drupalcontrib.org" "http://api.drupalcontrib.org/api/search/%v/%s")
8498
(string :tag "Other" "http://example.com/api/search/%v/%s"))
99+
:link '(url-link :tag "api.drupalcontrib.org" "http://api.drupalcontrib.org")
100+
:link '(url-link :tag "api.drupal.org" "http://api.drupal.org")
85101
:group 'drupal)
86102

103+
87104
(defcustom drupal-drush-search-url "http://api.drush.org/api/search/%v/%s"
88105
"The URL to search the Drush API.
89106
%v is the Drush version.
90107
%s is the search term."
91108
:type '(choice (const :tag "Api.drush.org" "http://api.drush.org/api/search/%v/%s")
92109
(string :tag "Other" "http://example.com/api/search/%v/%s"))
110+
:link '(url-link :tag "api.drush.org" "http://api.drush.org")
93111
:group 'drupal-drush)
94112

113+
95114
(defcustom drupal-drush-program (executable-find "drush")
96-
"Name of the Drush program."
115+
"Name of the Drush executable.
116+
Include path to the executable if it is not in your $PATH."
97117
:type 'file
118+
:link '(url-link :tag "Drush" "http://drupal.org/project/drush")
98119
:group 'drupal-drush)
99120

121+
100122
(defcustom drupal-drush-version (ignore-errors
101123
(replace-regexp-in-string
102124
"[\n\r]" ""
103125
(with-output-to-string
104126
(with-current-buffer standard-output
105127
(call-process drupal-drush-program nil (list t nil) nil "--version" "--pipe")))))
106-
"The installed version of Drush."
128+
"Version number of the installed version Drush."
107129
:type 'string
130+
:link '(variable-link drupal-drush-program)
108131
:group 'drupal-drush)
109132

133+
134+
110135
(defvar drupal-version nil "Drupal version as auto detected.")
111136
(make-variable-buffer-local 'drupal-version)
112137
(put 'drupal-version 'safe-local-variable 'string-or-null-p)
@@ -136,19 +161,37 @@ According to http://drupal.org/coding-standards#indenting."
136161
:init-value nil
137162
:lighter " Drupal"
138163
:keymap drupal-mode-map
164+
165+
;; Detect drupal version, drupal root, etc.
139166
(drupal-detect-drupal-version)
167+
168+
;; Delete trailing white space.
169+
(when (eq drupal-delete-trailing-whitespace 'always)
170+
(add-hook 'before-save-hook 'delete-trailing-whitespace nil t))
171+
(when (eq drupal-delete-trailing-whitespace 'never)
172+
(remove-hook 'before-save-hook 'delete-trailing-whitespace t))
173+
174+
;; Handle line ending and trailing white space.
175+
(add-hook 'before-save-hook 'drupal-convert-line-ending nil t)
176+
177+
;; Stuff special for php-mode buffers.
140178
(when (eq major-mode 'php-mode)
141179
(c-add-language 'drupal-mode 'c-mode)
142180
(c-set-style "drupal")))
143181

182+
;;;###autoload
144183
(define-minor-mode drupal-drush-mode
145184
"Advanced minor mode for Drupal Drush development.\n\n\\{drupal-drush-mode-map}"
146185
:group 'drupal-drush
147186
:init-value nil
148187
:lighter " Drush"
149188
:keymap drupal-drush-mode-map
189+
190+
;; Currently only enables drupal-mode.
150191
(drupal-mode 1))
151192

193+
194+
152195
;; drupal style
153196
(defcustom drupal-style
154197
'((c-basic-offset . 2)
@@ -167,7 +210,7 @@ According to http://drupal.org/coding-standards#indenting."
167210
)
168211
"Drupal coding style.
169212
According to http://drupal.org/coding-standards#indenting."
170-
:link '(url-link "http://drupal.org/coding-standards#indenting")
213+
:link '(url-link :tag "drupal.org" "http://drupal.org/coding-standards#indenting")
171214
:group 'drupal)
172215

173216
(c-add-style "drupal" drupal-style)
@@ -195,7 +238,7 @@ of the project)."
195238
(message "Clearing all caches...")
196239
(call-process drupal-drush-program nil nil nil "cache-clear" "all")
197240
(message "Clearing all caches...done")))
198-
(message "Can't clear caches. No DRUPALROOT and/or no drush command.")))
241+
(message "Can't clear caches. No DRUPAL_ROOT and/or no drush command.")))
199242

200243

201244

@@ -239,12 +282,6 @@ should save your files with unix style end of line."
239282
(progn
240283
(setq drupal-convert-line-ending nil)))))
241284

242-
(defun drupal-delete-trailing-whitespace ()
243-
"Delete trailing whitespace if in drupal mode."
244-
(when (and drupal-mode
245-
drupal-delete-trailing-whitespace)
246-
(delete-trailing-whitespace)))
247-
248285
(defun drupal-search-documentation ()
249286
"Search Drupal documentation for symbol at point."
250287
(interactive)
@@ -263,7 +300,9 @@ should save your files with unix style end of line."
263300

264301
;; Detect Drupal and Drupal version
265302
(defun drupal-detect-drupal-version ()
266-
"Detect if the buffer is part of a Drupal project."
303+
"Detect if the buffer is part of a Drupal project.
304+
If part of a Drupal project also detect the version of Drupal and
305+
the location of DRUPAL_ROOT."
267306
(interactive)
268307
(if drupal-version
269308
drupal-version
@@ -305,8 +344,7 @@ The function is suitable for adding to the supported major modes
305344
mode-hook, i.e.
306345
307346
(eval-after-load 'php-mode
308-
'(add-hook 'php-mode-hook 'drupal-mode-bootstrap))
309-
"
347+
'(add-hook 'php-mode-hook 'drupal-mode-bootstrap))"
310348
(when (eq major-mode 'php-mode)
311349
(drupal-detect-drupal-version)
312350
(when drupal-version
@@ -323,9 +361,6 @@ mode-hook, i.e.
323361
(add-to-list 'auto-mode-alist '("\\.\\(module\\|test\\|install\\|theme\\|tpl\\.php\\)$" . php-mode))
324362
(add-to-list 'auto-mode-alist '("\\.info$" . conf-windows-mode)))
325363

326-
;; Handle line ending and trailing white space.
327-
(add-hook 'before-save-hook 'drupal-convert-line-ending)
328-
(add-hook 'before-save-hook 'drupal-delete-trailing-whitespace)
329364

330365
;; Load support for various Emacs features if necessary.
331366
(eval-after-load 'etags '(require 'drupal/etags))

0 commit comments

Comments
 (0)