branch: externals/phps-mode commit e083e90ac083b07ced9c9870da12f995d92388ba Author: Christian Johansson <christ...@cvj.se> Commit: Christian Johansson <christ...@cvj.se>
Passing more indentation tests for PSR-2 --- phps-mode-indent.el | 22 +++++++++++----------- test/phps-mode-test-indent.el | 4 ++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/phps-mode-indent.el b/phps-mode-indent.el index 974d871445..22759692ea 100644 --- a/phps-mode-indent.el +++ b/phps-mode-indent.el @@ -28,8 +28,8 @@ (let* ((start (- point limit)) (backward-string (replace-regexp-in-string - "[\n\t ]+" - " " + "\n" + "\r" (buffer-substring-no-properties start (1+ point))))) @@ -256,7 +256,7 @@ (string-match "^[\t ]*\\(extends\\|implements\\)" current-line-string) (when-let ((backwards-string (phps-mode-indent--backwards-looking-at - "\\([\t ]*\\)class[\t ]+[a-zA-Z0-9_]+[\t ]+\\(extends[\t ]+[a-zA-Z0-9_]+\\)?[\n\t ]*\\(implements[\t ]+[a-zA-Z0-9_]+\\)?$"))) + "\r+\\([\t ]*\\)class[\r\t ]+[a-zA-Z0-9_]+[\r\t ]+\\(extends[\r\t ]+[a-zA-Z0-9_]+\\)?[\r\t ]*\\(implements[\r\t ]+[a-zA-Z0-9_]+\\)?$"))) (let ((old-indentation (length (match-string 1 backwards-string)))) ;; TODO Need to find away to prevent this matching <?php class (message "backwards-string: %S = %S" backwards-string old-indentation) @@ -270,7 +270,7 @@ current-line-starts-with-opening-bracket (string= current-line-starts-with-opening-bracket "{") (phps-mode-indent--backwards-looking-at - "[\t ]*implements[\t ]+\\([\t ]*[a-zA-Z_0-9]+,?\\)+[\t ]*{$")) + "[\r\t ]*implements[\r\t ]+\\([\r\t ]*[\\a-zA-Z_0-9]+,?\\)+[\r\t ]*{$")) (setq new-indentation (- new-indentation tab-width))) ;; if (true) @@ -585,13 +585,13 @@ new-indentation (- new-indentation tab-width))) - (message "\ncurrent-line-string: %S" current-line-string) - ;; (message "current-line-starts-with-closing-bracket: %S" current-line-starts-with-closing-bracket) - (message "previous-line-string: %S" previous-line-string) - ;; (message "previous-line-starts-with-opening-doc-comment: %S" previous-line-starts-with-opening-doc-comment) - (message "previous-bracket-level: %S" previous-bracket-level) - (message "previous-indentation: %S" previous-indentation) - (message "new-indentation: %S" new-indentation) + ;; (message "\ncurrent-line-string: %S" current-line-string) + ;; ;; (message "current-line-starts-with-closing-bracket: %S" current-line-starts-with-closing-bracket) + ;; (message "previous-line-string: %S" previous-line-string) + ;; ;; (message "previous-line-starts-with-opening-doc-comment: %S" previous-line-starts-with-opening-doc-comment) + ;; (message "previous-bracket-level: %S" previous-bracket-level) + ;; (message "previous-indentation: %S" previous-indentation) + ;; (message "new-indentation: %S" new-indentation) ;; switch ($condition) { ;; case true: diff --git a/test/phps-mode-test-indent.el b/test/phps-mode-test-indent.el index 93b21101fd..c2bcdc3672 100644 --- a/test/phps-mode-test-indent.el +++ b/test/phps-mode-test-indent.el @@ -227,7 +227,7 @@ "Test PSR-2 examples from: https://www.php-fig.org/psr/psr-2/." (phps-mode-test-indent--should-equal - "<?php\nnamespace Vendor\\Package;\n\nuse FooInterface;\nuse BarClass as Bar;\nuse OtherVendor\\OtherPackage\\BazClass;\n\nclass Foo extends Bar implements FooInterface\n{\n public function sampleMethod($a, $b = null)\n {\n if ($a === $b) {\n bar();\n } elseif ($a > $b) {\n $foo->bar($arg1);\n } else {\n BazClass::bar($arg2, $arg3);\n }\n }\n\n final public static function bar()\n {\n // method body\n [...] + "<?php\nnamespace Vendor\\Package;\n\nuse FooInterface;\nuse BarClass as Bar;\nuse OtherVendor\\OtherPackage\\BazClass;\n\nclass Foo extends Bar implements FooInterface\n{\n public function sampleMethod($a, $b = null)\n {\n if ($a === $b) {\n bar();\n } elseif ($a > $b) {\n $foo->bar($arg1);\n } else {\n BazClass::bar($arg2, $arg3);\n }\n }\n \n final public static function bar()\n {\n // method body [...] "PSR-2 : 1.1. Example") (phps-mode-test-indent--should-equal @@ -259,7 +259,7 @@ "PSR-2 : 4.4. Method Arguments : Example 2") (phps-mode-test-indent--should-equal - "<?php\nnamespace Vendor\\Package;\n\nabstract class ClassName\n{\n protected static $foo;\n\n abstract protected function zim();\n\n final public static function bar()\n {\n // method body\n }\n}" + "<?php\nnamespace Vendor\\Package;\n\nabstract class ClassName\n{\n protected static $foo;\n \n abstract protected function zim();\n \n final public static function bar()\n {\n // method body\n }\n}" "PSR-2 ; 4.5. abstract, final, and static") (phps-mode-test-indent--should-equal