From dbfc184f0bb8c83e507a18e58c11ef25894e977d Mon Sep 17 00:00:00 2001 From: KemoNine Date: Thu, 25 Aug 2022 20:05:52 -0400 Subject: [PATCH] re-enable flyspell with helm integration --- common/_global.el | 87 +++++++++++++++++++++++++++-------------------- 1 file changed, 50 insertions(+), 37 deletions(-) diff --git a/common/_global.el b/common/_global.el index f0dba04..34cfb2d 100644 --- a/common/_global.el +++ b/common/_global.el @@ -395,40 +395,53 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; flyspell -;(require 'flyspell) -;(setenv "LANG" "en_US") -;(setenv "DICPATH" "~/.emacs.d.profiles/common/dictionaries") ; https://github.com/wooorm/dictionaries -;(setq ispell-program-name "hunspell") -;(setq ispell-dictionary "en_US") -; -;(global-set-key (kbd "C-c y") 'flyspell-toggle ) -; -;(defun flyspell-on-for-buffer-type () -; "Enable Flyspell appropriately for the major mode of the current buffer. Uses `flyspell-prog-mode' for modes derived from `prog-mode', so only strings and comments get checked. All other buffers get `flyspell-mode' to check all text. If flyspell is already enabled, does nothing." -; (interactive) -; (if (not (symbol-value flyspell-mode)) ; if not already on -; (progn -; (if (derived-mode-p 'prog-mode) -; (progn -; (message "Flyspell on (code)") -; (flyspell-prog-mode)) -; ;; else -; (progn -; (message "Flyspell on (text)") -; (flyspell-mode 1))) -; ;; I tried putting (flyspell-buffer) here but it didn't seem to work -; ))) -; -; (defun flyspell-toggle () -; "Turn Flyspell on if it is off, or off if it is on. When turning on, it uses `flyspell-on-for-buffer-type' so code-vs-text is handled appropriately." -; (interactive) -; (if (symbol-value flyspell-mode) -; (progn ; flyspell is on, turn it off -; (message "Flyspell off") -; (flyspell-mode -1)) -; ; else - flyspell is off, turn it on -; (flyspell-on-for-buffer-type))) -; -;(add-hook 'find-file-hook 'flyspell-on-for-buffer-type) -;(add-hook 'text-mode-hook 'flyspell-on-for-buffer-type) -;(add-hook 'after-change-major-mode-hook 'flyspell-on-for-buffer-type) +(require 'flyspell) +(setenv "LANG" "en_US") +(setq ispell-program-name "hunspell") +(setq ispell-dictionary "en_US") +(use-package flyspell :demand t + :config + (use-package + flyspell-correct-helm) + (defun flyspellCompletion() + (flyspell-mode 1) + (set (make-local-variable 'company-backends) + (copy-tree company-backends)) + (add-to-list 'company-backends 'company-ispell)) + (defun flyspell-most-modes() + (add-hook 'text-mode-hook 'flyspellCompletion) + (add-hook 'prog-mode-hook 'flyspellCompletion) + (dolist (hook '(change-log-mode-hook log-edit-mode-hook)) + (add-hook hook (lambda () + (flyspell-mode -1))))) + (flyspell-most-modes) +) + +(defun flyspell-on-for-buffer-type () + "Enable Flyspell appropriately for the major mode of the current buffer. Uses `flyspell-prog-mode' for modes derived from `prog-mode', so only strings and comments get checked. All other buffers get `flyspell-mode' to check all text. If flyspell is already enabled, does nothing." + (interactive) + (if (not (symbol-value flyspell-mode)) ; if not already on + (progn + (if (derived-mode-p 'prog-mode) + (progn + (message "Flyspell on (code)") + (flyspell-prog-mode)) + ;; else + (progn + (message "Flyspell on (text)") + (flyspell-mode 1))) + ;; I tried putting (flyspell-buffer) here but it didn't seem to work + ))) +(defun flyspell-toggle () + "Turn Flyspell on if it is off, or off if it is on. When turning on, it uses `flyspell-on-for-buffer-type' so code-vs-text is handled appropriately." + (interactive) + (if (symbol-value flyspell-mode) + (progn ; flyspell is on, t it off + (message "Flyspell off") + (flyspell-mode -1)) + ; else - flyspell is off, turn it on + (flyspell-on-for-buffer-type))) + +; flyspell keyboard shortcuts +(global-set-key (kbd "C-x y") 'flyspell-toggle) +(global-set-key (kbd "C-x w") 'flyspell-correct-wrapper)