当我使用emacs python-mode时,如果一行的最后一个字符是一个左括号,它只是从上一行的缩进中缩进下一行。
call_some_function(
some_very_long_argument_that_I_want_to_put_on_its_own_line)
我喜欢那样。现在在ecmascript模式(我用于动作脚本3),它总是缩进到前一个括号的级别。
call_some_function(
this_is_not_really_saving_me_any_horizontal_space);
如何在这方面使ecmascript-mode缩进像python-mode? p>
答案 0 :(得分:20)
由于ecmascript-mode基于cc模式,因此您可以使用c-set-offset
,它允许您使用首选值自定义任何语法符号的偏移量。
在您的情况下,转到缩进级别的点,点击C-c C-o
(或键入M-x c-set-offset
),接受建议的符号(arglist-intro
),然后设置它一个新值(例如+
,默认偏移量。)
您也可以在dotemacs中以编程方式执行此操作,例如:
(add-hook 'ecmascript-mode-hook
(lambda ()
(c-set-offset 'arglist-intro '+)
(c-set-offset 'arglist-close 0)))
答案 1 :(得分:3)
ecmascript-mode 似乎基于 cc-mode 。如果为 cc-mode 设置缩进样式, 它也适用于 ecmascript-mode 。我在 .emacs 中有以下代码。我用的时候 ecmascript-mode 根据需要缩进:
;;{{{ c/c++ indent style variables
(require 'cc-mode)
(defconst my-c-style
'(
(c-electric-pound-behavior . 'alignleft)
(c-tab-always-indent . t)
(c-hanging-braces-alist . ((block-open)
(brace-list-open)
(substatement-open)
(defun-open before after)
(defun-close before after)
))
(c-hanging-colons-alist . ((member-init-intro before)
(inher-intro)
(case-label)
(access-label after)
(label after)
(access-key after)))
(c-cleanup-list . (scope-operator
empty-defun-braces
defun-close-semi))
(c-offsets-alist . ((arglist-close . c-lineup-arglist)
(case-label . 4)
(statement-case-intro . 4)
(access-label . -4)
(label . -)
(substatement-open . 0)
(block-open . 0)
(knr-argdecl-intro . -)))
)
"My C++/C Programming Style")
; Customizations for both c-mode and c++-mode
(defun my-c-mode-common-hook ()
; set up for my perferred indentation style, but only do it once
(c-add-style "My" my-c-style 'set-this-style)
; we like auto-newline and hungry-delete
(c-toggle-auto-hungry-state 1)
; keybindings for both C and C++. We can put these in c-mode-map
; because c++-mode-map inherits it
(define-key c-mode-map "\C-m" 'newline-and-indent)
; insert 8 tabs
(setq tab-width 8)
)
;;}}}
答案 2 :(得分:0)
谢谢TörökGábor,就我而言,我更喜欢设置
(add-hook 'XXX-mode-hook
(lambda ()
(c-set-offset 'arglist-cont-nonempty '+)))
我正在寻找这样的事情:
veryLongFunctionName (bar,
bar,
bar)
更详尽的变量列表:read emacs documentation