summaryrefslogtreecommitdiffstats
path: root/emacs
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2012-04-25 00:08:33 +0200
committerAlexander Sulfrian <alexander@sulfrian.net>2012-04-25 00:15:23 +0200
commit452a858fe4d70ec3521687dcbd1a8270f51b6f37 (patch)
tree598d8d9ec66b9f817d000f95ff40c0d357a98f17 /emacs
parent5e256dad163c14410813b639316f806b1a254ff5 (diff)
downloaddotfiles-452a858fe4d70ec3521687dcbd1a8270f51b6f37.tar.gz
dotfiles-452a858fe4d70ec3521687dcbd1a8270f51b6f37.tar.xz
dotfiles-452a858fe4d70ec3521687dcbd1a8270f51b6f37.zip
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" -*-
Diffstat (limited to 'emacs')
-rw-r--r--emacs94
1 files changed, 45 insertions, 49 deletions
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 "<f8>") '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 "<f8>") '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)