Set 4 Space Indent in Emacs in Text Mode

后端 未结 20 2312
梦谈多话
梦谈多话 2020-11-29 15:27

I\'ve been unsuccessful in getting Emacs to switch from 8 space tabs to 4 space tabs when pressing the TAB in buffers with the major mode text-mode.

20条回答
  •  时光说笑
    2020-11-29 15:53

    Update: Since Emacs 24.4:

    tab-stop-list is now implicitly extended to infinity. Its default value is changed to nil which means a tab stop every tab-width columns.

    which means that there's no longer any need to be setting tab-stop-list in the way shown below, as you can keep it set to nil.

    Original answer follows...


    It always pains me slightly seeing things like (setq tab-stop-list 4 8 12 ................) when the number-sequence function is sitting there waiting to be used.

    (setq tab-stop-list (number-sequence 4 200 4))
    

    or

    (defun my-generate-tab-stops (&optional width max)
      "Return a sequence suitable for `tab-stop-list'."
      (let* ((max-column (or max 200))
             (tab-width (or width tab-width))
             (count (/ max-column tab-width)))
        (number-sequence tab-width (* tab-width count) tab-width)))
    
    (setq tab-width 4)
    (setq tab-stop-list (my-generate-tab-stops))
    

提交回复
热议问题