The title contains the crux of my question. In
go-mode, tabs and auto-indentation generally works well, except when I am editing strings.
When inside of a string, I'd like the tab key to self-insert. Right now, it does nothing.
The function below checks if the point is in a string using
syntax-ppss and inserts a
TAB if it is, otherwise calls
indent-for-tab-command, which is what
TAB is bound to in
(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)))
Here's one way to get the behavior you need with the help of this function:
(add-hook 'go-mode-hook (lambda () (local-set-key (kbd "TAB") #'my-indent-or-insert-tab)))
Let me know if this works for you.