开发者

how to auto-ident in Textmate similar to Emacs

开发者 https://www.devze.com 2023-02-11 00:24 出处:网络
How do I auto-indent in Textmate similar to the effect of this code under Emacs: (defun set-newline-and-indent ()

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.

  1. First find out the scope of the caret position (Bundles -> Bundle Development -> Show Scope). It should look something like source.ruby string.quoted.double.ruby.
  2. Then create a snippet that contains a newline and a tab.
  3. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消