Skip to content

Commit

Permalink
Merge branch 'release/0.4.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
arnested committed Feb 21, 2014
2 parents a08207b + 95d6ecd commit da97264
Show file tree
Hide file tree
Showing 10 changed files with 273 additions and 99 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

CASK?=cask
EMACS?=emacs
TAR?=bsdtar
TAR?=COPYFILE_DISABLE=1 bsdtar
PANDOC?=pandoc --atx-headers

VERSION?=$(shell $(CASK) version)
Expand All @@ -46,7 +46,7 @@ $(ARCHIVE_NAME)-pkg.el: $(ARCHIVE_NAME).el

# create a tar ball in package.el format for uploading to http://marmalade-repo.org
$(PACKAGE_NAME).tar: README $(ARCHIVE_NAME).el $(ARCHIVE_NAME)-pkg.el $(ARCHIVE_NAME).info dir drupal/*.el drupal-tests.el drush-make-mode.el
COPYFILE_DISABLE=1 $(TAR) -c -s "@^@$(PACKAGE_NAME)/@" -f $(PACKAGE_NAME).tar $^
$(TAR) -c -s "@^@$(PACKAGE_NAME)/@" -f $(PACKAGE_NAME).tar $^

install: $(PACKAGE_NAME).tar
$(EMACS) --batch -l package -f package-initialize --eval "(package-install-file \"$(PWD)/$(PACKAGE_NAME).tar\")"
Expand Down
196 changes: 129 additions & 67 deletions drupal-mode.el
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
;;; drupal-mode.el --- Advanced minor mode for Drupal development

;; Copyright (C) 2012, 2013 Arne Jørgensen
;; Copyright (C) 2012, 2013, 2014 Arne Jørgensen

;; Author: Arne Jørgensen <[email protected]>
;; URL: https://github.com/arnested/drupal-mode
;; Created: January 17, 2012
;; Version: 0.3.1
;; Version: 0.4.1
;; Package-Requires: ((php-mode "1.5.0"))
;; Keywords: programming, php, drupal

Expand Down Expand Up @@ -36,8 +36,8 @@
(require 'php-mode)
(require 'format-spec)

(eval-when-compile
(require 'css-mode))
;; Silence byte compiler.
(defvar css-indent-level)



Expand All @@ -62,7 +62,7 @@ If `Ask' ask the user whether to convert line endings.
Drupal coding standards states that all text files should end in
a single newline (\\n)."
:type `(choice
:type `(choice
:tag " we offer to change line endings if needed?"
(const :tag "Always" t)
(const :tag "Never" nil)
Expand All @@ -83,7 +83,7 @@ If `Default' do what the global setting is.
Drupal coding standards states that lines should have no trailing
whitespace at the end."
:type `(choice
:type `(choice
:tag "Whether to delete all the trailing whitespace."
(const :tag "Always" always)
(const :tag "Default" default)
Expand All @@ -98,6 +98,7 @@ whitespace at the end."
%s is the search term."
:type '(choice (const :tag "Api.drupal.org" "http://api.drupal.org/api/search/%v/%s")
(const :tag "Api.drupalcontrib.org" "http://api.drupalcontrib.org/api/search/%v/%s")
(const :tag "Api.drupalize.me" "http://api.drupalize.me/api/search/%v/%s")
(string :tag "Other" "http://example.com/api/search/%v/%s"))
:link '(url-link :tag "api.drupalcontrib.org" "http://api.drupalcontrib.org")
:link '(url-link :tag "api.drupal.org" "http://api.drupal.org")
Expand Down Expand Up @@ -162,6 +163,36 @@ Include path to the executable if it is not in your $PATH."
:type '(repeat symbol)
:group 'drupal)

(defcustom drupal-enable-auto-fill-mode t
"Whether to use `auto-fill-mode' Drupal PHP buffers.
Drupal mode will only do auto fill in comments (auto filling code
is not nice).
If `Yes' enable `auto-fill-mode' in Drupal PHP mode buffers.
If `No' don't enable `auto-fill-mode' in Drupal PHP mode buffers (`auto-fill-mode' can still be enabled by other settings)."
:type `(choice
:tag "Enable `auto-fill-mode'."
(const :tag "Yes" t)
(const :tag "No" nil))
:link '(variable-link comment-auto-fill-only-comments)
:group 'drupal)

(defcustom drupal-paragraph-separate "^[ \t]*\\(\\(/[/\\*]+\\)\\|\\(\\*+/\\)\\|\\(\\*?\\)\\|\\(\\*?[ \t]*@[[:alpha:]]+\\([ \t]+.*\\)?\\)\\)[ \t]*$"
"Regexp for beginning of a line that separates paragraphs.
In Drupal mode we extend the regular `paragraph-separate' so we
will get better filling in Doxygen comments."
:type 'regexp
:link '(variable-link paragraph-separate)
:group 'drupal)

(defcustom drupal-paragraph-start (default-value 'drupal-paragraph-separate)
"Regexp for beginning of a line that starts OR separates paragraphs.
In Drupal mode we extend the regular `paragraph-start' so we will
get better filling in Doxygen comments."
:type 'regexp
:link '(variable-link paragraph-start)
:group 'drupal)



(defvar drupal-version nil "Drupal version as auto detected.")
Expand All @@ -188,14 +219,23 @@ Include path to the executable if it is not in your $PATH."
(make-variable-buffer-local 'drupal-project)
(put 'drupal-project 'safe-local-variable 'string-or-null-p)

(defvar drupal-mode-map-alist
'((?d . drupal-search-documentation)
(?c . drupal-drush-cache-clear)
(?h . drupal-insert-hook)
(?f . drupal-insert-function)
(?m . drupal-module-name)
(?t . drupal-wrap-string-in-t-function))
"Map of mnemonic keys and functions for keyboard shortcuts.
See `drupal-mode-map'.")

(defvar drupal-mode-map
(let ((map (make-sparse-keymap)))
(define-key map [(control c) (control v) (control d)] #'drupal-search-documentation)
(define-key map [(control c) (control v) (control c)] #'drupal-drush-cache-clear)
(define-key map [(control c) (control v) (control h)] #'drupal-insert-hook)
(define-key map [(control c) (control v) (control f)] #'drupal-insert-function)
(define-key map [(control c) (control v) (control m)] #'drupal-module-name)
(define-key map [(control c) (control v) (control t)] #'drupal-wrap-string-in-t-function)
;; Iterate `drupal-mode-map-alist' and assign the functions to the
;; mode map on C-c C-v C-`mnemonic-key'.
(dolist (elem drupal-mode-map-alist)
(define-key map `[(control c) (control v) (control ,(car elem))] (cdr elem)))

(define-key map [(control a)] #'drupal-mode-beginning-of-line)
map)
"Keymap for `drupal-mode'")
Expand Down Expand Up @@ -228,9 +268,6 @@ function arguments.")
:lighter " Drupal"
:keymap drupal-mode-map

;; Detect drupal version, drupal root, etc.
(drupal-detect-drupal-version)

;; Delete trailing white space.
(when (eq drupal-delete-trailing-whitespace 'always)
(add-hook 'before-save-hook #'delete-trailing-whitespace nil t))
Expand Down Expand Up @@ -263,7 +300,16 @@ function arguments.")
;; Setup cc-mode style stuff.
(when (derived-mode-p 'c-mode)
(c-add-language 'drupal-mode 'c-mode)
(c-set-style "drupal"))))
(c-set-style "drupal"))

;; Use `auto-fill' only in comments.
(when drupal-enable-auto-fill-mode
(set (make-local-variable 'comment-auto-fill-only-comments) t)
(auto-fill-mode 1))

;; Improve filling in Doxygen comments.
(set (make-local-variable 'paragraph-separate) drupal-paragraph-separate)
(set (make-local-variable 'paragraph-start) drupal-paragraph-start)))



Expand Down Expand Up @@ -497,7 +543,7 @@ It is really slow to download `drupal-search-url'. You should
probably not use this. Have a look at using GNU GLOBAL / Gtags
instead."
(unless version
(setq version (drupal-detect-drupal-version)))
(setq version drupal-version))
(with-temp-buffer
(ignore-errors
(url-insert-file-contents (format-spec drupal-search-url `((?v . ,version)
Expand Down Expand Up @@ -538,79 +584,95 @@ Heavily based on `message-beginning-of-line' from Gnus."
(set zrs t)))
(if (derived-mode-p 'conf-mode)
(let* ((here (point))
(bol (progn (beginning-of-line n) (point)))
(eol (point-at-eol))
(eoh (re-search-forward "= *" eol t)))
(goto-char
(if (and eoh (or (< eoh here) (= bol here)))
eoh bol)))
(bol (progn (beginning-of-line n) (point)))
(eol (point-at-eol))
(eoh (re-search-forward "= *" eol t)))
(goto-char
(if (and eoh (or (< eoh here) (= bol here)))
eoh bol)))
(beginning-of-line n)))



(defvar drupal-local-variables (make-hash-table :test 'equal)
"Drupal local variables hash table.")

;; Detect Drupal and Drupal version
(defun drupal-detect-drupal-version ()
"Detect if the buffer is part of a Drupal project.
If part of a Drupal project also detect the version of Drupal and
the location of DRUPAL_ROOT."
(interactive)
(hack-local-variables)
(drupal-hack-local-variables)
(when (or (not drupal-version)
(not drupal-rootdir))
(dolist (file '("modules/system/system.module" "includes/bootstrap.inc" "core/lib/Drupal.php"))
(let ((here (or buffer-file-name default-directory)))
(when here
(let ((dir (locate-dominating-file here file)))
(when dir
(with-current-buffer (find-file-noselect (concat dir file) t)
(save-excursion
(widen)
(goto-char (point-min))
(when (re-search-forward "\\(define('VERSION',\\|const VERSION =\\) +'\\(.+\\)'" nil t)
(dir-locals-set-class-variables 'drupal-site `((nil . ((drupal-version . ,(match-string-no-properties 2))
(drupal-rootdir . ,dir)))))
(dir-locals-set-directory-class dir 'drupal-site)))
(setq drupal-version (match-string-no-properties 2))))))))
(hack-local-variables))
(with-temp-buffer
(insert-file-contents-literally (concat dir file))
(goto-char (point-min))
(when (re-search-forward "\\(define('VERSION',\\|const VERSION =\\) +'\\(.+\\)'" nil t)
(setq drupal-version (match-string-no-properties 2))
(puthash (expand-file-name dir) `((drupal-version . ,drupal-version)
(drupal-rootdir . ,dir))
drupal-local-variables)))))))))
(drupal-hack-local-variables)
(let ((module (drupal-locate-dominating-module (or buffer-file-name default-directory) t))
(version drupal-version)
(module-name nil)
(module-version nil)
(project nil))
(when module
(with-current-buffer (find-file-noselect module t)
(save-excursion
(widen)
(goto-char (point-min))
(when (and (not drupal-version)
(re-search-forward "^core *=" nil t))
(re-search-forward " *\"?\\([^\"]+\\)\"?" (point-at-eol) t)
(setq version (match-string-no-properties 1)))
(goto-char (point-min))
(when (re-search-forward "^name *=" nil t)
(re-search-forward " *\"?\\([^\"]+\\)\"?" (point-at-eol) t)
(setq module-name (match-string-no-properties 1)))
(goto-char (point-min))
(when (re-search-forward "^version *=" nil t)
(re-search-forward " *\"?\\([^\"]+\\)\"?" (point-at-eol) t)
(setq module-version (match-string-no-properties 1)))
(goto-char (point-min))
(when (re-search-forward "^project *=" nil t)
(re-search-forward " *\"?\\([^\"]+\\)\"?" (point-at-eol) t)
(setq project (match-string-no-properties 1)))
(when (and (string= project "drupal")
(string= module-version "VERSION"))
(setq module-version version))))
(dir-locals-set-class-variables 'drupal-module `((nil . ((drupal-module . ,(file-name-nondirectory
(file-name-sans-extension module)))
(drupal-version . ,version)
(drupal-module-name . ,module-name)
(drupal-module-version . ,module-version)
(drupal-project . ,project)))))
(dir-locals-set-directory-class (file-name-directory module) 'drupal-module)))
(hack-local-variables)
(with-temp-buffer
(insert-file-contents-literally module)
(goto-char (point-min))
(when (and (not drupal-version)
(re-search-forward "^core *=" nil t))
(re-search-forward " *\"?\\([^\"]+\\)\"?" (point-at-eol) t)
(setq version (match-string-no-properties 1)))
(goto-char (point-min))
(when (re-search-forward "^name *=" nil t)
(re-search-forward " *\"?\\([^\"]+\\)\"?" (point-at-eol) t)
(setq module-name (match-string-no-properties 1)))
(goto-char (point-min))
(when (re-search-forward "^version *=" nil t)
(re-search-forward " *\"?\\([^\"]+\\)\"?" (point-at-eol) t)
(setq module-version (match-string-no-properties 1)))
(goto-char (point-min))
(when (re-search-forward "^project *=" nil t)
(re-search-forward " *\"?\\([^\"]+\\)\"?" (point-at-eol) t)
(setq project (match-string-no-properties 1)))
(when (and (string= project "drupal")
(string= module-version "VERSION"))
(setq module-version version))
(puthash (expand-file-name (file-name-directory module)) `((drupal-module . ,(file-name-nondirectory
(file-name-sans-extension module)))
(drupal-version . ,version)
(drupal-module-name . ,module-name)
(drupal-module-version . ,module-version)
(drupal-project . ,project))
drupal-local-variables))))
(drupal-hack-local-variables)
drupal-version)

(defun drupal-hack-local-variables ()
"Drupal hack `drupal-local-variables' as buffer local variables."
(interactive)
(let ((dir (expand-file-name (or (file-name-directory buffer-file-name) default-directory)))
matches)
(maphash (lambda (key value)
(when (string-match (concat "^" (regexp-quote key)) dir)
(add-to-list 'matches key)))
drupal-local-variables)
(sort matches #'(lambda (a b) (> (string-width a) (string-width b))))
(dolist (elem matches)
(let ((vars (gethash elem drupal-local-variables)))
(dolist (var vars)
(set (make-local-variable (car var)) (cdr-safe var)))))))

(defun drupal-locate-dominating-module (file &optional info-file-location)
"Look up the directory hierarchy from FILE for a Drupal module root.
Stop at the first parent where a matching module is found and
Expand Down Expand Up @@ -666,7 +728,7 @@ Used in `drupal-insert-hook' and `drupal-insert-function'."
drupal-module
;; Otherwise fall back to a very naive
;; way of guessing the module name.
(file-name-nondirectory (file-name-sans-extension (buffer-file-name)))))))
(file-name-nondirectory (file-name-sans-extension (or buffer-file-name (buffer-name))))))))
(if (called-interactively-p 'any)
(insert name)
name)))
Expand All @@ -675,7 +737,7 @@ Used in `drupal-insert-hook' and `drupal-insert-function'."
"Return major version number of version string.
If major version number is 4 - return both major and minor."
(unless version
(setq version (drupal-detect-drupal-version)))
(setq version drupal-version))
(when version
(let ((version-list (split-string version "\\.")))
(if (= (string-to-number (car version-list)) 4)
Expand Down
6 changes: 3 additions & 3 deletions drupal/autoinsert.el
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
;;; drupal/autoinsert.el --- Drupal-mode support for `auto-insert-mode'

;; Copyright (C) 2012, 2013 Arne Jørgensen
;; Copyright (C) 2012, 2013, 2014 Arne Jørgensen

;; Author: Arne Jørgensen <[email protected]>
;; Keywords:
;; Keywords:

;; This file is part of Drupal mode.

Expand Down Expand Up @@ -34,7 +34,7 @@
(define-skeleton drupal/autoinsert-insert-info-skeleton
"Drupal info file skeleton."
nil
'(setq v1 (file-name-nondirectory (file-name-sans-extension (buffer-file-name))))
'(setq v1 (file-name-nondirectory (file-name-sans-extension (or buffer-file-name (buffer-name)))))
'(setq v2 (if (drupal-major-version) (>= (string-to-number (drupal-major-version)) 7) t))
"name = " @ - (upcase-initials (replace-regexp-in-string "[-_\\.]+" " " v1)) \n
"description = " @ \n
Expand Down
2 changes: 1 addition & 1 deletion drupal/emacs-drush.el
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
On `after-save-hook' run `drush etags' or `drush gtags'.
Requires `Drush utilities for Emacs users' to be installed."
:type `(choice
:type `(choice
(const :tag "Yes" t)
(const :tag "No" nil))
:link '(url-link :tag "Drush utilities for Emacs users" "https://drupal.org/project/emacs_drush")
Expand Down
4 changes: 2 additions & 2 deletions drupal/etags.el
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
;;; drupal/etags.el --- Drupal-mode support for etags

;; Copyright (C) 2012, 2013 Arne Jørgensen
;; Copyright (C) 2012, 2013, 2014 Arne Jørgensen

;; Author: Arne Jørgensen <[email protected]>

Expand Down Expand Up @@ -29,7 +29,7 @@

(defun drupal/etags-enable ()
"Setup TAGS file for etags if it exists."
(let ((dir (locate-dominating-file (buffer-file-name) "TAGS")))
(let ((dir (locate-dominating-file (or buffer-file-name default-directory) "TAGS")))
(when dir
(set (make-local-variable 'drupal/etags-rootdir) dir)

Expand Down
Loading

0 comments on commit da97264

Please sign in to comment.