Skip to content

Commit

Permalink
Merge pull request #229 from ejmr/issue-227
Browse files Browse the repository at this point in the history
Ignore '=' or '.' if it is inside string or comment
  • Loading branch information
syohex committed Mar 4, 2015
2 parents e46c80f + 320eb00 commit 7e5d35d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
5 changes: 5 additions & 0 deletions php-mode-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -551,4 +551,9 @@ style from Drupal."
(search-forward "return")
(should (eq (current-indentation) (* 2 c-basic-offset)))))

(ert-deftest php-mode-test-issue-227 ()
"multi-line strings indents "
(custom-set-variables '(php-lineup-cascaded-calls t))
(with-php-mode-test ("issue-227.php" :indent t :style pear)))

;;; php-mode-test.el ends here
26 changes: 16 additions & 10 deletions php-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
(defconst php-mode-version-number "1.15.3"
"PHP Mode version number.")

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

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

(defsubst php-in-string-p ()
(nth 3 (syntax-ppss)))

(defsubst php-in-comment-p ()
(nth 4 (syntax-ppss)))

(defsubst php-in-string-or-comment-p ()
(nth 8 (syntax-ppss)))

(defun php-lineup-string-cont (langelem)
"Line up string toward equal sign or dot
e.g.
Expand All @@ -876,9 +885,12 @@ $str = 'some'
this ^ lineup"
(save-excursion
(goto-char (cdr langelem))
(when (or (search-forward "=" (line-end-position) t)
(search-forward "." (line-end-position) t))
(vector (1- (current-column))))))
(let (ret finish)
(while (and (not finish) (re-search-forward "[=.]" (line-end-position) t))
(unless (php-in-string-or-comment-p)
(setq finish t
ret (vector (1- (current-column))))))
ret)))

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

(defsubst php-in-string-p ()
(nth 3 (syntax-ppss)))

(defsubst php-in-comment-p ()
(nth 4 (syntax-ppss)))

(defun php-syntax-propertize-function (start end)
"Apply propertize rules from START to END."
;; (defconst php-syntax-propertize-function
Expand Down
12 changes: 12 additions & 0 deletions tests/issue-227.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

/**
* GitHub Issue: https://github.com/ejmr/php-mode/issues/227
*
* Indentation of multi-line strings
*/

function my_func() {
return "a really long string with = inside " .
"some more text"; // ###php-mode-test### ((indent 49))
}

0 comments on commit 7e5d35d

Please sign in to comment.