checkers/spell: add add/remove word & next/prev error commands

So both spell-fu and flyspell users have a more consistent interface.
This commit is contained in:
Henrik Lissner 2020-09-02 13:58:27 -04:00
parent 5de263f6a4
commit 91c1e705e6
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
4 changed files with 66 additions and 9 deletions

View file

@ -26,3 +26,57 @@
(cl-loop for ov in (overlays-at (or point (point)))
if (overlay-get ov 'flyspell-overlay)
return t))
;;;###autoload
(defun +spell/add-word (word &optional scope)
"Add WORD to your personal dictionary, within SCOPE.
SCOPE can be `buffer' or `session' to exclude words only from the current buffer
or session. Otherwise, the addition is permanent."
(interactive
(list (progn (require 'flyspell)
(flyspell-get-word))))
(require 'flyspell)
(cond
((null scope)
(ispell-send-string (concat "*" word "\n"))
(ispell-send-string "#\n")
(flyspell-unhighlight-at (point))
(setq ispell-pdict-modified-p '(t)))
((memq scope '(buffer session))
(ispell-send-string (concat "@" word "\n"))
(add-to-list 'ispell-buffer-session-localwords word)
(or ispell-buffer-local-name ; session localwords might conflict
(setq ispell-buffer-local-name (buffer-name)))
(flyspell-unhighlight-at (point))
(if (null ispell-pdict-modified-p)
(setq ispell-pdict-modified-p
(list ispell-pdict-modified-p)))
(if (eq replace 'buffer)
(ispell-add-per-file-word-list word))))
(ispell-pdict-save t))
;;;###autoload
(defun +spell/remove-word (word &optional _scope)
"Remove WORD from your personal dictionary."
(interactive)
(user-error "Not supported yet with +flyspell"))
;;;###autoload
(defun +spell/next-error ()
"Jump to next flyspell error."
(interactive)
(call-interactively
(if (featurep 'evil)
#'evil-next-flyspell-error
#'flyspell-goto-next-error)))
;;;###autoload
(defun +spell/previous-error ()
"Jump to previous flyspell error."
(interactive)
(call-interactively
(if (featurep 'evil)
#'evil-prev-flyspell-error
;; TODO Implement this
(user-error "Not supported"))))

View file

@ -105,3 +105,8 @@
(unless (string-equal wrd word)
(+spell--correct wrd poss word orig-pt start end))))))
(ispell-pdict-save t)))))))
;;;###autoload (defalias '+spell/add-word #'spell-fu-word-add)
;;;###autoload (defalias '+spell/remove-word #'spell-fu-word-remove)
;;;###autoload (defalias '+spell/next-error #'spell-fu-goto-next-error)
;;;###autoload (defalias '+spell/previous-error #'spell-fu-goto-previous-error)