Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 46 additions & 3 deletions modules/checkers/grammar/README.org
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ This module adds grammar checking to Emacs to aid your writing by combining
/This module has no dedicated maintainers./ [[doom-contrib-maintainer:][Become a maintainer?]]

** Module flags
/This module has no flags./
- +lsp ::
Use [[doom-package:][lsp-ltex]] to provide on the fly corrections via [[https://valentjn.github.io/ltex/index.html][LTeX LS]].

** Packages
- [[doom-package:][langtool]]
- [[doom-package:][writegood-mode]]
- if [[doom-module:][+lsp]]
- [[doom-package:][lsp-ltex]]
- else
- [[doom-package:][langtool]]

** Hacks
/No hacks documented for this module./
Expand All @@ -27,7 +31,8 @@ This module adds grammar checking to Emacs to aid your writing by combining
* Installation
[[id:01cffea4-3329-45e2-a892-95a384ab2338][Enable this module in your ~doom!~ block.]]

This module requires [[https://languagetool.org/][LanguageTool]] (which requires =Java 1.8+=).
When using [[doom-package:][langtool]], this module requires [[https://languagetool.org/][LanguageTool]] (which requires =Java
1.8+=).

It is available from either https://languagetool.org/ or your OS's package
manager. E.g.
Expand All @@ -38,6 +43,10 @@ This module tries to guess the location of =languagetool-commandline.jar=. If
you get a warning that Doom ~couldn't find languagetool-commandline.jar~, you
will need to set ~langtool-language-tool-jar~ to its location.

When configured with the [[doom-module:][+lsp]] flag, the [[doom-package:][lsp-ltex]] package will automatically
install the LSP server which comes with bundled with LanguageTool and a Java
distribution.

* TODO Usage
#+begin_quote
🔨 /This module's usage documentation is incomplete./ [[doom-contrib-module:][Complete it?]]
Expand All @@ -52,9 +61,17 @@ stylistic issues in your writing. This requires Java 1.8+.
#+end_quote

*** Commands
**** For [[doom-package:][langtool]] users
- ~M-x langtool-check~
- ~M-x langtool-correct-buffer~

**** For [[doom-package:][lsp-ltex]] users
Doom automatically enables ~lsp-ltex~ for ~text-mode~, ~latex-mode~, ~org-mode~, and
~markdown-mode~.

- Use ~M-x +lsp-ltex-toggle~ or ~SPC localleadr G~ to enable or disable ~lsp-ltex~ in the current
buffer.

** writegood-mode
This minor mode highlights weasel words, duplication and passive voice.

Expand All @@ -63,6 +80,32 @@ This minor mode highlights weasel words, duplication and passive voice.
🔨 This module has no configuration documentation yet. [[doom-contrib-module:][Write some?]]
#+end_quote


** For [[doom-package:][lsp-ltex]] users
You can enhance your LanguageTool experience by customizing ~lsp-ltex~.

#+begin_src emacs-lisp
(setq lsp-ltex-language "fr" ;; Set your default (most used) language
lsp-ltex-mother-tongue "ar") ;; Set your mother longue
#+end_src

LanguageTool can make use of large n-gram data sets to detect errors with words
that are often confused, like /their/ and /there/. The n-gram data set is huge and
thus not part of the LanguageTool package. To make use of it, you have two
choices:

- Download it form [[https://languagetool.org/download/ngram-data/][languagetool.org]]
- Install it from your distribution package manager
- For Arch-based distros, there is AUR packages (~languagetool-ngrams-<lang>~
for languages: en, fr, de, es, he, it, nl, ru or zh.

Doom will automatically use n-grams if found in =/usr/share/ngrams=, however, if
you downloaded them to another directory, you can set the following variable:

#+begin_src emacs-lisp
(setq lsp-ltex-additional-rules-language-model "path/to/ngrams")
#+end_src

* Troubleshooting
/There are no known problems with this module./ [[doom-report:][Report one?]]

Expand Down
66 changes: 66 additions & 0 deletions modules/checkers/grammar/config.el
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
;;; checkers/grammar/config.el -*- lexical-binding: t; -*-

(use-package! langtool
:unless (modulep! +lsp)
:commands (langtool-check
langtool-check-done
langtool-show-message-at-point
Expand All @@ -26,6 +27,71 @@
(setq langtool-java-classpath "/usr/share/languagetool:/usr/share/java/languagetool/*")))))


(use-package! lsp-ltex
:when (modulep! +lsp)
:unless (modulep! :tools lsp +eglot)
:commands (+lsp-ltex-toggle
+lsp-ltex-enable
+lsp-ltex-disable
+lsp-ltex-setup)
:hook ((latex-mode LaTeX-mode org-mode markdown-mode) . #'+lsp-ltex-setup)
:init
;; There is some problematic modes when it comes to enabling LSP
(defvar +lsp-ltex-disabled-modes '(org-msg-edit-mode))
:config
;; Add doom-docs-mode to LSP language IDs
(add-to-list 'lsp-language-id-configuration '(doom-docs-org-mode . "org"))
:init
(setq lsp-ltex-check-frequency "edit"
lsp-ltex-log-level "warning" ;; No need to log everything
lsp-ltex-diagnostic-severity "warning"
;; Path in which, interactively added words and rules will be stored.
lsp-ltex-user-rules-path (expand-file-name "lsp-ltex" doom-data-dir))

;; When n-gram data sets are available, use them to detect errors with words
;; that are often confused (like their and there).
(when (file-directory-p "/usr/share/ngrams")
(setq lsp-ltex-additional-rules-language-model "/usr/share/ngrams"))

(defun +lsp-ltex-setup ()
"Load LTeX LSP server."
(interactive)
(require 'lsp-ltex)
(when (and (+lsp-ltex--enabled-p)
(not (memq major-mode +lsp-ltex-disabled-modes)))
(lsp-deferred)))

(defun +lsp-ltex--enabled-p ()
(not (memq 'ltex-ls lsp-disabled-clients)))

(defun +lsp-ltex-enable ()
"Enable LTeX LSP for the current buffer."
(interactive)
(unless (+lsp-ltex--enabled-p)
(setq-local lsp-disabled-clients (delq 'ltex-ls lsp-disabled-clients))
(message "Enabled ltex-ls"))
(+lsp-ltex-setup))

(defun +lsp-ltex-disable ()
"Disable LTeX LSP for the current buffer."
(interactive)
(when (+lsp-ltex--enabled-p)
(setq-local lsp-disabled-clients (cons 'ltex-ls lsp-disabled-clients))
(lsp-disconnect)
(message "Disabled ltex-ls")))

(defun +lsp-ltex-toggle ()
"Toggle LTeX LSP for the current buffer."
(interactive)
(if (+lsp-ltex--enabled-p)
(+lsp-ltex-disable)
(+lsp-ltex-enable)))

(map! :localleader
:map (text-mode-map latex-mode-map LaTeX-mode-map org-mode-map markdown-mode-map)
:desc "Toggle grammar check" "G" #'+lsp-ltex-toggle))


;; Detects weasel words, passive voice and duplicates. Proselint would be a
;; better choice.
(use-package! writegood-mode
Expand Down
6 changes: 6 additions & 0 deletions modules/checkers/grammar/doctor.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
;; -*- lexical-binding: t; no-byte-compile: t; -*-
;;; checkers/grammar/doctor.el

(assert! (or (not (modulep! +lsp))
(modulep! :tools lsp))
"This module requires (:tools lsp)")
11 changes: 10 additions & 1 deletion modules/checkers/grammar/packages.el
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
;; -*- no-byte-compile: t; -*-
;;; checkers/grammar/packages.el

(package! langtool :pin "8276eccc5587bc12fd205ee58a7a982f0a136e41")
(when (and (modulep! +lsp)
(not (modulep! :tools lsp +eglot)))
(package! lsp-ltex :pin "18b0e8608408f9e913d89075e78c2b4e3f69cf1c")
;; Optional dependency of lsp-ltex, needed for installing/updating ltex-ls LSP server
(package! github-tags
:recipe (:host github
:repo "jcs-elpa/github-tags")
:pin "7b02d6e883ac3d766106de30c60b22609c4515f9"))
(unless (modulep! +lsp)
(package! langtool :pin "8276eccc5587bc12fd205ee58a7a982f0a136e41"))
(package! writegood-mode :pin "ed42d918d98826ad88928b7af9f2597502afc6b0")