0

I am a beginning Emacs user. I am trying to set up Emacs to simply add 2 spaces when I hit TAB. [If possible, I would like to have auto-indentation within Lisp files as well, but if it's not possible to have this coexist with manual tabbing, I would prefer manual tabbing.]

Currently, in "plainly" named files, TAB inserts 2 spaces as expected. However, in files that have an extension .c, .lisp, .java, etc., that Emacs apparently recognizes, pressing TAB currently does nothing.

Here is the full content of my current .emacs:


(add-to-list 'load-path "~")
(setf inhibit-startup-screen t)
(load (expand-file-name "~/.quicklisp/slime-helper.el"))
(setq inferior-lisp-program "sbcl")
(slime-setup '(slime-fancy))
(global-font-lock-mode 0)
(require 'pbcopy)
(turn-on-pbcopy)
(setq-default tab-width 2)

[Currently, auto-indentation is working in .lisp and .emacs files.]

What can I do to make Emacs allow me to TAB manually in any type of file, with or without Lisp auto-indentation for Lisp files? Any info would be much appreciated!

zeroclaim
  • 57
  • 2
  • 7

1 Answers1

0

After finding this related question and reading about global-set-key here, I tried adding

(global-set-key (kbd "TAB") 'tab-to-tab-stop)

to my .emacs and that worked!

[ Side note - for some reason, the more standard

(global-set-key (kbd "<tab>") 'tab-to-tab-stop)

did not work. I am on MacOS 13.0. ]

zeroclaim
  • 57
  • 2
  • 7
  • 1
    `(kbd "TAB")` returns a literal tab character; `(kbd "")` returns the keycode for the tab key, `[tab]` – tripleee Nov 02 '22 at 08:58
  • 1
    Your OS version is probably of secondary importance, but which Emacs build and version you are running could be quite significant. – tripleee Nov 02 '22 at 08:59