fxbois / web-mode

web template editing mode for emacs
https://web-mode.org
GNU General Public License v3.0
1.63k stars 262 forks source link

PHP array indents #1249

Closed ezicheq closed 2 years ago

ezicheq commented 2 years ago

web-mode is creating this odd indentation (I'm using tabs not spaces):

<?php

$array = [
    'apple',
        'banana',
        'carrot'
];

It also happens with parameters in function calls, or using "array(" and ")" instead of "[" and "]"

ezicheq commented 2 years ago

I just discovered this only happens with (web-mode-use-tabs). If I use (setq indent-tabs-mode t) and dont set the former, it works fine. I'll leave this open in case web-mode-use-tabs is meant to do otherwise. Close if you wish as my issue is now resolved.

fxbois commented 2 years ago

I do not really use tabs. If it now works for you, I close this issue

jasalt commented 1 year ago

Having this issue still when using tabs with package version 20230329.601 (17.3.9) when using (web-mode-use-tabs). Array indentation behaves better when using only (setq indent-tabs-mode t) as noted by ezicheq.

The documentation on web-mode.org is bit confusing on this stating "Moreover you might need to call (web-mode-use-tabs) in your web-mode hook." which leads into having this problem. Looked at the function but couldn't comprehend yet what gets missed if it's skipped.

Related https://github.com/fxbois/web-mode/issues/1268.

EDIT: seems that using only (setq indent-tabs-mode t) ends up indenting php-only files wrong. For example's sake using 4 spaces here as tab:

<?php
    $env = include(plugin_dir_path(__FILE__) . 'env.php');
    // and so on, whole script indented by one tab after the starting <?php tag

While correct would be:

<?php
$env = include(plugin_dir_path(__FILE__) . 'env.php');
// and so on...

This is fixed by also setting (setq web-mode-block-padding 0).

jasalt commented 1 year ago

I had trouble getting the (setq web-mode-block-padding 0) to stick using a hook and found that editorconfig was resetting the value back to 4 as file local variable. I'm running Emacs with Prelude config pack that enables editorconfig by default and didn't come to think of this.

Related issue was https://github.com/fxbois/web-mode/issues/695 with workaround mentioned in editorconfig repo https://github.com/editorconfig/editorconfig-emacs/issues/79#issuecomment-200639230.