Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
5eb72ab
Merge branch 'release/0.3.1' into develop
arnested Nov 24, 2013
557f34c
Fixed tar on Mac OS X.
arnested Nov 27, 2013
0a9d8df
Cleaned whitespace.
arnested Nov 27, 2013
4e4714f
...
arnested Nov 27, 2013
493acf4
Redone building `drupal-mode-map`.
arnested Nov 27, 2013
0eac307
Don't delete `'trailing` form `whitespace-style` after all.
arnested Nov 27, 2013
31c2b67
Added Api.drupalize.me as `drupal-search-url` option.
arnested Dec 9, 2013
3c32d7e
`flycheck-declare-checker` is now `flycheck-define-checker`
spaceotter Jan 1, 2014
46ad71d
Used `default-directory` as fallback if `buffer-file-name` us not set.
arnested Jan 3, 2014
2b71509
Used `(buffer-name)` as fallback if `buffer-file-name` us not set.
arnested Jan 3, 2014
6bb266b
Fixed typo in latest commit.
arnested Jan 3, 2014
3cf6d3a
Updated phpcs patterns to new flycheck format.
xendk Jan 3, 2014
72ceba6
Merge pull request #39 from xendk/develop
arnested Jan 3, 2014
be281df
Added info modes. Drupal Coder Sniffer understands info files as well.
arnested Jan 11, 2014
430b045
Added special case for .tpl.php extensions.
arnested Jan 11, 2014
5ac9531
Added default to run flymake in place.
arnested Jan 11, 2014
a4768c7
Fixed namespace of custom variable.
arnested Jan 11, 2014
a25b4df
Cope with different implementations of flymake-phpcs.
arnested Jan 11, 2014
b2ba37e
Bumped version to 0.4.0.
arnested Jan 12, 2014
f1985b5
Merge branch 'release/0.4.0'
arnested Jan 12, 2014
9b091a3
Merge tag '0.4.0' into develop
arnested Jan 12, 2014
3bb1e40
Silence byte compiler.
arnested Jan 13, 2014
b929895
Added own implementation of flymake init and temp names.
arnested Jan 13, 2014
230e579
Removed flymake-phpcs from `drush-make-mode' files.
arnested Jan 16, 2014
8860570
Removed usage of directory local variables.
arnested Jan 27, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
94 changes: 61 additions & 33 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 <arne@arnested.dk>
;; URL: https://github.com/arnested/drupal-mode
;; Created: January 17, 2012
;; Version: 0.3.1
;; Version: 0.4.0
;; 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 @@ -188,14 +189,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 @@ -538,23 +548,26 @@ 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"))
Expand All @@ -567,11 +580,11 @@ the location of DRUPAL_ROOT."
(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))
(setq drupal-version (match-string-no-properties 2))
(puthash 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)
Expand Down Expand Up @@ -601,16 +614,31 @@ the location of DRUPAL_ROOT."
(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)
(puthash (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 (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 +694,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 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 <arne@arnested.dk>
;; 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 <arne@arnested.dk>

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
25 changes: 16 additions & 9 deletions drupal/flycheck.el
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
;;; drupal/flycheck.el --- Drupal-mode support for flycheck and phpcs

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

;; Author: Thomas Fini Hansen <xen@xen.dk>

Expand All @@ -25,6 +25,7 @@

;;; Code:

(require 'flycheck)
(require 'drupal/phpcs)

(defcustom drupal/flycheck-phpcs-js-and-css t
Expand All @@ -44,31 +45,37 @@

;; Flycheck will also highlight trailing whitespace as an
;; error so no need to highlight it twice.
(drupal/phpcs-dont-show-trailing-whitespace)))
(when (fboundp 'drupal/phpcs-dont-show-trailing-whitespace)
(drupal/phpcs-dont-show-trailing-whitespace))))

(add-hook 'drupal-mode-hook #'drupal/flycheck-hook)

(flycheck-declare-checker css-js-phpcs
(flycheck-define-checker css-js-phpcs
"Check CSS and JavaScript using PHP_CodeSniffer.

PHP_CodeSniffer can be used to check non-PHP files, as exemplified by the
Drupal code sniffer.

See URL `http://pear.php.net/package/PHP_CodeSniffer/'."
:command '("phpcs" "--report=emacs"
(option "--standard=" flycheck-phpcs-standard)
source)
:command ("phpcs" "--report=emacs"
(option "--standard=" flycheck-phpcs-standard)
source)
;; Though phpcs supports Checkstyle output which we could feed to
;; `flycheck-parse-checkstyle', we are still using error patterns here,
;; because PHP has notoriously unstable output habits. See URL
;; `https://github.com/lunaryorn/flycheck/issues/78' and URL
;; `https://github.com/lunaryorn/flycheck/issues/118'
:error-patterns
'(("\\(?1:.*\\):\\(?2:[0-9]+\\):\\(?3:[0-9]+\\): error - \\(?4:.*\\)" error)
("\\(?1:.*\\):\\(?2:[0-9]+\\):\\(?3:[0-9]+\\): warning - \\(?4:.*\\)" warning))
:modes '(css-mode js-mode)
((error line-start
(file-name) ":" line ":" column ": error - " (message)
line-end)
(warning line-start
(file-name) ":" line ":" column ": warning - " (message)
line-end))
:modes (css-mode js-mode)
:predicate (lambda ()
(and drupal/flycheck-phpcs-js-and-css (apply 'derived-mode-p (append drupal-php-modes drupal-css-modes drupal-js-modes)))))

(add-to-list 'flycheck-checkers 'css-js-phpcs)


Expand Down
Loading