2009-09-25 61 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

相關問題