-
Notifications
You must be signed in to change notification settings - Fork 3
/
drupal-mode.el
82 lines (66 loc) · 2.49 KB
/
drupal-mode.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
;;; drupal-mode.el --- Major mode for developing Drupal modules
;;; Commentary:
;;
;;; History:
;;
;;; Code:
(require 'w3m)
(defgroup drupal nil
"Drupal Development."
:group 'programming)
(defcustom drupal-api-url "http://api.drupal.org/"
"Drupal API URL."
:type 'string
:group 'drupal)
(defcustom drupal-hook-docstring
"/**
* Implements %s()
*/"
"Documentation string for hook."
:type 'string
:group 'drupal)
;; source: http://drupal.org/node/59868
(defcustom drupal-php-style
'((c-offsets-alist . ((case-label . +)
(arglist-intro . +) ; for FAPI arrays and DBTNG
(arglist-cont-nonempty . c-lineup-math) ; for DBTNG fields and values
(arglist-close . c-lineup-close-paren) ; correct arglist closing parenthesis
)))
"Drupal coding style."
:group 'drupal)
(defcustom drupal-api-buffer-name
"*drupal-api*"
"Buffer name for temporary API lookup."
:type 'string
:group 'drupal)
(defun drupal-hook-implement (hook-name)
"Insert API code for HOOK-NAME at point."
(interactive (list (read-string "Hook name: ")))
(let ((module-name (drupal-module-name))
(docstring (format drupal-hook-docstring hook-name))
(url (concat drupal-api-url hook-name)))
(insert
(concat docstring (with-current-buffer (get-buffer-create drupal-api-buffer-name)
(if (w3m-process-with-wait-handler
(w3m-retrieve-and-render url nil nil nil nil handler))
(let* ((beg (search-forward "<?php" nil t))
(end (- (search-forward "?>" nil t) 2))
(content (buffer-substring-no-properties beg end)))
(replace-regexp-in-string "^function \\(hook\\)_" module-name content nil nil 1))
(error "Failed to fetch page.")))))))
;; based on sacha chua's idea
(defun drupal-module-name ()
"Return the Drupal module name for .module and .install files."
(file-name-sans-extension (file-name-nondirectory (buffer-file-name))))
(define-derived-mode drupal-mode
php-mode "Drupal"
"Major mode for working with Drupal.
\\{drupal-mode-map}"
(c-set-style "drupal-php-style")
(set 'tab-width 2)
(set 'c-basic-offset 2)
(local-set-key (kbd "C-c h") 'drupal-hook-implement)
(set 'indent-tabs-mode nil))
(c-add-style "drupal-php-style" drupal-php-style)
(provide 'drupal-mode)
;;; drupal-mode.el ends here