Json buffers don't seem to respect (set-variable 'tab-width 2) reddit / emacs ---------------------------------------------------------------------- TomSwirly · 2022-11-10 12:36 Long-time emacs user here. I need to occasionally edit Jason buffers indented with 2 spaces, when my default indentation is 4. However, incanting `(set-variable 'tab-width 2)` in such a JSON buffer has, to my surprise, no effect. `M-x describe-variable` says: tab-width is a variable defined in ‘C source code’. Its value is 2 Original value was 8 Local in buffer summary-fields.json; global value is 4 exactly as expected, but hitting tab, or even comma :-/ consistently aligns me with 4 space tabs, which is getting me down. `C-h m` gives me the mode: JavaScript mode defined in ‘js.el’: Major mode for editing JavaScript. which also seems as expected. I'm running Aquamacs 3.6 GNU Emacs 25.3.50.1 Thanks for any ideas or tips. ---------------------------------------------------------------------- globalcandyamnesia · 2022-11-10 15:47 Ugh tab size variables are so inconsistent in Emacs. I believe what you're looking for is `js-indent-level`, but for any given mode it can be MODE-indent-offset, MODE-basic-indent, MODE-basic-offset or who knows what else. ---------------------------------------------------------------------- Alan_Shutko · 2022-11-10 15:49 You want to set `js-indent-level`. `tab-width` controls how wide a TAB character (in the file) is displayed on screen. ---------------------------------------------------------------------- Pinsl · 2022-11-10 20:09 I have this in my config: (defvaralias 'c-basic-offset 'tab-width) (defvaralias 'cperl-indent-level 'tab-width) (defvaralias 'js-indent-level 'tab-width) ---------------------------------------------------------------------- YakumoYoukai · 2022-11-10 21:42 Uggh yeah, It took me too long to figure out this variable. I hoped it would just piggyback off of the C mode indentation logic, particularly the ability to guess the indent size from the contents. ---------------------------------------------------------------------- TomSwirly · 2022-11-11 10:21 Dagnabbit! Right, I even knew that about `tab-width` and forgot. ---------------------------------------------------------------------- TomSwirly · 2022-11-11 10:23 Just added this. ---------------------------------------------------------------------- TomSwirly · 2022-11-11 10:23 That seems to be right. Upvotes all round!