skip to Main Content

I’m using Ubuntu 20.04 and the emacs version is:

GNU Emacs 29.1 (build 2, x86_64-pc-linux-gnu, GTK+ Version 3.24.20,
cairo version 1.16.0) of 2023-08-04

as seen when I look the emacs-menu help->About Emacs

in my .emacs file this line is present:

(setq-default indent-tabs-mode nil)

which, as far as I understand, shall make the default setting of this variable (indent-tabs-mode) to be disabled, i.e. instead of inserting a tab in the code-file, it shall insert a number of spaces, four to be exact, according to this line in .emacs:

(setq-default tab-width 4)

This is what I want, and it has worked fine until recently. I suspect that it broke during some upgrade of emacs, judging from the build date of emacs it is updated recently, 2023-08-04 it seems.

Further, if I disable the variable locally in a buffer it works, but that has to be done manually in every buffer I start, tedious…

I’ve also tried moving the (setq-default indent-tabs-mode nil) to the last line in .emacs, if the variable was "implicitly overwritten" by some other directive in the .emacs file. It had no effect.

So it seems the problem is that the default setting of this variable is ignored.

Has anybody else seen this problem? Any solution? Or is it an emacs bug?

2

Answers


  1. Chosen as BEST ANSWER

    Found the problem. I had this in my .emacs :

    (add-hook 'c-mode-hook (lambda () (c-set-style "linux")))

    which adds the linux-kernel code style standard. This standard has tab and spaces as indentation, so removing it solved the problem.

    I've not changed my .emacs for several years and it has worked before. With "worked" I mean I have had only spaces as indentation. My guess is that there has been a correction made in emacs, the linux-kernel code style, that made my old .emacs incompatible with a new version of emacs, but I don't know for sure.

    Anyway it works when I remove

    (add-hook 'c-mode-hook (lambda () (c-set-style "linux")))

    so problem solved.


  2. Try the following after you’ve set the default value, to learn what’s subsequently setting it to something different.

    (defun var-debug (&rest _args)
      (debug))
    
    (add-variable-watcher 'indent-tabs-mode 'var-debug)
    
    ;; remove with:
    ;; (remove-variable-watcher 'indent-tabs-mode 'var-debug)
    

    Refer to C-hig (elisp)Debugger Commands for driving the debugger.

    If you’re not sure what to make of the information it gives you, copy and paste the backtrace into your question.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search