20

emacs python-mode を使用すると、行の最後の文字が開き括弧の場合、前の行のインデントから 1 ステップだけ次の行がインデントされます。

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 のようにインデントするにはどうすればよいですか?

4

3 に答える 3

21

ecmascript-modeはcc-modeに基づいているため、これを使用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)))
于 2009-09-25T12:03:30.233 に答える
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)
 )

;;}}}
于 2009-09-25T05:56:01.143 に答える
1

ありがとうTörökGábor、私の場合は設定することを好みました

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

私はこのようなものを探していました:

veryLongFunctionName (bar, bar, bar)

変数の完全なリストについては、emacs のドキュメントを参照してください。

于 2016-05-19T09:20:42.623 に答える