1

In go-mode, inside a rune hitting the tab key doesn't add the tab character.

E.g.:

var foobar = `
If I place the point at the start of this line and press tab it wouldn't add the tab character :(
`
var barfoo = 1 // I expect the tab character not to be added if I do the same  here

How can I get this behavior?

Trying what's proposed here doesn't do it.

  • 1
    As last resort you can always insert a tab character by typing `C-q TAB`. – Tobias May 27 '16 at 13:43
  • What does `M-: (nth 3 (syntax-ppss (point)))` say when point is where you want to insert the tab character? – Tobias May 27 '16 at 13:47
  • It is likely that you did something wrong when installing http://emacs.stackexchange.com/a/19807/8223. Put the `defun` and the `add-hook` into your initialization file, maybe re-compile the file, then restart emacs and try again. (Note, the restart is actually not required. But I added it here to make sure that you restart everything. (E.g., restart `go-mode` for the go-file **after** you installed the hook.) – Tobias May 27 '16 at 13:58
  • Result of the command: `96 (#o140, #x60, ?\`)`Restarting Emacs I do as last resort and I my least preferred. (E)Lisp is powerful enough to provide a solution. @Tobias. +1 to `C-q TAB` but inconvenient. – Bleeding Fingers May 27 '16 at 15:23
  • The non-nil result says that the syntax is setup correctly. Therefore, the solution from http://emacs.stackexchange.com/a/19807/8223 should work. As I already stated you most certainly did something wrong when installing that solution. Did you copy the `defun` and the `add-hook` from that page into your initialization file (e.g., `~/.emacs`)? – Tobias May 27 '16 at 16:10
  • I don't have it in my `~/.emacs`, instead I executed with `M-:` ---> `(defun my-indent-or-insert-tab (arg) "Insert TAB if point is in a string, otherwise call \`indent-for-tab-command'." (interactive "P") (if (nth 3 (syntax-ppss (point))) (insert "\t") (indent-for-tab-command arg)))` ---> `M-:` ---> `(add-hook 'go-mode-hook (lambda () (local-set-key (kbd "TAB") #'my-indent-or-insert-tab)))` – Bleeding Fingers Jun 09 '16 at 13:57
  • 1
    If you do this with the go file already loaded you need to do `M-x normal-mode` afterwards to run the hook functions. – Tobias Jun 09 '16 at 18:51
  • That works! Thanks! :D What should I with this question? Thinking: Edit the answer in the other question and mark it as a duplicate of that. – Bleeding Fingers Jun 10 '16 at 07:14

0 Answers0