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.

10
  • Does this answer your question? Advantages of setting variables with setq instead of custom.el?
    – Drew
    Jul 15, 2020 at 17:59
  • testing now to see
    – Caleb Jay
    Jul 15, 2020 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, 2020 at 18:25
  • this may be an issue with spacemacs loading custom set variables too early github.com/syl20bnr/spacemacs/issues/7970 I'll update as I explore further
    – Caleb Jay
    Jul 15, 2020 at 18:27
  • 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, 2020 at 20:38

3 Answers 3

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.

3
  • 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, 2020 at 17:48
  • It works for me. What version of Emacs and web-mode do you use?
    – choroba
    Jul 15, 2020 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, 2020 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.)

5
  • testing now to see
    – Caleb Jay
    Jul 15, 2020 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, 2020 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, 2020 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, 2020 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, 2020 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.