web-dev-qa-db-ja.com

Spacemacsがタブの幅を設定

VIMからSpacemacsに移行しました。タブ幅をデフォルト(\ t?)から2スペースのみに変更したいと思います。

(setq-default indent-tabs-mode nil)

そして

(setq tab-width 4) ; or any other preferred value
(defvaralias 'c-basic-offset 'tab-width)
(defvaralias 'cperl-indent-level 'tab-width)

私の問題は、それらが正しいかどうか、.spacemacsファイルのどこに挿入するべきか、そしてそれらの意味すらわからないことです。

33
Catsy

次の記事を見つけました: http://blog.binchen.org/posts/easy-indentation-setup-in-emacs-for-web-development.html

コードのこの部分を関数の外部の.spacemacsファイルに追加しました(ただし、(defun dotspacemacs/user-init () ... )):

(defun my-setup-indent (n)
  ;; Java/c/c++
  (setq c-basic-offset n)
  ;; web development
  (setq coffee-tab-width n) ; coffeescript
  (setq javascript-indent-level n) ; javascript-mode
  (setq js-indent-level n) ; js-mode
  (setq js2-basic-offset n) ; js2-mode, in latest js2-mode, it's alias of js-indent-level
  (setq web-mode-markup-indent-offset n) ; web-mode, html tag in html file
  (setq web-mode-css-indent-offset n) ; web-mode, css in html file
  (setq web-mode-code-indent-offset n) ; web-mode, js code in html file
  (setq css-indent-offset n) ; css-mode
  )

そして、行を追加しました

(my-setup-indent 2) ; indent 2 spaces width

(defun dotspacemacs/user-init () ... ) このような:

(defun dotspacemacs/user-init ()
  "Initialization function for user code.
It is called immediately after `dotspacemacs/init', before layer configuration
executes.
 This function is mostly useful for variables that need to be set
before packages are loaded. If you are unsure, you should try in setting them in
`dotspacemacs/user-config' first."
  (my-setup-indent 2) ; indent 2 spaces width
  )
44
Catsy

Spacemacs内でコマンドstandard-indentを呼び出して、customize-variable変数をカスタマイズして2に設定することもできます。これにより、カスタマイズが.spacemacsファイルに保存されます。

編集:

'customize-variable'を実行するには、ホットキーM-x(ほとんどのシステムではalt-x)を使用し、プロンプトにcustomize-variableを入力します。

検索を使用して「標準インデント」を検索できます

18
SpaceNuB1