Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore '=' or '.' if it is inside string or comment #229

Merged
merged 3 commits into from
Mar 4, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
}