eglot 聪明地接管 TAB 格式化

随便糊的,印象里 lsp-mode 是默认行为。

如果还有什么类似 yasnippet 的 corner case 欢迎补充(

(use-package eglot
  :ensure nil
  :init
  (setq eglot-code-action-indications '(eldoc-hint))
  (defun eglot-for-tab-command ()
    (interactive)
    (cond ((yas-active-snippets)
           (yas-next-field-or-maybe-expand))
          ((save-excursion
             (beginning-of-line)
             (looking-at-p "[ \t]*$"))
           (indent-for-tab-command))
          (t (eglot-format)
             (when (use-region-p)
               (deactivate-mark)))))
  :bind (:map eglot-mode-map
              ([tab] . eglot-for-tab-command)))
1 个赞

tab键堪称emacs中占用最为严重的按键,要小心。比如 markdown 中的 markdown cycle 用的也是它…

1 个赞

markdown-mode 跟 eglot 没什么关系吧,这里改的是 eglot-mode-map

嗯嗯,确实。主要是提醒下。我的tab键设计的各种冲突了,只能专门写了一个mode来分配它的行为了。

我试下来还好、感觉也不会有什么 prog-mode 给 tab 绑定 indent-for-tab-command 之外的意义

当然 yasnippet 这样用 tab 来展开的 corner case 也的确存在