;;; -*- lexical-binding: t -*- ;;; ;;; this file: ;;; http://user.it.uu.se/~embe8573/emacs-init/spell-new.el ;;; https://dataswamp.org/~incal/emacs-init/spell-new.el (require 'ispell) ;; (ispell-change-dictionary "american") (setq ispell-program-name "ispell") (setq ispell-silently-savep t) (setq ispell-skip-region-alist (nconc ispell-skip-region-alist (list '("`" . "\\(`\\|'\\)"))) ) ;; dicts (defvar eng-dict) (setq eng-dict "american") (defvar swe-dict) (setq swe-dict "svenska") ;; from Lisp / single word (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 ;; buffer / single word (defun spell-this-word (dict) "`ispell-word' the preceding word with DICT." (ispell-change-dictionary dict) (ispell-word) ) (defun word () (interactive) (spell-this-word eng-dict) ) ;; test: hello / hxllo (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. \nIf a region, use `ispell-region' \nIf editing code, `ispell-comments-and-strings' \nIf writng a message, `ispell-message' \nelse, `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)) (t (ispell-buffer)) )))) (defun spell-swedish () (interactive) (spell swe-dict) ) (defun spell-english () (interactive) (spell eng-dict)) (provide 'spell-new)