;;; -*- lexical-binding: t -*- ;; ;; this file: ;; https://dataswamp.org/~incal/emacs-init/spell.el ;; ;; Debian bug: ;; ispell-init-process: Illegal format hash table ;; /usr/lib/ispell/svenska.hash - expected magic2 0x9602, got 0x414c ;; $ sudo buildhash /usr/share/dict/svenska \ ;; /usr/lib/ispell/svenska.aff \ ;; /usr/lib/ispell/svenska.hash ;; ;; user-local supplemental lists: ;; ~/.ispell_american-insane ;; ~/.ispell_svenska (require 'cl-lib) (require 'dwim) (require 'ispell) (when (eq system-type 'gnu/linux) (load-file "/usr/share/dictionaries-common/site-elisp/debian-ispell.el") (load-file "/var/cache/dictionaries-common/emacsen-ispell-dicts.el") ) (setq ispell-program-name "ispell") (setq ispell-silently-savep t) ;; single word (defun spell-word-2 (word) (and (ispell-lookup-words word) t) ) ;; (spell-word-2 "length") ; t ;; (spell-word-2 "lenght") ; nil (defun spell-word (word) (with-temp-buffer (save-excursion (insert word) ) (condition-case nil (not (ispell-word)) (error nil) ))) ;; (spell-word "length") ; t ;; (spell-word "lenght") ; nil (defun spell-this-word (dict) "`ispell-word' the word with DICT." (ispell-change-dictionary dict) (ispell-word) ) (let ((eng-dict "american-insane")) (defun spell-english () (interactive) (spell eng-dict) ) (defun word () (interactive) (spell-this-word eng-dict) )) ;; test: hello / hxlle (let ((swe-dict "svenska")) (defun spell-swedish () (interactive) (spell swe-dict) ) (defun ord () (interactive) (spell-this-word swe-dict) )) ;; test: hej / hxj ;; buffer / whole / dwim (defun is-code () (member major-mode '(c++-mode c-mode emacs-lisp-mode prolog-mode python-mode sh-mode Shell-script-mode) )) ; add more ... (defun is-message () (eq major-mode 'message-mode) ) (defun spell (dict) "Spell with DICT. If region is active, use `ispell-region'; if editing code, `ispell-comments-and-strings'; if writing a message, `ispell-message'; else, `ispell-buffer'" (ispell-change-dictionary dict) (save-window-excursion (save-excursion (cond ((use-region-p) (ispell-region (region-beginning) (region-end))) ((is-message) (ispell-message)) ((is-code) (ispell-comments-and-strings)) ( (ispell-buffer)) )))) (provide 'spell)