I'm trying to bind tab to either a tab or multiple spaces in Latex/ESS-noweb mode but I can't get it to work. I tried (local-set-key (kbd "<tab>") 'self-insert-command) which didn't work, and then (local-set-key (kbd "<tab>") (lambda() (insert " "))) which also didn't work.

  • See emacs.stackexchange.com/q/5579/15748 and stackoverflow.com/a/34835914/3084001. Your second example is missing an interactive spec, which makes it a plain function, rather than an interactive command. Functions must be interactive in order to be bound to keys. See masteringemacs.org/article/mastering-key-bindings-emacs for a great writeup on how to define and bind commands.
    – Basil
    Jan 21 '18 at 0:02
  • It would be helpful to clarify whether you are solely looking to insert some string of text, such as tab or space characters (which is covered in the questions I link), or whether there is a higher-level purpose to this, such as performing indentation or some other type of formatting, as suggested by your choice of tags. In this case people may be able to provide answers relevant to LaTeX/ESS modes.
    – Basil
    Jan 21 '18 at 0:07
  • 1. The function you are attempting to bind to a key is not a command. It is missing an interactive spec. 2. Only keys that correspond to characters can reasonably be bound to self-insert-command, so your first attempt would be wrong even if it had interactive: (kbd "<tab>") is not something that can be used by self-insert-command.
    – Drew
    Jan 21 '18 at 0:25
  • "which didn't work" carries very little information. Please clarify.
    – Stefan
    Jan 21 '18 at 3:20
  • @Basil Sorry for the lack of clarity. I'm new to emacs and wasn't aware of the command/function distinction. The higher level purpose is that I would like to adjust the electric indentation settings somehow, I'm just not sure exactly how I would like them yet.
    – user17376
    Jan 21 '18 at 18:59
(local-set-key (kbd "<tab>") #'tab-to-tab-stop)

Will make tab behave like it does in other primitive editors.