Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs replaces spaces with tabs

Tags:

emacs

tabs

The problem is that I want Emacs to save tabs when I entered them as tabs and spaces if I entered them as spaces. But the editor replaces my manually typed spaces with tab when the number of spaces reaches amonut that is defined in tab-stop-list, i.e. when I type

   →func1() {
   →   →some_long_command_name -param1 -param2 \
   →   →→→→→→→→→→→→→→→→→→→→→→→→-param3 -param4

(where tab is    → and space is ) Emacs makes it

   →func1() {
   →   →some_long_command_name -param1 -param2 \
   →   →   →   →   →   →   →→→→-param3 -param4

Which breaks the indentation I wanted to preserve, if the length of the tab changes.

like image 461
tijagi Avatar asked Oct 15 '25 15:10

tijagi


1 Answers

Customize option indent-tabs-mode to give the value nil. This stops Emacs from converting indentation whitespace to use TAB chars. SPC chars and TAB chars that you enter remain such.

Then you will need to either bind key TAB to self-insert-command or else use C-q TAB to insert a TAB character. This means that you lose the TAB key as an indentation command. Alternatively, you could bind some other key to a command that inserts a TAB char, or else bind some other key than TAB to the indentation command that TAB is bound to by default.

like image 169
Drew Avatar answered Oct 19 '25 12:10

Drew