branch: externals/phps-mode commit 07d9176757f7722f6543f954d50958f05e7af871 Author: Christian Johansson <christ...@cvj.se> Commit: Christian Johansson <christ...@cvj.se>
Improved flycheck support --- Makefile | 2 +- phps-mode-flycheck.el | 70 +++++---------------------------------------------- phps-mode.el | 6 +---- 3 files changed, 8 insertions(+), 70 deletions(-) diff --git a/Makefile b/Makefile index 8cedd5f..05a2472 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ ifdef emacs endif EMACS_CMD := $(EMACS) -Q -batch -L . -EL := phps-mode-flymake.el phps-mode-font-lock.el phps-mode-functions.el phps-mode-lexer.el phps-mode-map.el phps-mode-semantic.el phps-mode-syntax-table.el phps-mode-test.el phps-mode-test-functions.el phps-mode-test-integration.el phps-mode-test-lexer.el phps-mode-test-parser.el phps-mode-test-syntax-table.el phps-mode.el +EL := phps-mode-flycheck.el phps-mode-flymake.el phps-mode-font-lock.el phps-mode-functions.el phps-mode-lexer.el phps-mode-map.el phps-mode-semantic.el phps-mode-syntax-table.el phps-mode-test.el phps-mode-test-functions.el phps-mode-test-integration.el phps-mode-test-lexer.el phps-mode-test-parser.el phps-mode-test-syntax-table.el phps-mode.el ELC := $(EL:.el=.elc) .PHONY: clean diff --git a/phps-mode-flycheck.el b/phps-mode-flycheck.el index c2a0965..315ad23 100644 --- a/phps-mode-flycheck.el +++ b/phps-mode-flycheck.el @@ -28,72 +28,14 @@ ;;; Code: -(require 'flycheck) (defun phps-mode-flycheck-init () - "Add flycheck support for PHP Semantic mode." - - ;; Is flycheck available? - (when (fboundp 'flycheck-define-checker) - - ;; Add PHP checker - (flycheck-define-checker php - "A PHP syntax checker using the PHP command line interpreter. - -See URL `http://php.net/manual/en/features.commandline.php'." - :command ("php" "-l" "-d" "error_reporting=E_ALL" "-d" "display_errors=1" - "-d" "log_errors=0" source) - :error-patterns - ((error line-start (or "Parse" "Fatal" "syntax") " error" (any ":" ",") " " - (message) " in " (file-name) " on line " line line-end)) - :modes (phps-mode) - :next-checkers ((warning . php-phpmd) - (warning . php-phpcs))) - - ;; Add PHP Mess Detector checker - (flycheck-define-checker php-phpmd - "A PHP style checker using PHP Mess Detector. - -See URL `https://phpmd.org/'." - :command ("phpmd" source "xml" - (eval (flycheck-option-comma-separated-list - flycheck-phpmd-rulesets))) - :error-parser flycheck-parse-phpmd - :modes (phps-mode) - :next-checkers ((warning . php-phpcs))) - - ;; Add PHP Code Sniffer checker - (flycheck-define-checker php-phpcs - "A PHP style checker using PHP Code Sniffer. - -Needs PHP Code Sniffer 2.6 or newer. - -See URL `http://pear.php.net/package/PHP_CodeSniffer/'." - :command ("phpcs" "--report=checkstyle" - ;; Use -q flag to force quiet mode - ;; Quiet mode prevents errors from extra output when phpcs has - ;; been configured with show_progress enabled - "-q" - (option "--standard=" flycheck-phpcs-standard concat) - ;; Pass original file name to phpcs. We need to concat explicitly - ;; here, because phpcs really insists to get option and argument as - ;; a single command line argument :| - (eval (when (buffer-file-name) - (concat "--stdin-path=" (buffer-file-name)))) - ;; Read from standard input - "-") - :standard-input t - :error-parser flycheck-parse-checkstyle - :error-filter - (lambda (errors) - (flycheck-sanitize-errors - (flycheck-remove-error-file-names "STDIN" errors))) - :modes (php-mode php+-mode phps-mode) - ;; phpcs seems to choke on empty standard input, hence skip phpcs if the - ;; buffer is empty, see https://github.com/flycheck/flycheck/issues/907 - :predicate (lambda () (not (flycheck-buffer-empty-p)))) - - )) + "Add flycheck support for phps-mode." + + (when (fboundp 'flycheck-add-mode) + (flycheck-add-mode 'php 'phps-mode) + (flycheck-add-mode 'php-phpmd 'phps-mode) + (flycheck-add-mode 'php-phpcs 'phps-mode))) (provide 'phps-mode-flycheck) diff --git a/phps-mode.el b/phps-mode.el index ddd08ac..adfd681 100644 --- a/phps-mode.el +++ b/phps-mode.el @@ -58,9 +58,6 @@ (defvar phps-mode-idle-interval 1.0 "Idle seconds before running incremental lexer.") -(defvar phps-mode-flycheck-support nil - "Boolean whether flycheck support should be enabled or not.") - (define-derived-mode phps-mode prog-mode "PHPs" "Major mode for PHP with Semantic integration." @@ -77,8 +74,7 @@ ;; (phps-mode-flymake-init) ;; Flycheck - (when phps-mode-flycheck-support - (phps-mode-flycheck-init)) + (phps-mode-flycheck-init) ;; Override functions (phps-mode-functions-init)