Skip to content

Commit 8b1f4fc

Browse files
committed
Add "zg" and "zG" bindings
Implements evil-ispell-mark-word-as-good and evil-ispell-mark-word-as-locally-good
1 parent 070abb1 commit 8b1f4fc

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

evil-commands.el

+36
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
(require 'evil-jumps)
3434
(require 'evil-vars)
3535
(require 'flyspell)
36+
(require 'ispell)
3637
(require 'cl-lib)
3738
(require 'reveal)
3839

@@ -636,6 +637,41 @@ and jump to the corresponding one."
636637
(when ov
637638
(goto-char (overlay-start ov))))))))
638639

640+
(defun evil-ispell-mark-word-as-good (word &optional buffer-local)
641+
"Add WORD under the cursor as a good word to the Ispell dictionary.
642+
If BUFFER-LOCAL is non-nil, the word will be added to current buffer."
643+
(interactive (list (thing-at-point 'word) current-prefix-arg))
644+
(cond
645+
((null buffer-local)
646+
;; accept and insert word into personal dictionary.
647+
(ispell-send-string (concat "*" word "\n"))
648+
;; dictionary modified!
649+
(setq ispell-pdict-modified-p '(t))
650+
(ispell-pdict-save ispell-silently-savep)
651+
(message "Word '%s' added to personal dictionary" (upcase word)))
652+
(t
653+
(ispell-add-per-file-word-list word)
654+
(message "Word '%s' added to local word list" (upcase word))))
655+
(when (bound-and-true-p flyspell-mode)
656+
(let ((start (car (bounds-of-thing-at-point 'word))))
657+
(when start
658+
(flyspell-unhighlight-at start)))))
659+
660+
(defun evil-ispell-mark-word-as-locally-good (word)
661+
"Add WORD under the cursor to the session dictionary."
662+
(interactive (list (thing-at-point 'word)))
663+
;; accept word without insertion
664+
(ispell-send-string (concat "@" word "\n"))
665+
(add-to-list 'ispell-buffer-session-localwords word)
666+
;; session localwords might conflict.
667+
(unless ispell-buffer-local-name
668+
(setq ispell-buffer-local-name (buffer-name)))
669+
(when (bound-and-true-p flyspell-mode)
670+
(let ((start (car (bounds-of-thing-at-point 'word))))
671+
(when start
672+
(flyspell-unhighlight-at start))))
673+
(message "Word '%s' added to session dictionary" (upcase word)))
674+
639675
(evil-define-motion evil-next-flyspell-error (count)
640676
"Go to the COUNT'th spelling mistake after point."
641677
(interactive "p")

evil-maps.el

+2
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@
8282
(define-key evil-normal-state-map "za" 'evil-toggle-fold)
8383
(define-key evil-normal-state-map "zr" 'evil-open-folds)
8484
(define-key evil-normal-state-map "zm" 'evil-close-folds)
85+
(define-key evil-normal-state-map "zg" 'evil-ispell-mark-word-as-good)
86+
(define-key evil-normal-state-map "zG" 'evil-ispell-mark-word-as-locally-good)
8587
(define-key evil-normal-state-map "z=" 'ispell-word)
8688
(define-key evil-normal-state-map "\C-n" 'evil-paste-pop-next)
8789
(define-key evil-normal-state-map "\C-p" 'evil-paste-pop)

0 commit comments

Comments
 (0)