How do I auto-indent in Textmate similar to the effect of this code under Emacs:
(defun set-newline-and-indent ()
(local-set-key (kbd "RET") 'newline-and-indent))
(add-hook 'c-mode 'set-newline-and-indent)
i.e. I don't want to hit return, then tab to indent. I want to hit retu开发者_如何学运维rn and have Textmate automatically indent to the correct location based on the language.
Thanks for any hints.
Textmate should do this automatically. If if doesn't, you can create a custom macro, command, or snippet in the bundle editor which does it for you.
- First find out the scope of the caret position (
Bundles -> Bundle Development -> Show Scope
). It should look something likesource.ruby string.quoted.double.ruby
. - Then create a snippet that contains a newline and a tab.
- Then assign the snippet to the previously mentioned scope and assign it a shortcut.
If done correctly, your shortcut should trigger the bundle item in the assigned scope instead of inserting a new line.
Look inside the bundle editor at the CSS -> properties {}(})
bundle item for an example.
精彩评论