1

I want web-mode-script-padding to be set to 0 at all times.

In my config, I have tried both

(with-eval-after-load 'web-mode
 (setq web-mode-script-padding 0)
 )

As well as simply,

(setq web-mode-script-padding 0)

If I open a new window, and then a webmode file, the behavior of pressing TAB and other things indicates that the value is not set how I want it to be (this after reset so my new config is reloaded). So, I do M-x describe-variable web-mode-script-padding. I see:

web-mode-script-padding is a variable defined in ‘web-mode.el’.
Its value is 2
Original value was 1
Local in buffer Navbar.vue; global value is 0

This is not what I want. I want the value to be 0.

So I do M-x set-variable web-mode-script-padding 0 in that buffer. Now, describe-variable shows

web-mode-script-padding is a variable defined in ‘web-mode.el’.
Its value is 0
Original value was 1
Local in buffer CardList.vue; global value is the same.

Furthermore, in this buffer, the script-padding behaves as I want.

However, opening a new buffer means I have to manually set-variable again to maintain this behavior.

How can I either set-variable so it applies to the entire frame, or get my setq in my config to "stick?"

Edit: In case this was a buffer-local variable, I tried setq-default, still not getting the desired behavior though.

Caleb Jay
  • 239
  • 2
  • 12
  • Does this answer your question? [Advantages of setting variables with setq instead of custom.el?](https://emacs.stackexchange.com/questions/102/advantages-of-setting-variables-with-setq-instead-of-custom-el) – Drew Jul 15 '20 at 17:59
  • testing now to see – Caleb Jay Jul 15 '20 at 18:20
  • Yea, I dunno, setting through custom doesn't work either. I've got spacemacs so I'm checking to make sure there isn't some override - custom is adding to the already existent custom-set-variables in .spacemacs at least. – Caleb Jay Jul 15 '20 at 18:25
  • this may be an issue with spacemacs loading custom set variables too early https://github.com/syl20bnr/spacemacs/issues/7970 I'll update as I explore further – Caleb Jay Jul 15 '20 at 18:27
  • If it turns out to be Spacemacs related, please add the `spacemacs` tab. Thx. – Drew Jul 15 '20 at 19:25
  • I'm seeing this in my messages, wonder if it's related? `Local variables list is not properly terminated [2 times]` – Caleb Jay Jul 15 '20 at 19:43
  • Also, weirdly, outside of web mode describe-variable correctly describes it as 0. In web mode buffers there's a line about "local to buffer," where it's incorrect. Is there a way for settings to "stick" to buffers even if I reset emacs? I checked to make sure there were no .editorconfig shenanigans. EDIT: Nope, there were editorconfig shenanigans. – Caleb Jay Jul 15 '20 at 19:46
  • 1
    There is no way to `setq` a variable such that it clobbers any buffer-local values that might exist for that same variable. You *either* set the global value, or (when in a buffer with a local value) set the current buffer's local value. The point of buffer-local variables is so that you *can* override the global value. – phils Jul 15 '20 at 20:38
  • In your case, I would expect that *everything* that editorconfig sets will be buffer-local -- its purpose is make buffers under its control behave the way it wants, regardless of how any other buffers behave. *Normally* an `.editorconfig` file would indicate established coding standards for a project, so make sure that removing the setting is actually the correct thing to do! – phils Jul 15 '20 at 20:39
  • @phils you're not wrong with anything your saying! It's just unexpected behavior, particularly as it relates to a .vue file. In this case, I expect that vscode or something treats what it sees in that .editorconfig differently than emacs. The .editorconfig, I found out, was simply the default one provided by vue-cli when doing `vue create someapp`. However, when web-mode auto-aligns with that .editorconfig setting, it triggers the linter, that also comes default with `vue-cli`! Something, somewhere, is wrong. – Caleb Jay Jul 16 '20 at 02:09

3 Answers3

0

The description of the variable (C-hv) also mentions:

You can customize this variable.

Click on "customize", fill in the value and click "Apply and Save".

This will add the line

 '(web-mode-script-padding 0)

into the

(custom-set-variables

list, or create it, if it didn't exist.

choroba
  • 1,925
  • 10
  • 16
  • I confirm that this did add to `custom-set-variables` exactly as you described, however, the result is identical to when I tried to `setq`. That is to say, in new buffers, it says it's value is 2, while the global value is 0. This after restarting emacs. – Caleb Jay Jul 15 '20 at 17:48
  • It works for me. What version of Emacs and web-mode do you use? – choroba Jul 15 '20 at 17:51
  • GNU Emacs 26.3 (build 2, x86_64-pc-linux-gnu, GTK+ Version 3.22.30) of 2019-09-16 web-mode-version is a variable defined in ‘web-mode.el’. Its value is "16.0.29" – Caleb Jay Jul 15 '20 at 18:21
0

As @choroba has pointed out, this is apparently a user option (aka a customize variable).

As a general rule, do not use setq or setq-default to set the value of a user option. This answer explains why.

(I'm guessing this question seems to be about this problem, so I'm voting to close it as essentially a duplicate of that other question. If I'm mistaken, then this answer might help.)

Drew
  • 75,699
  • 9
  • 109
  • 225
  • testing now to see – Caleb Jay Jul 15 '20 at 18:20
  • I've confirmed that `custom-file` is pointing to an existent file with a `custom-set-variables` list that contains the expected `'(web-mode-script-padding 0)` – Caleb Jay Jul 15 '20 at 18:30
  • Is your `custom-file` actually loaded - do you load it in your init file, for example? If so, does something else later change the value? You can perhaps bisect your init file to find out the latter (use `comment-region` for that). – Drew Jul 15 '20 at 19:27
  • It appears to be loaded, based on spacemacs code, but is there any way to confirm that? Also, how would bisecting my init file tell me if something is changing the value later? I searched through the file for any other mentions of web-mode-script-padding, but I'm happy to try anything! I recursively grepped my entire .emacs.d and didn't see anything anywhere setting web-mode-script padding to anything other than 0. So weird. – Caleb Jay Jul 15 '20 at 19:31
  • 1
    You can tell whether your `custom-file` gets loaded by looking at the value of its options or faces. The init-file bisecting is to help you narrow down to the part of the file that causes the problem. Presumably, it's somewhere in the part after your init file loads your `custom-file`. – Drew Jul 15 '20 at 23:34
0

In file .editorconfig, someone had put this:

indent_size = 2

For some reason, this overwrote the web-mode-script-padding value locally to this project.

I removed that line, and it worked as expected.

Drew
  • 75,699
  • 9
  • 109
  • 225
Caleb Jay
  • 239
  • 2
  • 12