Skip to content

Commit 3937ec3

Browse files
committed
Initial version.
1 parent 6e1ef13 commit 3937ec3

8 files changed

+418
-0
lines changed

Makefile

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
.PHONY: all
2+
3+
VERSION=0.1.0
4+
5+
all: drupal-mode.info README
6+
7+
drupal-mode.info: README.md
8+
pandoc -t texinfo $^ | makeinfo -o $@
9+
10+
README: README.md
11+
pandoc -t plain -o $@ $^
12+
13+
# create a tar ball in package.el format for uploading to http://marmalade-repo.org
14+
elpa-package: README drupal-mode.el drupal-mode-pkg.el drupal-mode.info dir
15+
tar -c -s "@^@drupal-mode-${VERSION}/@" -f drupal-mode-${VERSION}.tar $^

README

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
Drupal Mode
2+
===========
3+
4+
Drupal Mode is an advanced minor mode for developing in Drupal.
5+
6+
Drupal Mode is based on top of PHP mode and defines among other things
7+
indentation etc. to match Drupal Coding Standards.
8+
9+
Mission statement
10+
-----------------
11+
12+
- Don't over do it
13+
- Only provide what makes sense in standard Emacs fashion.
14+
- Leave out what is considered personal taste.
15+
- Provide optional stuff if in doubt.
16+
- ... or provide option to disable if the personal taste is
17+
considered good practice.
18+
- The rest can go as advice on EmacsWiki or github wiki or g.d.o.
19+
20+
- Lets base this on Emacs 24 - to do it simple, backporting can come
21+
later.
22+
- Do the right thing in all relevant major modes:
23+
- php-mode
24+
- javascript mode(s)
25+
- conf-mode (module.info)
26+
27+
- Provide the mode via ELPA.
28+
29+
Installation
30+
------------
31+
32+
The easiest way to install Drupal Mode is probably to install it via the
33+
ELPA archive at Marmalade.

README.md

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Drupal Mode #
2+
3+
Drupal Mode is an advanced minor mode for developing in Drupal.
4+
5+
Drupal Mode is based on top of PHP mode and defines among other things
6+
indentation etc. to match Drupal Coding Standards.
7+
8+
## Mission statement ##
9+
10+
* Don't over do it
11+
* Only provide what makes sense in standard Emacs fashion.
12+
* Leave out what is considered personal taste.
13+
* Provide optional stuff if in doubt.
14+
* ... or provide option to disable if the personal taste is considered good practice.
15+
* The rest can go as advice on EmacsWiki or github wiki or g.d.o.
16+
* Lets base this on Emacs 24 - to do it simple, backporting can come later.
17+
* Do the right thing in all relevant major modes:
18+
* php-mode
19+
* javascript mode(s)
20+
* conf-mode (module.info)
21+
* Provide the mode via ELPA.
22+
23+
## Installation ##
24+
25+
The easiest way to install Drupal Mode is probably to install it via
26+
the ELPA archive at [Marmalade](http://marmalade-repo.org).

dir

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
This is the file .../info/dir, which contains the
2+
topmost node of the Info hierarchy, called (dir)Top.
3+
The first time you invoke Info you start off looking at this node.
4+

5+
File: dir, Node: Top This is the top of the INFO tree
6+
7+
This (the Directory node) gives a menu of major topics.
8+
Typing "q" exits, "?" lists all Info commands, "d" returns here,
9+
"h" gives a primer for first-timers,
10+
"mEmacs<Return>" visits the Emacs manual, etc.
11+
12+
In Emacs, you can click mouse button 2 on a menu item or cross reference
13+
to select it.
14+
15+
* Menu:
16+
17+
Programming
18+
* Drupal: (drupal-mode). Advanced minor mode for developing in Drupal.

drupal-mode-pkg.el

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
(define-package "drupal-mode" "0.1.0"
2+
"Advanced minor mode for developing in Drupal"
3+
'((php-mode "1.5.0")))

drupal-mode.el

+245
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,245 @@
1+
;;; drupal-mode.el --- Advanced minor mode for developing in Drupal
2+
3+
;; Copyright (C) 2012 Arne Jørgensen
4+
5+
;; Author: Arne Jørgensen <[email protected]>
6+
;; URL: https://github.com/arnested/drupal-mode
7+
;; Created: January 17, 2012
8+
;; Version: 0.1.0
9+
;; Package-Requires: ((php-mode "1.5.0"))
10+
;; Keywords: programming, php, drupal
11+
12+
;; This file is NOT part of GNU Emacs.
13+
14+
;; GNU Emacs is free software: you can redistribute it and/or modify
15+
;; it under the terms of the GNU General Public License as published by
16+
;; the Free Software Foundation, either version 3 of the License, or
17+
;; (at your option) any later version.
18+
19+
;; GNU Emacs is distributed in the hope that it will be useful,
20+
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21+
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22+
;; GNU General Public License for more details.
23+
24+
;; You should have received a copy of the GNU General Public License
25+
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
26+
27+
;;; Commentary:
28+
29+
;; Drupal mode is an advanced minor mode for developing in Drupal.
30+
31+
;; Drupal mode is based on top of PHP mode and defines among other
32+
;; things indentation etc. to match Drupal Coding Standards.
33+
34+
;;; Code:
35+
36+
(require 'php-mode)
37+
38+
39+
40+
;; Customization
41+
(defgroup drupal nil
42+
"Drupal configuration."
43+
:prefix "drupal-"
44+
:group 'languages)
45+
46+
;; Should we offer to change line endings if needed?
47+
(defcustom drupal-convert-line-ending 'ask
48+
"Should we offer to change line endings if needed?.
49+
According to http://drupal.org/coding-standards#indenting."
50+
:type `(choice
51+
:tag " we offer to change line endings if needed?"
52+
(const :tag "Always" t)
53+
(const :tag "Never" nil)
54+
(const :tag "Ask" ask))
55+
:group 'drupal)
56+
(make-variable-buffer-local 'drupal-convert-line-ending)
57+
58+
;; Should we delete trailing white space?
59+
(defcustom drupal-delete-trailing-whitespace t
60+
"Should we delete trailing white space?.
61+
According to http://drupal.org/coding-standards#indenting."
62+
:type `(choice
63+
:tag " we offer to delete trailing whitespace."
64+
(const :tag "Always" t)
65+
(const :tag "Never" nil))
66+
:group 'drupal)
67+
68+
;;
69+
(defcustom drupal-search-url "http://api.drupal.org/api/search/%s/%s"
70+
"The URL to search the Drupal API.
71+
First parameter is the Drupal version. Second parameter is the search term."
72+
:type 'string
73+
:group 'drupal)
74+
75+
(defvar drupal-version nil "Drupal version as auto detected.")
76+
(make-variable-buffer-local 'drupal-version)
77+
(put 'drupal-version 'safe-local-variable 'string-or-null-p)
78+
79+
(defvar drupal-mode-map
80+
(let ((map (make-sparse-keymap)))
81+
(define-key map "\C-cdf" 'drupal-search-documentation)
82+
map)
83+
"Keymap for `drupal-mode'")
84+
85+
86+
87+
;;;###autoload
88+
(define-minor-mode drupal-mode
89+
"Major mode for developing Drupal modules and code.\n\n\\{drupal-mode-map}"
90+
:group 'drupal
91+
:init-value nil
92+
:lighter "/Drupal"
93+
:keymap drupal-mode-map
94+
(drupal-detect-drupal-version)
95+
(when (eq major-mode 'php-mode)
96+
(c-add-language 'drupal-mode 'c-mode)
97+
(c-set-style "drupal"))
98+
99+
(add-hook 'before-save-hook 'drupal-convert-line-ending)
100+
(add-hook 'before-save-hook 'drupal-delete-trailing-whitespace))
101+
102+
;; drupal style
103+
(defcustom drupal-style
104+
'((c-basic-offset . 2)
105+
(fill-column . 80)
106+
(show-trailing-whitespace . t)
107+
(indent-tabs-mode . nil)
108+
(require-final-newline . t)
109+
(c-offsets-alist . ((arglist-close . 0)
110+
(arglist-cont-nonempty . c-lineup-math)
111+
(arglist-intro . +)
112+
(case-label . +)
113+
(comment-intro . 0)))
114+
)
115+
"Drupal coding style.
116+
According to http://drupal.org/coding-standards#indenting."
117+
:group 'drupal)
118+
119+
(c-add-style "drupal" drupal-style)
120+
(add-to-list 'c-default-style '(drupal-mode . "drupal"))
121+
122+
123+
124+
(defun drupal-mode-manual ()
125+
"Go to the Drupal Mode info page."
126+
(interactive)
127+
(info-display-manual "drupal-mode"))
128+
129+
130+
131+
;; Make a menu keymap (with a prompt string)
132+
;; and make it the menu bar item's definition.
133+
(define-key drupal-mode-map [menu-bar] (make-sparse-keymap))
134+
(define-key drupal-mode-map [menu-bar drupal]
135+
(cons "Drupal" (make-sparse-keymap "Drupal")))
136+
137+
;; Define specific subcommands in this menu.
138+
(define-key drupal-mode-map
139+
[menu-bar drupal customize]
140+
'("Customize Drupal Mode" . (lambda () (interactive) (customize-group 'drupal))))
141+
(define-key drupal-mode-map
142+
[menu-bar drupal manual]
143+
'("Drupal Mode manual" . drupal-mode-manual))
144+
(define-key drupal-mode-map
145+
[menu-bar drupal search-documentation]
146+
'("Search documentation" . drupal-search-documentation))
147+
148+
149+
150+
;; utility functions
151+
152+
(defun drupal-convert-line-ending ()
153+
"Convert to unix style line ending.
154+
According to http://drupal.org/coding-standards#indenting you
155+
should save your files with unix style end of line."
156+
(when (and (eq major-mode 'drupal-mode)
157+
drupal-convert-line-ending
158+
(/= (coding-system-eol-type buffer-file-coding-system) 0))
159+
(if (or (eq drupal-convert-line-ending t)
160+
(y-or-n-p "Convert to unix style line endings?"))
161+
(progn
162+
(message "Coding system conversion")
163+
(set-buffer-file-coding-system 'unix))
164+
(progn
165+
(setq drupal-convert-line-ending nil)))))
166+
167+
(defun drupal-delete-trailing-whitespace ()
168+
"Delete trailing whitespace if in drupal mode."
169+
(when (and (eq major-mode 'drupal-mode)
170+
drupal-delete-trailing-whitespace)
171+
(delete-trailing-whitespace)))
172+
173+
(defun drupal-search-documentation ()
174+
"Search Drupal documentation for symbol at point."
175+
(interactive)
176+
(browse-url(format drupal-search-url (drupal-major-version drupal-version) (symbol-at-point))))
177+
178+
179+
180+
;; Detect Drupal and Drupal version
181+
(defun drupal-detect-drupal-version ()
182+
"Detect if the buffer is part of a Drupal project."
183+
(interactive)
184+
(if drupal-version
185+
drupal-version
186+
(dolist (file '("modules/system/system.module" "includes/bootstrap.inc" "core/includes/bootstrap.inc"))
187+
(let ((dir (locate-dominating-file buffer-file-name file)))
188+
(when dir
189+
(with-current-buffer (find-file-noselect (concat dir file) t)
190+
(save-excursion
191+
(goto-char (point-min))
192+
(when (re-search-forward "\\(define('VERSION',\\|const VERSION =\\) +'\\(.+\\)'" nil t)
193+
(dir-locals-set-class-variables 'drupal-class `((nil . ((drupal-version . ,(match-string-no-properties 2))))))
194+
(dir-locals-set-directory-class dir 'drupal-class)))
195+
(setq drupal-version (match-string-no-properties 2))
196+
)
197+
(hack-local-variables))))
198+
drupal-version))
199+
200+
(defun drupal-major-version (&optional version)
201+
"Return major version number of version string.
202+
If major version number is 4 - return both major and minor."
203+
(unless version
204+
(setq version (drupal-detect-drupal-version)))
205+
(let ((version-list (split-string version "\\.")))
206+
(if (= (string-to-number (car version-list)) 4)
207+
(format "%s.%s" (car version-list) (cadr version-list))
208+
(car version-list))))
209+
210+
;;;###autoload
211+
(defun drupal-mode-bootstrap ()
212+
"Activate Drupal minor mode if major mode is supported.
213+
The command will activate `drupal-mode' if the current major mode
214+
is a mode supported by `drupal-mode' (currently only
215+
`php-mode').
216+
217+
The function is suitable for adding to the supported major modes
218+
mode-hook, i.e.
219+
220+
(eval-after-load 'php-mode
221+
'(add-hook 'php-mode-hook 'drupal-mode-bootstrap))
222+
"
223+
(when (eq major-mode 'php-mode)
224+
(drupal-detect-drupal-version)
225+
(when drupal-version
226+
(drupal-mode 1))))
227+
228+
;;;###autoload
229+
(eval-after-load 'php-mode
230+
'(add-hook 'php-mode-hook 'drupal-mode-bootstrap))
231+
232+
;;;###autoload
233+
(progn
234+
(add-to-list 'auto-mode-alist '("\\.\\(module\\|test\\|install\\|theme\\|tpl\\.php\\)$" . php-mode))
235+
(add-to-list 'auto-mode-alist '("\\.info$" . conf-windows-mode)))
236+
237+
238+
239+
(provide 'drupal-mode)
240+
241+
;; Local Variables:
242+
;; coding: utf-8
243+
;; End:
244+
245+
;;; drupal-mode.el ends here

drupal-mode.elc

6.31 KB
Binary file not shown.

0 commit comments

Comments
 (0)