Smartparens와 C# 모드

언제부터인가 smartparens가 C# 모드에서 작동하지 않게 되었다. 예로 아래와 같이 methodA()에서 리턴을 누르면 다음과 같은 위치(|)에 커서가 있는데

void methodA()
    |

이 상태에서 { 를 입력하면 앞으로 인덴트 되어야 하는데 그냥 그자리에 입력된다.

void methodA()
    {|}

어쨌건 여기서 다시 리턴을 누르면 아래처럼 되어야 하는데

void methodA()
{
    |
}

아래처럼 되는 것이었다.

void methodA()
    {
	|
    }

나의 smartparens 설정이 잘못되었나 생각되어 이리저리 고쳐 보았지만 해결되지 않았다. 그러다 구글 검색을 해보니 emacs 27에서 cc-mode의 버그(?)로 안되는 것이었다. 다음과 같은 workaround로 해결.

(use-package smartparens
  :hook (prog-mode . smartparens-mode)
  :bind
  ("M-<backspace>" . sp-unwrap-sexp)
  ("M-<left>" . sp-forward-barf-sexp)
  ("M-<right>" . sp-forward-slurp-sexp)
  :config
  (require 'smartparens-config)
  (when my-emacs27
    (dolist (fun '(c-electric-paren c-electric-brace))
      (add-to-list 'sp--special-self-insert-commands fun)))

  (setq sp-escape-quotes-after-insert nil)

  (sp-local-pair 'elixir-mode "do" "end"
		 :when '(("RET" "<evil-ret>"))
		 :unless '(sp-in-comment-p sp-in-string-p)
		 :post-handlers '("||\n[i]"))
  (sp-local-pair 'csharp-mode "{" nil
		 :post-handlers '(("||\n[i]" "RET") ("| " "SPC"))
		 :unless '(sp-point-before-word-p sp-point-before-same-p)))

(when my-emacs27 ... 부분이 포인트다. 관련 github 이슈는 https://github.com/Fuco1/smartparens/issues/963 이곳에 있다.

댓글

Comments powered by Disqus