The Computer Oracle

How can I disable smart indentation in emacs (and force either spaces or tabs)?

--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------


Take control of your privacy with Proton's trusted, Swiss-based, secure services.
Choose what you need and safeguard your digital life:
Mail: https://go.getproton.me/SH1CU
VPN: https://go.getproton.me/SH1DI
Password Manager: https://go.getproton.me/SH1DJ
Drive: https://go.getproton.me/SH1CT


Music by Eric Matyas
https://www.soundimage.org
Track title: Unforgiving Himalayas Looping

--

Chapters
00:00 How Can I Disable Smart Indentation In Emacs (And Force Either Spaces Or Tabs)?
00:27 Accepted Answer Score 2
00:53 Answer 2 Score 3
01:06 Thank you

--

Full question
https://superuser.com/questions/268029/h...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#emacs

#avk47



ANSWER 1

Score 3


Try this.

Find your .emacs and add this:

(setq c-basic-offset 2)

this make your emacs inserts 2 spaces, you can change the number and put 4,

(setq-default indent-tabs-mode nil)

if you want spaces NO tabs




ACCEPTED ANSWER

Score 2


The problem is that each mode in emacs defines the TAB key diferently. To get a global behavior, look at Trey Jackson's answer in https://stackoverflow.com/questions/344966/sane-tab-in-emacs

 (defvar just-tab-keymap (make-sparse-keymap) "Keymap for just-tab-mode")
 (define-minor-mode just-tab-mode
   "Just want the TAB key to be a TAB"
   :global t :lighter " TAB" :init-value 0 :keymap just-tab-keymap
   (define-key just-tab-keymap (kbd "TAB") 'indent-for-tab-command))

You may want to use 'self-insert-command instead of 'indent-for-tab-command as pointed out by another person answering the question.