commit 7af0e35acc08d59b1bc25ff28edddcc09c51544f parent cd88b58eac7b2716e5f65e78e4e5bf96706ad68d Author: andsy10 <andsy1016@gmail.com> Date: Mon, 19 Oct 2026 07:04:27 +0800 Add grammar checker integration Diffstat:
| M | lisp/init-custom.el | | | 7 | +++++++ |
| M | lisp/init-kbd.el | | | 2 | +- |
| M | lisp/init-package.el | | | 51 | +++++++++++++++++++++++++++++++++++++++++++++++++++ |
3 files changed, 59 insertions(+), 1 deletion(-)
diff --git a/lisp/init-custom.el b/lisp/init-custom.el @@ -85,5 +85,12 @@ I need to use `org-directory' before org is loaded." :type 'boolean :group 'trogloxene) +(defcustom my-grammar-checker-backend 'nil + "Backend to use for grammar checking." + :type '(choice (const :tag "nil" nil) + (const :tag "LanguageTool" languagetool) + (const :tag "Harper" harper) + (const :tag "NSSpellChecker" nsspell))) + (provide 'init-custom) ;;; init-custom.el ends here diff --git a/lisp/init-kbd.el b/lisp/init-kbd.el @@ -496,7 +496,7 @@ :prefix "C-c t" "f" #'flycheck-mode "j" #'jinx-mode - "g" #'gptel-mode + "g" #'my-toggle-grammar-checker "h" #'global-diff-hl-mode "k" #'keycast-header-line-mode "v" #'vcursor-use-vcursor-map diff --git a/lisp/init-package.el b/lisp/init-package.el @@ -29,6 +29,57 @@ (consult-jinx :type git :repo "https://git.trogloxene.org/consult-jinx.git")) +;; grammar checkers +(autoload #'eglot-managed-p "eglot") +(defun my-toggle-grammar-checker () + "Toggle grammar checker depend on `my-grammar-checker-backend'." + (interactive) + (if text-mode-variant + (pcase my-grammar-checker-backend + ('harper (if (eglot-managed-p) + (call-interactively #'eglot-shutdown) + (call-interactively #'eglot))) + ('languagetool (if (eglot-managed-p) + (call-interactively #'eglot-shutdown) + (call-interactively #'eglot))) + ('nsspell (nsspell-grammar-mode)) + ('nil (message "No grammar checker backend"))) + (message "Not in a text-mode buffer"))) + +(my-use-package nsspell + (and *is-mac* (equal my-grammar-checker-backend 'nsspell)) + :straight (nsspell + :type git + :host github + :repo "LdBeth/nsspell" + :file ("lisp/")) + :init + (setq ispell-program-name "nsspell") + (setq ispell-dictionary "en")) + +(my-use-package eglot-ltex + (equal my-grammar-checker-backend 'languagetool) + :straight + (eglot-letx :type git :host github :repo "emacs-languagetool/eglot-ltex") + :hook + (text-mode . (lambda () (require 'eglot-ltex))) + :init + (setq eglot-ltex-server-path "ltex-ls-plus" + eglot-ltex-communication-channel 'stdio)) + +(my-use-package harper + (equal my-grammar-checker-backend 'harper) + :no-require t + :straight nil + :init + (with-eval-after-load 'eglot + (add-to-list 'eglot-server-programs + '((markdown-mode :language-id "markdown") . ("harper-ls" "--stdio"))) + (add-to-list 'eglot-server-programs + '((org-mode :language-id "org") . ("harper-ls" "--stdio"))) + (setq-default eglot-workspace-configuration + '(:harper-ls (:linters (:SpellCheck :json-false :Spaces :json-false)))))) + ;; terminal emulator (my-use-package ghostel :hook