尝试在Emacs中捕获块缩进

时间:2022-01-22 19:33:47

I'm using the bsd style of indentation in emacs & I'd like to modify it a bit. The related portion of my .emacs file is below. When I write a function with try catch blocks the braces are indented. I'd like them to not indent similar to a function.

我在emacs中使用bsd缩进样式,我想稍微修改一下。我的.emacs文件的相关部分如下。当我用try catch块编写函数时,大括号会缩进。我希望他们不要像函数那样缩进。

What's it's doing now.

它现在在做什么

try 
    {
    }
catch 
    {
    }

What I'd like it to do.

我想要它做什么。

try 
{
}
catch 
{
}

.emacs file

(defun my-c-mode-common-hook ()
  ;; my customizations for all of c-mode and related modes
  ;; other customizations can go here
  (setq c-default-style "bsd")
  (setq c-basic-offset 4)
  (setq indent-tabs-mode nil)
  )

(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)

Any help would be appreciated.

任何帮助,将不胜感激。

1 个解决方案

#1


Go to the line with the indent you'd like to change and press C-c C-o. This runs c-set-offset and defaults to the current line's syntax (in this case substatement-open). '+' means one level of indent, '-' means one level unindent, and '0' means no additional indent. You want 0. To make it permanent, add (c-set-offset 'substatement-open 0) to your hook.

转到您想要更改的缩进行,然后按C-c C-o。这将运行c-set-offset并默认为当前行的语法(在本例中为substatement-open)。 '+'表示一个缩进级别,' - '表示一个级别的unindent,'0'表示没有额外的缩进。你想要0.为了使它永久化,将(c-set-offset'subcatement-open 0)添加到你的钩子。

#1


Go to the line with the indent you'd like to change and press C-c C-o. This runs c-set-offset and defaults to the current line's syntax (in this case substatement-open). '+' means one level of indent, '-' means one level unindent, and '0' means no additional indent. You want 0. To make it permanent, add (c-set-offset 'substatement-open 0) to your hook.

转到您想要更改的缩进行,然后按C-c C-o。这将运行c-set-offset并默认为当前行的语法(在本例中为substatement-open)。 '+'表示一个缩进级别,' - '表示一个级别的unindent,'0'表示没有额外的缩进。你想要0.为了使它永久化,将(c-set-offset'subcatement-open 0)添加到你的钩子。