Skip to content

Commit f148849

Browse files
authored
Merge pull request #312 from jorissteyn/issue-310
Fix indentation after function with return type
2 parents fd2db3c + 631e840 commit f148849

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

php-mode-test.el

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,10 @@ style from Drupal."
612612
(php-mode)
613613
(should-not (buffer-modified-p))))
614614

615+
(ert-deftest php-mode-test-issue-310 ()
616+
"Proper indentation after function with return type."
617+
(with-php-mode-test ("issue-310.php" :indent t :magic t)))
618+
615619
;;; php-mode-test.el ends here
616620

617621
;; Local Variables:

php-mode.el

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,23 @@
9393
(if (and (= emacs-major-version 24) (>= emacs-minor-version 4))
9494
(require 'cl)))
9595

96+
;; Work around https://github.com/ejmr/php-mode/issues/310.
97+
;;
98+
;; In emacs 24.4 and 24.5, lines after functions with a return type
99+
;; are incorrectly analyzed as member-init-cont.
100+
;;
101+
;; Before emacs 24.4, c member initializers are not supported this
102+
;; way. Starting from emacs 25.1, cc-mode only detects member
103+
;; initializers when the major mode is c++-mode.
104+
(eval-and-compile
105+
(if (and (= emacs-major-version 24) (or (= emacs-minor-version 4)
106+
(= emacs-minor-version 5)))
107+
(defun c-back-over-member-initializers ()
108+
;; Override of cc-engine.el, cc-mode in emacs 24.4 and 24.5 are too
109+
;; optimistic in recognizing c member initializers. Since we don't
110+
;; need it in php-mode, just return nil.
111+
nil)))
112+
96113

97114
;; Local variables
98115
;;;###autoload

tests/issue-310.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
3+
function a() : string {
4+
return 'world';
5+
}
6+
echo 'hello'; // ###php-mode-test### ((indent 0))

0 commit comments

Comments
 (0)