Skip to content

Commit 7e5d35d

Browse files
committed
Merge pull request #229 from ejmr/issue-227
Ignore '=' or '.' if it is inside string or comment
2 parents e46c80f + 320eb00 commit 7e5d35d

File tree

3 files changed

+33
-10
lines changed

3 files changed

+33
-10
lines changed

php-mode-test.el

+5
Original file line numberDiff line numberDiff line change
@@ -551,4 +551,9 @@ style from Drupal."
551551
(search-forward "return")
552552
(should (eq (current-indentation) (* 2 c-basic-offset)))))
553553

554+
(ert-deftest php-mode-test-issue-227 ()
555+
"multi-line strings indents "
556+
(custom-set-variables '(php-lineup-cascaded-calls t))
557+
(with-php-mode-test ("issue-227.php" :indent t :style pear)))
558+
554559
;;; php-mode-test.el ends here

php-mode.el

+16-10
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
(defconst php-mode-version-number "1.15.3"
1212
"PHP Mode version number.")
1313

14-
(defconst php-mode-modified "2015-02-16"
14+
(defconst php-mode-modified "2015-03-04"
1515
"PHP Mode build date.")
1616

1717
;;; License
@@ -868,6 +868,15 @@ This is was done due to the problem reported here:
868868
"See `php-c-at-vsemi-p'."
869869
)
870870

871+
(defsubst php-in-string-p ()
872+
(nth 3 (syntax-ppss)))
873+
874+
(defsubst php-in-comment-p ()
875+
(nth 4 (syntax-ppss)))
876+
877+
(defsubst php-in-string-or-comment-p ()
878+
(nth 8 (syntax-ppss)))
879+
871880
(defun php-lineup-string-cont (langelem)
872881
"Line up string toward equal sign or dot
873882
e.g.
@@ -876,9 +885,12 @@ $str = 'some'
876885
this ^ lineup"
877886
(save-excursion
878887
(goto-char (cdr langelem))
879-
(when (or (search-forward "=" (line-end-position) t)
880-
(search-forward "." (line-end-position) t))
881-
(vector (1- (current-column))))))
888+
(let (ret finish)
889+
(while (and (not finish) (re-search-forward "[=.]" (line-end-position) t))
890+
(unless (php-in-string-or-comment-p)
891+
(setq finish t
892+
ret (vector (1- (current-column))))))
893+
ret)))
882894

883895
(defun php-lineup-arglist-intro (langelem)
884896
(save-excursion
@@ -911,12 +923,6 @@ the string HEREDOC-START."
911923
(string-match "\\w+" heredoc-start)
912924
(concat "^\\(" (match-string 0 heredoc-start) "\\)\\W"))
913925

914-
(defsubst php-in-string-p ()
915-
(nth 3 (syntax-ppss)))
916-
917-
(defsubst php-in-comment-p ()
918-
(nth 4 (syntax-ppss)))
919-
920926
(defun php-syntax-propertize-function (start end)
921927
"Apply propertize rules from START to END."
922928
;; (defconst php-syntax-propertize-function

tests/issue-227.php

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
/**
4+
* GitHub Issue: https://github.com/ejmr/php-mode/issues/227
5+
*
6+
* Indentation of multi-line strings
7+
*/
8+
9+
function my_func() {
10+
return "a really long string with = inside " .
11+
"some more text"; // ###php-mode-test### ((indent 49))
12+
}

0 commit comments

Comments
 (0)