Reputation: 16270
After a long time looking for solutions to force Emacs to use tab as real characters in C++ code, I realized that the only robust solution is to insert tabs using the "CTRL+Q TAB" key sequence. See https://stackoverflow.com/a/5146702/225186 .
Is there a way to make this the default? That is to output a real TAB character when pressing the TAB key, without the need of typing CTRL+Q TAB.
Is there a way to activate this option from an Emacs "modeline" (first line of text file enclosed by //-*-
and -*-
)?
Upvotes: 1
Views: 376
Reputation: 898
In C++ mode (and many other modes) TAB is considered as a command instead of a character. In c++ mode it is bound to c-indent-line-or-region
and it's behaviour is
Indent active region, current line, or block starting on this line. In Transient Mark mode, when the region is active, reindent the region. Otherwise, with a prefix argument, rigidly reindent the expression starting on the current line. Otherwise reindent just the current line.
You can either use Ctrl+Q Tab
or M-i
(a bit shorter than Ctrl+Q Tab) commands to insert tab character.
If you want to insert real tab character on pressing TAB (overriding binding for indentation) then you can add following on top of your file to set buffer specific variables.
// -*- eval: (define-key c++-mode-map (kbd "<tab>") 'tab-to-tab-stop)
-*-
or you can bind it to Shift-Tab to insert TAB character (not intuitive though):
// -*- eval: (define-key c++-mode-map (kbd "<backtab>") 'tab-to-tab-stop)
-*-
Upvotes: 2