From 452a858fe4d70ec3521687dcbd1a8270f51b6f37 Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Wed, 25 Apr 2012 00:08:33 +0200 Subject: emacs: globally disable flyspell, but activate it if needed flyspell-mode is no more enabled in all the different major-modes, if you need it you could enable it with automatic variables on file level with this at top of an file as comment: -*- flyspell-dict: "german" -*- --- emacs | 94 ++++++++++++++++++++++++++++++++----------------------------------- 1 file changed, 45 insertions(+), 49 deletions(-) (limited to 'emacs') diff --git a/emacs b/emacs index 813bcaa..c22764e 100644 --- a/emacs +++ b/emacs @@ -127,55 +127,51 @@ (doxymacs-font-lock))))) ;; flyspell (with aspell for Unicode) -(setq ispell-program-name "aspell") -(setq ispell-extra-args '("--sug-mode=ultra")) - -(add-hook 'c-mode-hook 'flyspell-prog-mode) -(add-hook 'sh-mode-hook 'flyspell-prog-mode) -(add-hook 'c++-mode-hook 'flyspell-prog-mode) -(add-hook 'ruby-mode-hook 'flyspell-prog-mode) -(add-hook 'cperl-mode-hook 'flyspell-prog-mode) -(add-hook 'python-mode-hook 'flyspell-prog-mode) -(add-hook 'autoconf-mode-hook 'flyspell-prog-mode) -(add-hook 'autotest-mode-hook 'flyspell-prog-mode) -(add-hook 'makefile-mode-hook 'flyspell-prog-mode) -(add-hook 'emacs-lisp-mode-hook 'flyspell-prog-mode) - -(add-hook 'tex-mode-hook (function (lambda () (setq ispell-parser 'tex)))) -(add-hook 'texinfo-mode - '(lambda () (setq flyspell-generic-check-word-p - 'texinfo-mode-flyspell-verify))) - -(add-hook 'text-mode-hook (lambda () (flyspell-mode 1))) -(add-hook 'change-log-mode-hook (lambda () (flyspell-mode 1))) - -(add-hook 'flyspell-mode-hook 'flyspell-buffer) - -; ignore all #include stings -(add-hook 'flyspell-incorrect-hook - (lambda (left right undef) - (save-excursion - (goto-char left) - (beginning-of-line) - (if (looking-at "#include") - 't - 'nil) - ))) - -; change dictionary -(defun switch-dictionary() - (interactive) - (let* ((dic ispell-current-dictionary) - (change (if (string= dic "german") "english" "german"))) - (ispell-change-dictionary change) - (message "Dictionary switched from %s to %s" dic change) - (if flyspell-mode (save-excursion (flyspell-buffer))))) -(global-set-key (kbd "") 'switch-dictionary) - -; update flyspell after changing dictionary -(defadvice ispell-pdict-save (after advice) - (save-excursion (flyspell-buffer))) -(ad-activate 'ispell-pdict-save t) +(setq ispell-program-name "aspell" + ispell-extra-args '("--sug-mode=ultra")) + +;; define variable to store default dictionary for automatic flyspell enabling +(defvar flyspell-dict nil "Dictionary name, that should be set during find-file for flyspell-mode. +If this is set during find-file, flyspell mode gets enabled automaticaly.") +(make-variable-buffer-local 'flyspell-dict) + +(when (require 'ispell nil 'noerror) + ;; change dictionary + (defun switch-dictionary() + (interactive) + (let* ((dic ispell-current-dictionary) + (change (if (string= dic "german") "english" "german"))) + (ispell-change-dictionary change) + (message "Dictionary switched from %s to %s" dic change) + (if flyspell-mode (save-excursion (flyspell-buffer))))) + (global-set-key (kbd "") 'switch-dictionary) + + (when (require 'flyspell nil 'noerror) + ;; check buffer if enable flyspell + (add-hook 'flyspell-mode-hook + (lambda () + (when flyspell-mode (flyspell-buffer)))) + + ;; ignore all #include stings + (add-hook 'flyspell-incorrect-hook + (lambda (left right undef) + (save-excursion + (goto-char left) + (beginning-of-line) + (if (looking-at "#include") t nil)))) + + ;; activate flyspell mode during find-file if flyspell-dict is set + (add-hook 'find-file-hook + (lambda () + (when flyspell-dict + (ispell-change-dictionary flyspell-dict) + (flyspell-mode t)))) + + ;; update flyspell after changing personal dictionary + (defadvice ispell-pdict-save (after advice) + (save-excursion (flyspell-buffer))) + (ad-activate 'ispell-pdict-save t))) + ;; auto compile files (require 'self-compile-mode) -- cgit v1.2.3