在Emacs Prelude中启用特定于模式的Paren缩进

在Emacs Prelude中启用特定于模式的Paren缩进,emacs,emacs24,emacs-prelude,Emacs,Emacs24,Emacs Prelude,因此,我切换到Emacs Prelude,并喜欢它;它有95%的东西是我想要烤的,这很可爱。我只想改变一件事:参数之间特定于模式的缩进,即laautopair.el。例如,如果我正在编写Scala并键入: Object foo { bar() {} } 。。。然后在条的大括号之间输入一条换行符,我应该得到: Object foo { bar() { // And point should be here, a Scala-standard two-space indent

因此,我切换到Emacs Prelude,并喜欢它;它有95%的东西是我想要烤的,这很可爱。我只想改变一件事:参数之间特定于模式的缩进,即la
autopair.el
。例如,如果我正在编写Scala并键入:

Object foo {

  bar() {}

}
。。。然后在
条的大括号之间输入一条换行符,我应该得到:

Object foo {

  bar() {
    // And point should be here, a Scala-standard two-space indent in from bar.
  }

}
但是,如果我用PHP写的东西或多或少是一样的,我应该得到一个
tab
字符,而不是两个空格的tab

那么:有没有一种“正确”的方法可以通过
custom.el
来调整这一点呢?Prelude使用
smartparens
而不是
autopair.el
,在
Prelude editor.el
中配置--但我更愿意在不必破解“核心”Prelude的情况下进行配置,这样我就可以轻松地合并更新


想法?还有人知道如何使用smartparens,或者特别是Prelude来实现这一点吗?

通常,我一发布这篇文章就想到了。。。大部分答案是肯定的。它很好,因为它可以通过
custom.el
工作;这很糟糕,因为它涉及大量的重复,我不知道如何使它干涸

(sp-local-pair 'major-mode "{" nil :post-handlers '((my-create-newline-and-enter-sexp "RET")))                                                                                                                 
(sp-local-pair 'major-mode "(" nil :post-handlers '((my-create-newline-and-enter-sexp "RET")))                                                                                                                 
(sp-local-pair 'major-mode "[" nil :post-handlers '((my-create-newline-and-enter-sexp "RET")))                                                                                                                 
(sp-local-pair 'major-mode "<" nil :post-handlers '((my-create-newline-and-enter-sexp "RET")))                                                                                                                 

(defun my-create-newline-and-enter-sexp (&rest _ignored)                                                                                                                                                       
  "Open a new brace or bracket expression, with relevant newlines and indent. "                                                                                                                                
  (newline)                                                                                                                                                                                                    
  (indent-according-to-mode)                                                                                                                                                                                   
  (forward-line -1) 

你已经在正确的轨道上了。我只想在你自传的答案上加一点

smartparens的总体思路是为不同的主要模式开发专门的配置,这样您就可以为每种模式提供最佳体验。历史告诉我们,一般的解决方案通常是次优的

鼓励smartparens用户提交各种主要模式的上游配置-已有针对、Latex、Lisp和Lua的配置。为了所有smartparens用户的利益,您最好提交Scala和PHP的上游配置。前奏曲将使那些开箱即用的音乐出现


几乎所有东西都能微调,这让我选择了smartparens作为前奏曲。我认为smartparens在未来对Emacs用户将变得更加重要(它已经成功地取代了类似paredit for Lisp编程的庞然大物)。

啊,好吧!我已经用我习惯的方式思考了太多(
autopair.el
)——虽然我在sp源代码中发现了
smartparens ruby.el
,但我还没有想太久为什么会有这样的结果……无论如何:谢谢你的清晰和前奏(这是非常棒的)。
(loop for c in 'sp-pair-list                                                                                                                                                                                 
  do (                                                                                                                                                                                                       
    sp-local-pair 'major-mode c nil :post-handlers '((my-create-newline-and-enter-sexp "RET"))))