Skip to content

Commit

Permalink
tweak(natural-langs): use jinx if available or fallback to spell-fu
Browse files Browse the repository at this point in the history
  • Loading branch information
abougouffa committed Jan 4, 2024
1 parent 6014efa commit 153cbd0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
37 changes: 27 additions & 10 deletions modules/me-natural-langs.el
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,34 @@
(use-package jinx
:straight t
:when (+emacs-features-p 'modules)
:autoload jinx--load-module
:init
(+map! "ts" #'jinx-mode)
(+nvmap! "z=" #'jinx-correct)
;; Module compilation with libenchant should be easy on Linux, BSD and Mac OS,
;; and on Windows when the installation is done using MSYS2. When Emacs flavor
;; is MinGW, do not setup the hook by default.
(when (or os/linux os/bsd os/mac (and os/win (string-suffix-p "msys" system-configuration)))
(add-hook 'text-mode-hook #'jinx-mode)))

(unless (+emacs-features-p 'modules)
(+load minemacs-modules-dir "obsolete/me-spell-fu.el"))
(defun +jinx-load-module ()
"Try to compile and load the jinx module and fail silently."
(condition-case nil (jinx--load-module) (error nil) (:success t))))

(+load minemacs-obsolete-modules-dir "me-spell-fu.el")

(defun +spellcheck-correct ()
"Correct word at point."
(interactive)
(cond ((bound-and-true-p jinx-mode) (call-interactively #'jinx-correct))
((bound-and-true-p spell-fu-mode) (call-interactively #'+spell-fu-correct))))

(defun +spellcheck-mode ()
"Toggle spellchecking."
(interactive)
(cond ((and (fboundp 'jinx-mode) (+jinx-load-module))
(jinx-mode (if (bound-and-true-p jinx-mode) -1 1)))
((and (fboundp 'spell-fu-mode))
(spell-fu-mode (if (bound-and-true-p spell-fu-mode) -1 1)))
(t ; Fallback to builtin `flyspell'
(flyspell-mode (if (bound-and-true-p flyspell-mode) -1 1)))))

(+map! "ts" #'+spellcheck-mode)
(+nvmap! "z=" #'+spellcheck-correct)

(add-hook #'text-mode-hook #'+spellcheck-mode)

(use-package go-translate
:straight (:host github :repo "lorniu/go-translate")
Expand Down
3 changes: 0 additions & 3 deletions modules/obsolete/me-spell-fu.el
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@
(use-package spell-fu
:straight t
:when (executable-find "aspell")
:hook (text-mode . spell-fu-mode)
:hook (spell-fu-mode . +spell-fu--init-excluded-faces-h)
:custom
(spell-fu-directory (+directory-ensure minemacs-local-dir "spell-fu/"))
(spell-fu-word-delimit-camel-case t)
:init
(+map! "ts" #'spell-fu-mode)
(+nvmap! "z=" #'+spell-fu-correct) ; autoloaded from `me-spell-fu'
(defmacro +spell-fu-register-dictionaries! (&rest langs)
"Register dictionaries for `LANGS` to spell-fu's multi-dict."
(with-eval-after-load 'spell-fu
Expand Down

0 comments on commit 153cbd0

Please sign in to comment.