Hello there pretty people, an emacs newbie here, and would love some help.
When I insert a new line in my Java file, I get a lovely, sexy tab for indentation inserted automatically.
When I press the backspace key to delete the tab, all my tabs are changed into spaces. This disgusts me. It angers me. I am close to homicidal.
Does anyone know how to stop this?
I have tried running "indent-tabs-mode t", but that does nothing, which makes sense, because tabs are already enabled.
The functionality I want is simple. Tabs for indentation, spaces for alignment. When I delete a tab, it deletes the tab. When I delete a space, it deletes the space.
I've been googling for quite a while, and can't seem to figure it out.
Extra info - Emacs 28.2 snap package. Git cloned spacemacs just today after issues with doomemacs.
​
**UPDATE - sort of solved it:**
So I have been experimenting, and I have had to change a few things to get what I want. I am testing all this by writing java code and have lsp enabled, which may affect how indentation is decided.
For some reason spaceemacs wants to indent by having a series of tabs first, followed by 4 spaces, which is completely against how any programmer should indent. With the config below, it still does this for some lines I add, but I can press tab again to convert it into a tab.
I had to change a few variables using M-x customize-variable and typing the variable name. These are under the function emacs-custom-settings().
I added this to my .spacemacs file:
(defun dotspacemacs/user-config ()
;; My settings to override spaceemacs' weird indentation rules.
;;(global-set-key (kbd "<backspace>") 'backward-delete-char) ;; bad practice to override, but keep for info.
(global-set-key (kbd "TAB") 'tab-to-tab-stop)
)
(defun dotspacemacs/emacs-custom-settings ()
(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.
'(backward-delete-char-untabify-method nil) ;; make the backspace delete a single character, instead of changing tabs to spaces.
'(electric-indent-mode nil) ;; Stops it changing the indent as I type on the current line.
'(global-hungry-delete-mode nil) ;; Turns hungry delete mode off, needed as I overwrote the backspace key earlier.
'(indent-tabs-mode t) ;; set indent to tabs
'(tab-always-indent t) ;; always insert tabs
'(tab-width 8) ;; A sane tab length.
;; I want to see the whitespace, to make sure it's all working properly.
'(global-whitespace-mode t)
'(whitespace-style
'(face trailing tabs spaces lines newline missing-newline-at-eof empty indentation space-after-tab space-before-tab space-mark tab-mark))
)
)