我正在使用具有常规电动模式的emacs(按照here概述安装)。我的.emacs文件的相关部分(我认为)在本问题的最后给出。
我输入缩进时的当前行为是:
def someObject = new Something(
param1
此时我想要的是一切,但只要输入':'字符,就会变成:
def someObject = new Something(
param1:
我希望param / value对(以及后面的任何一对)保持缩进一级,就像之前一样,例如:
def someObject = new Something(
param1: val1,
param2: val2
)
.emacs
摘录:
(electric-indent-mode t)
(setq-default tab-width 4)
(setq-default indent-tabs-mode nil)
(setq indent-line-function 'insert-tab)
(setq tabify nil)
(setq-default c-basic-offset 4)
(delete-selection-mode 1)
(set-default-font "-apple-Bitstream_Vera_Sans_Mono-medium-normal-normal-*-*-*-*-*-m-0-iso10646-1")
(setq load-path (cons "~/.emacs.d/" load-path))
(add-to-list 'custom-theme-load-path "~/.emacs.d/themes/")
(setq whitespace-action '(auto-cleanup)) ;; automatically clean up bad whitespace
(setq whitespace-style '(trailing space-before-tab indentation empty space-after-tab)) ;; only show bad whitespace
;;; delete trailing whitespace
(add-hook 'before-save-hook 'delete-trailing-whitespace)
;;; turn on syntax highlighting
(global-font-lock-mode 1)
;;; use groovy-mode when file ends in .groovy or has #!/bin/groovy at start
(autoload 'groovy-mode "groovy-mode" "Major mode for editing Groovy code." t)
(add-to-list 'auto-mode-alist '("\\.groovy\\'" . groovy-mode))
(add-to-list 'interpreter-mode-alist '("groovy" . groovy-mode))
;;; make Groovy mode electric by default.
(add-hook 'groovy-mode-hook
(lambda ()
(require 'groovy-electric)
(groovy-electric-mode)))
编辑:关于@ataylor的建议如下,我试过了两个:
(add-hook 'groovy-mode-hook
'(lambda ()
(require 'groovy-electric)
(groovy-electric-mode)))
(add-hook 'groovy-mode-hook '(c-set-offset 'label 4))
和
(add-hook 'groovy-mode-hook
'(lambda ()
(require 'groovy-electric)
(groovy-electric-mode)
(c-set-offset 'label 4)))
两者都不能按我的意愿工作。这是正确的地方吗?
答案 0 :(得分:3)
Groovy模式将这些类型的参数视为标签,例如case语句标签和从Java继承的很少使用的特性,允许break
语句指定目标。
您可以通过将其添加到钩子来覆盖缩进:
(add-hook 'groovy-mode-hook
(lambda ()
(c-set-offset 'label 4)))