Skip to content

Commit a5fd4b5

Browse files
author
Eric James Michael Ritz
committed
Fix indentation error involving magic constants
Consider the following code from the test case in this patch: $x = some_function(__FILE__) . ''; $broken = true; PHP Mode will indent the second line far to the right, aligning the start of the line with the concatenation operator from the line above it. CC Mode (which handles our indentation) indents the second line according to the settings for `knr-argdecl'. None of the indentation styles we provide give any value to this. This patch modifies all of the PHP Mode indentation styles so that `knr-argdecl' has the value of a vector with one element: the number zero. This tells Emacs to always position the line in the first column so that we get the actual indentation in the example above. This approach is not bullet-proof. If we write the same two lines of code inside of a function then CC Mode indents the second line using something besides `knr-argdecl'. However, that does not mean there are not other situations where it may meaningfully use `knr-argdecl' in a situation where we do not want to start a line in the first column of the screen. This patch fixes the specific problem of the bug report referenced below, but there may still be corner-cases where indentation surrounding magic constants unexpectedly breaks. GitHub-Issue: 102
1 parent 429e0a6 commit a5fd4b5

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

php-mode.el

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ This variable can take one of the following symbol values:
305305
(brace-list-entry . c-lineup-cascaded-calls)
306306
(arglist-close . php-lineup-arglist-close)
307307
(arglist-intro . php-lineup-arglist-intro)
308+
(knr-argdecl . [0])
308309
(statement-cont . (first c-lineup-cascaded-calls +))))))
309310

310311
(defun php-enable-pear-coding-style ()
@@ -325,6 +326,7 @@ code and modules."
325326
(arglist-close . php-lineup-arglist-close)
326327
(arglist-intro . php-lineup-arglist-intro)
327328
(arglist-cont-nonempty . c-lineup-math)
329+
(knr-argdecl . [0])
328330
(statement-cont . (first c-lineup-cascaded-calls +))))))
329331

330332
(defun php-enable-drupal-coding-style ()
@@ -351,6 +353,7 @@ working with Drupal."
351353
(arglist-close . 0)
352354
(defun-close . 0)
353355
(defun-block-intro . +)
356+
(knr-argdecl . [0])
354357
(statement-cont . (first c-lineup-cascaded-calls +))))))
355358

356359
(defun php-enable-wordpress-coding-style ()
@@ -376,6 +379,7 @@ working with Wordpress."
376379
(statement-case-intro . 4)
377380
(defun-close . 0)
378381
(defun-block-intro . +)
382+
(knr-argdecl . [0])
379383
(statement-cont . php-lineup-hanging-semicolon)))))
380384

381385
(defun php-enable-symfony2-coding-style ()

tests/issue-102.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
*/
1515

1616
$x = some_function(__FILE__) . '';
17-
$broken = true;
17+
$broken = true;
1818

1919
some_function(__FILE__) . '';
20-
$broken = true;
20+
$broken = true;
2121

2222
some_function(__FILE__) + 1;
23-
$broken = true;
23+
$broken = true;

0 commit comments

Comments
 (0)