2009-09-25 67 views
19

当我使用emacs python-mode时,如果一行的最后一个字符是左括号,它会从上一行的缩进中缩进下一行。如何在Emacs的左括号之后控制缩进

call_some_function(
    some_very_long_argument_that_I_want_to_put_on_its_own_line) 

我喜欢那样。现在在ecmascript-mode(我用于actionscript 3)中,它总是缩进到前一个括号的水平。

call_some_function(
        this_is_not_really_saving_me_any_horizontal_space); 

如何在这方面使ecmascript-mode缩进像python-mode?

回答

18

由于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))) 
+0

谢谢!这个钩子完美的工作,并不需要我搞砸任何其他模式。我也不知道C-C C-o,这很方便。 – lacker 2009-09-25 16:18:24

+0

如何在文件末尾添加模式行?像这里http://stackoverflow.com/questions/5382475/emacs-modeline-at-the-end-of-file-in-one-line – alfC 2011-08-29 02:26:03

3

ecmascript-mode似乎基于CC模式。如果您为cc-mode设置缩进样式, 它也可以用于ecmascript-mode。我在我的.emacs中有以下代码。当我使用 ECMAScript的模式它缩进根据需要:

;;{{{ 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

如果移出足够的部分并专注于缩进自定义,那将会很好。 – 2010-07-08 07:34:44

0

谢谢Török的Gabor,在我的情况我者优先设置

(add-hook 'XXX-mode-hook 
     (lambda() 
       (c-set-offset 'arglist-cont-nonempty '+))) 

我一直在寻找的东西像这样:

veryLongFunctionName (bar, bar, bar)

对于MOR e详尽的变量列表:read emacs documentation

+0

请检查这[URL](http://stackoverflow.com/help )这将有助于提升您的内容质量 – 2016-05-19 09:37:24

+0

我不太明白你的意思。 URL指向帮助页面,但没有任何精确性:我应该在那里查看哪些内容?我的评论有什么错误? – Meinew 2016-05-19 10:42:24

相关问题