0

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.

Stefan
  • 26,154
  • 3
  • 46
  • 84
  • See https://emacs.stackexchange.com/q/5579/15748 and https://stackoverflow.com/a/34835914/3084001. Your second example is missing an [`interactive` spec](https://www.emacswiki.org/emacs/InteractiveFunction), which makes it a plain function, rather than an interactive command. Functions must be interactive in order to be bound to keys. See https://www.masteringemacs.org/article/mastering-key-bindings-emacs for a great writeup on how to define and bind commands. – Basil Jan 21 '18 at 00: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 00: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 "")` is not something that can be used by `self-insert-command`. – Drew Jan 21 '18 at 00:25
  • "which didn't work" carries very little information. Please clarify. – Stefan Jan 21 '18 at 03: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. –  Jan 21 '18 at 18:59

1 Answers1

0
(local-set-key (kbd "<tab>") #'tab-to-tab-stop)

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

Moyamo
  • 388
  • 2
  • 7