簡體   English   中英

如何在Emacs中打開括號后控制縮進

[英]How to control indentation after an open parenthesis in Emacs

當我使用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);

在這方面我怎么能像ecthon-mode那樣制作ecmascript-mode縮進?

由於ecmascript模式基於cc模式,因此您可以使用c-set-offset ,它允許您使用首選值自定義任何語法符號的偏移量。

在你的情況下,轉到錯誤級別縮進的點,點擊Cc Co (或鍵入Mx c-set-offset ),接受建議的符號( arglist-intro ),並設置一個新值(例如+ ,默認偏移量)。

您也可以在dotemacs中以編程方式執行此操作,例如:

(add-hook 'ecmascript-mode-hook
          (lambda ()
            (c-set-offset 'arglist-intro '+)
            (c-set-offset 'arglist-close 0)))

ecmascript-mode似乎基於cc模式 如果為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)
 )

;;}}}

謝謝TörökGábor,在我的情況下,我更喜歡設置

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

我在尋找這樣的東西:

veryLongFunctionName (bar, bar, bar)

有關變量的更詳盡列表: 請閱讀emacs文檔

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM