0

I need some help getting custom indentation behavior with my .emacs config.

In emacs text-mode / Fundamental Mode, by default a tab will take me to the location of the top line's next word (non whitespace char) :

reallylongword nextword
<TAB>----------^

whereas in 90% of cases, I'd like to do:

reallylongword nextword
--^

There are two possible ways I believe can achieve this:

1 - Automatically going to minor mode "outline-mode" whenever custom extension ".plain" opened, or using some other improvement on Fundamental Mode.

2 - Keybind TAB to be fixed to 2 spaces while in text-mode -- or make this feature a default, but toggleable.

I've looked at the following links for reference already but after trying suggested fixes, I need some help detecting problems in my config. Indents work how I like for Python / C++, etc, just not plaintext. Lots of effort just to avoid [space][space]... but I want to know why my current config doesn't alter text-mode properly.

Disable `indent-relative`

Bind Keys in Emacs For Particular Mode

Change Indentation in text-mode, emacs

AutoEnable Minor Modes in Fundamental

My Config, using Emacs 26 on macOS:

(package-initialize)

;; use the $PATH from bashrc
(when (memq window-system '(mac ns x))
  (exec-path-from-shell-initialize))

(tool-bar-mode -1)

;; Tab settings
(setq-default tab-width 2) ;; always using tab = 2 spaces
(setq-default c-basic-offset 2) ;; default is 4
(setq-default python-indent-offset 2) ;; default is 4
(setq-default tab-stop-list '(2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84))

;; Tabs to 2 spaces for text-mode too..
;; https://stackoverflow.com/questions/3976240/how-to-change-indentation-in-text-mode-for-emacs
;; https://www.xemacs.org/Links/tutorials_1.html
;; indent-for-tab or indent-relative ?

(setq c-default-style "stroustrup")
;; Show line numbers
(global-linum-mode t)

(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(indent-tabs-mode nil)
 '(package-selected-packages
   (quote
    (exec-path-from-shell haskell-mode use-package all-the-icons doom-themes)))
 '(standard-indent 2))
(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 )


;;; ~~ ATTEMPTED INDENTATION FIXES ... i.e. random, found emacsLisp hotfixes ~~

;;; OUTLINE MODE UPON FILE EXT DETECTION:

;; "outline-mode" not recognized.. 
;;(setq outline-mode
;;      (cons '("\\.plain$" . text-mode) outline-mode))


;;; RE-BIND indent-line-function to be insert-tab, set to tab-width 2, whenever in text mode

(add-hook 'text-mode-hook (lambda () 
                            (setq-default indent-line-function (quote insert-tab) )))


;; recent files emacs
(recentf-mode 1)
(setq recentf-max-menu-items 25)
(setq recentf-max-saved-items 25)
(global-set-key "\C-x\ \C-r" 'recentf-open-files)


;; auto close bracket insertion. New in emacs 24
(electric-pair-mode 1)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.