branch: externals/phps-mode commit c625217d81227b31c09cf37fd34758f9c402163b Author: Christian Johansson <christ...@cvj.se> Commit: Christian Johansson <christ...@cvj.se>
Added flag for PSR-2 white-space settings --- phps-functions.el | 18 ++++++++++++++---- phps-mode.el | 3 +++ phps-syntax-table.el | 10 ++++++---- phps-test-functions.el | 3 --- 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/phps-functions.el b/phps-functions.el index cc2bc7a..9c67d3a 100644 --- a/phps-functions.el +++ b/phps-functions.el @@ -47,8 +47,8 @@ ;; Are we in scripting? (if in-scripting - (let* ((indent-start (* (+ (nth 1 start) (nth 2 start)) 4)) - (indent-end (* (+ (nth 1 end) (nth 2 end)) 4)) + (let* ((indent-start (* (+ (nth 1 start) (nth 2 start)) tab-width)) + (indent-end (* (+ (nth 1 end) (nth 2 end)) tab-width)) (indent-diff 0)) (when (and (> indent-start indent-end) (looking-at-p "^[][ \t)(}{};]+\\($\\|?>\\)")) @@ -57,7 +57,7 @@ (message "inside scripting, start: %s, end: %s, indenting to column %s " start end indent-level) (indent-line-to indent-level)) (progn - (message "Outside scripting %s" start) + ;; (message "Outside scripting %s" start) ;; (indent-relative) )))))) @@ -69,7 +69,17 @@ "PHP specific init-cleanup routines." (set (make-local-variable 'indent-line-function) #'phps-mode/indent-line) - (set (make-local-variable 'tab-width) 8) + + (when phps-mode/use-psr-2 + + ;; PSR-2 : Code MUST use an indent of 4 spaces + (set (make-local-variable 'tab-width) 4) + + ;; PSR-2 : MUST NOT use tabs for indenting + (set (make-local-variable 'indent-tabs-mode) nil) + + ) + ;; (set (make-local-variable 'indent-line-function) #'phps-mode/indent-region) ) diff --git a/phps-mode.el b/phps-mode.el index 65542f7..0d5c19d 100644 --- a/phps-mode.el +++ b/phps-mode.el @@ -57,6 +57,9 @@ (autoload 'phps-mode/tags-init "phps-tags") (autoload 'phps-mode/semantic-init "phps-semantic") +(defvar phps-mode/use-psr-2 t + "Whether to use PSR-2 guidelines for white-space or not.") + (define-derived-mode phps-mode prog-mode "PHPs" "Major mode for PHP with Semantic integration." diff --git a/phps-syntax-table.el b/phps-syntax-table.el index 6cbdecd..b482143 100644 --- a/phps-syntax-table.el +++ b/phps-syntax-table.el @@ -43,12 +43,14 @@ (let ((phps-mode/syntax-table (make-syntax-table))) ;; This is added so entity names with underscores can be more easily parsed as one word - (modify-syntax-entry ?_ "w" phps-mode/syntax-table) + + ;; Treat underscore as a punctuation + (modify-syntax-entry ?_ "." phps-mode/syntax-table) ;; Improve parsing of <?php and ?> as words - (modify-syntax-entry ?? "w" phps-mode/syntax-table) - (modify-syntax-entry ?< "w" phps-mode/syntax-table) - (modify-syntax-entry ?> "w" phps-mode/syntax-table) + ;;(modify-syntax-entry ?? "w" phps-mode/syntax-table) + ;;(modify-syntax-entry ?< "w" phps-mode/syntax-table) + ;;(modify-syntax-entry ?> "w" phps-mode/syntax-table) ;; (modify-syntax-entry ?_ "w" phps-mode/syntax-table) diff --git a/phps-test-functions.el b/phps-test-functions.el index 3f6543e..003ea4d 100644 --- a/phps-test-functions.el +++ b/phps-test-functions.el @@ -99,9 +99,6 @@ (defun phps-mod/test-functions () "Run test for functions." - (setq-default indent-tabs-mode nil) - (setq-default tab-width 4) - (setq-default c-basic-indent 4) (phps-mode/test-indentation)) (phps-mod/test-functions)