From b89992624b95400a6023bb27030d56a9f58d6bd6 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Thu, 9 Jan 2020 18:41:48 -0500 Subject: [PATCH] Move :tools fly{check,spell} to :checkers {syntax,spell} These modules were renamed so we can later generalize their implementations, such as adding flymake support to the syntax checker. --- core/core-modules.el | 4 ++- docs/index.org | 11 +++++--- init.example.el | 6 ++--- modules/checkers/spell/autoload.el | 27 +++++++++++++++++++ .../flyspell => checkers/spell}/config.el | 13 ++++----- .../flyspell => checkers/spell}/packages.el | 2 +- modules/checkers/syntax/autoload.el | 25 +++++++++++++++++ .../flycheck => checkers/syntax}/config.el | 19 +++++++------ .../flycheck => checkers/syntax}/packages.el | 4 ++- modules/tools/flycheck/autoload.el | 13 --------- modules/tools/flyspell/autoload.el | 27 ------------------- modules/tools/flyspell/doctor.el | 4 --- 12 files changed, 83 insertions(+), 72 deletions(-) create mode 100644 modules/checkers/spell/autoload.el rename modules/{tools/flyspell => checkers/spell}/config.el (89%) rename modules/{tools/flyspell => checkers/spell}/packages.el (89%) create mode 100644 modules/checkers/syntax/autoload.el rename modules/{tools/flycheck => checkers/syntax}/config.el (88%) rename modules/{tools/flycheck => checkers/syntax}/packages.el (74%) delete mode 100644 modules/tools/flycheck/autoload.el delete mode 100644 modules/tools/flyspell/autoload.el delete mode 100644 modules/tools/flyspell/doctor.el diff --git a/core/core-modules.el b/core/core-modules.el index 63be64585..b77a2a8f0 100644 --- a/core/core-modules.el +++ b/core/core-modules.el @@ -24,7 +24,9 @@ (debugger (:tools debugger))) (:tools (rotate-text (:editor rotate-text)) (vterm (:term vterm)) - (password-store (:tools pass))) + (password-store (:tools pass)) + (flycheck (:checker syntax)) + (flyspell (:checker spell))) (:emacs (electric-indent (:emacs electric)) (hideshow (:editor fold)) (eshell (:term eshell)) diff --git a/docs/index.org b/docs/index.org index 32a4b7737..2f5f9104b 100644 --- a/docs/index.org +++ b/docs/index.org @@ -107,8 +107,13 @@ loaded last, before =:config= modules. + [[file:../modules/app/irc/README.org][irc]] - how neckbeards socialize + rss =+org= - an RSS client in Emacs + [[file:../modules/app/twitter/README.org][twitter]] - A twitter client for Emacs -+ [[file:../modules/app/write/README.org][write]] =+wordnut +langtool= - Transforms emacs into an IDE for writers, and for - writing fiction, notes, papers and so on. + +** :checkers +Modules dedicated to linting or checking your code or writing for issues. + ++ syntax =+childframe= - Live error/warning highlights ++ spell =+everywhere= - Spell checking ++ grammar - TODO ** :completion Modules that provide new interfaces or frameworks for completion, including code @@ -234,8 +239,6 @@ Small modules that give Emacs access to external tools & services. + [[file:../modules/tools/editorconfig/README.org][editorconfig]] - TODO + [[file:../modules/tools/ein/README.org][ein]] - TODO + [[file:../modules/tools/eval/README.org][eval]] =+overlay= - REPL & code evaluation support for a variety of languages -+ flycheck - Live error/warning highlights -+ flyspell =+everywhere= - Spell checking + gist - TODO + [[file:../modules/tools/lookup/README.org][lookup]] =+dictionary +docsets= - Universal jump-to & documentation lookup backend diff --git a/init.example.el b/init.example.el index f542b4e91..7fc2f63f9 100644 --- a/init.example.el +++ b/init.example.el @@ -77,7 +77,9 @@ ;;vterm ; another terminals in Emacs :checkers - ;;grammar + syntax ; tasing you for every semicolon you forget + ;;spell ; tasing you for misspelling mispelling + ;;grammar ; tasing grammar mistake every you make :tools ;;ansible @@ -87,8 +89,6 @@ ;;editorconfig ; let someone else argue about tabs vs spaces ;;ein ; tame Jupyter notebooks with emacs (eval +overlay) ; run code, run (also, repls) - flycheck ; tasing you for every semicolon you forget - ;;flyspell ; tasing you for misspelling mispelling ;;gist ; interacting with github gists (lookup ; helps you navigate your code and documentation +docsets) ; ...or in Dash docsets locally diff --git a/modules/checkers/spell/autoload.el b/modules/checkers/spell/autoload.el new file mode 100644 index 000000000..0674dc5c1 --- /dev/null +++ b/modules/checkers/spell/autoload.el @@ -0,0 +1,27 @@ +;;; checkers/spell/autoload.el -*- lexical-binding: t; -*- + +;;;###autodef +(defalias 'flyspell-mode! #'flyspell-mode) + +(defvar +spell--flyspell-predicate-alist nil + "TODO") + +;;;###autodef +(defun set-flyspell-predicate! (modes predicate) + "TODO" + (declare (indent defun)) + (dolist (mode (doom-enlist modes) +spell--flyspell-predicate-alist) + (add-to-list '+spell--flyspell-predicate-alist (cons mode predicate)))) + +;;;###autoload +(defun +spell-init-flyspell-predicate-h () + "TODO" + (when-let (pred (assq major-mode +spell--flyspell-predicate-alist)) + (setq-local flyspell-generic-check-word-predicate (cdr pred)))) + +;;;###autoload +(defun +spell-correction-at-point-p (&optional point) + "TODO" + (cl-loop for ov in (overlays-at (or point (point))) + if (overlay-get ov 'flyspell-overlay) + return t)) diff --git a/modules/tools/flyspell/config.el b/modules/checkers/spell/config.el similarity index 89% rename from modules/tools/flyspell/config.el rename to modules/checkers/spell/config.el index 3636d8c0c..b1a95e747 100644 --- a/modules/tools/flyspell/config.el +++ b/modules/checkers/spell/config.el @@ -1,7 +1,4 @@ -;;; tools/flyspell/config.el -*- lexical-binding: t; -*- - -;; -;;; Packages +;;; checkers/spell/config.el -*- lexical-binding: t; -*- (defvar ispell-dictionary "en_US") @@ -28,10 +25,10 @@ ispell-extra-args '("--sug-mode=ultra" "--run-together")) (add-hook! 'text-mode-hook - (defun +flyspell-remove-run-together-switch-for-aspell-h () + (defun +spell-remove-run-together-switch-for-aspell-h () (setq-local ispell-extra-args (remove "--run-together" ispell-extra-args)))) - (defun +flyspell-setup-ispell-extra-args-a (orig-fun &rest args) + (defun +spell-init-ispell-extra-args-a (orig-fun &rest args) :around '(ispell-word flyspell-auto-correct-word) (let ((ispell-extra-args (remove "--run-together" ispell-extra-args))) (ispell-kill-ispell t) @@ -57,7 +54,7 @@ #'flyspell-prog-mode)) (add-hook! 'flyspell-mode-hook - (defun +flyspell-inhibit-duplicate-detection-maybe-h () + (defun +spell-inhibit-duplicate-detection-maybe-h () "Don't mark duplicates when style/grammar linters are present. e.g. proselint and langtool." (when (or (and (bound-and-true-p flycheck-mode) @@ -67,7 +64,7 @@ e.g. proselint and langtool." ;; Ensure mode-local predicates declared with `set-flyspell-predicate!' are ;; used in their respective major modes. - (add-hook 'flyspell-mode-hook #'+flyspell-init-predicate-h) + (add-hook 'flyspell-mode-hook #'+spell-init-flyspell-predicate-h) (map! :map flyspell-mouse-map "RET" #'flyspell-correct-at-point diff --git a/modules/tools/flyspell/packages.el b/modules/checkers/spell/packages.el similarity index 89% rename from modules/tools/flyspell/packages.el rename to modules/checkers/spell/packages.el index efb81d804..a60738087 100644 --- a/modules/tools/flyspell/packages.el +++ b/modules/checkers/spell/packages.el @@ -1,5 +1,5 @@ ;; -*- no-byte-compile: t; -*- -;;; tools/flyspell/packages.el +;;; checkers/spell/packages.el (package! flyspell-correct) (cond ((featurep! :completion ivy) diff --git a/modules/checkers/syntax/autoload.el b/modules/checkers/syntax/autoload.el new file mode 100644 index 000000000..4dc963572 --- /dev/null +++ b/modules/checkers/syntax/autoload.el @@ -0,0 +1,25 @@ +;;; checkers/syntax/autoload.el -*- lexical-binding: t; -*- + +;;;###autodef +(defun set-next-checker! (mode checker next &optional append) + "TODO" + (let ((fn (intern (format "+syntax--init-checkers-for-%s-h" mode)))) + (fset fn + (lambda () + (if (not (bound-and-true-p flycheck-mode)) + (add-hook 'flycheck-mode-hook fn 'append 'local) + (flycheck-add-next-checker checker next append) + (remove-hook 'flycheck-mode-hook fn 'local)))) + (add-hook (intern (format "%s-hook" mode)) fn))) + +;;;###autoload +(defun +syntax-init-popups-h () + "Activate `flycheck-posframe-mode' if available and in GUI Emacs. +Activate `flycheck-popup-tip-mode' otherwise. +Do nothing if `lsp-ui-mode' is active and `lsp-ui-sideline-enable' is non-nil." + (unless (and (bound-and-true-p lsp-ui-mode) + lsp-ui-sideline-enable) + (if (and (fboundp 'flycheck-posframe-mode) + (display-graphic-p)) + (flycheck-posframe-mode +1) + (flycheck-popup-tip-mode +1)))) diff --git a/modules/tools/flycheck/config.el b/modules/checkers/syntax/config.el similarity index 88% rename from modules/tools/flycheck/config.el rename to modules/checkers/syntax/config.el index 060f971cc..b91df9195 100644 --- a/modules/tools/flycheck/config.el +++ b/modules/checkers/syntax/config.el @@ -1,12 +1,7 @@ -;;; tools/flycheck/config.el -*- lexical-binding: t; -*- - -(defvar +flycheck-lazy-idle-delay 3.0 - "The delay before flycheck checks the buffer, after a check that produces no -errors.") - +;;; checkers/syntax/config.el -*- lexical-binding: t; -*- ;; -;;; Packages +;;; Flycheck (use-package! flycheck :commands flycheck-list-errors flycheck-buffer @@ -27,7 +22,7 @@ errors.") (set-popup-rule! "^\\*Flycheck error messages\\*" :select nil) (add-hook! 'doom-escape-hook :append - (defun +flycheck-buffer-h () + (defun +syntax-check-buffer-h () "Flycheck buffer on ESC in normal mode." (when flycheck-mode (ignore-errors (flycheck-buffer)) @@ -46,7 +41,7 @@ errors.") (use-package! flycheck-popup-tip :commands flycheck-popup-tip-show-popup flycheck-popup-tip-delete-popup - :init (add-hook 'flycheck-mode-hook #'+flycheck-init-popups-h) + :init (add-hook 'flycheck-mode-hook #'+syntax-init-popups-h) :config (setq flycheck-popup-tip-error-prefix "✕ ") (after! evil @@ -54,7 +49,7 @@ errors.") ;; the cursor's position or cause disruptive input delays. (add-hook! '(evil-insert-state-entry-hook evil-replace-state-entry-hook) #'flycheck-popup-tip-delete-popup) - (defadvice! +flycheck--disable-popup-tip-maybe-a (&rest _) + (defadvice! +syntax--disable-flycheck-popup-tip-maybe-a (&rest _) :before-while #'flycheck-popup-tip-show-popup (if evil-local-mode (eq evil-state 'normal) @@ -78,3 +73,7 @@ errors.") (add-hook! 'flycheck-posframe-inhibit-functions #'evil-insert-state-p #'evil-replace-state-p))) + + +;; +;;; TODO Flymake diff --git a/modules/tools/flycheck/packages.el b/modules/checkers/syntax/packages.el similarity index 74% rename from modules/tools/flycheck/packages.el rename to modules/checkers/syntax/packages.el index b9bcdfd82..5ce8c3f0f 100644 --- a/modules/tools/flycheck/packages.el +++ b/modules/checkers/syntax/packages.el @@ -1,7 +1,9 @@ ;; -*- no-byte-compile: t; -*- -;;; tools/flycheck/packages.el +;;; checkers/syntax/packages.el (package! flycheck) (package! flycheck-popup-tip) (when (featurep! +childframe) (package! flycheck-posframe)) + +;; TODO flymake? diff --git a/modules/tools/flycheck/autoload.el b/modules/tools/flycheck/autoload.el deleted file mode 100644 index 4f3ea2929..000000000 --- a/modules/tools/flycheck/autoload.el +++ /dev/null @@ -1,13 +0,0 @@ -;;; tools/flycheck/autoload.el -*- lexical-binding: t; -*- - -;;;###autoload -(defun +flycheck-init-popups-h () - "Activate `flycheck-posframe-mode' if available and in GUI Emacs. -Activate `flycheck-popup-tip-mode' otherwise. -Do nothing if `lsp-ui-mode' is active and `lsp-ui-sideline-enable' is non-nil." - (unless (and (bound-and-true-p lsp-ui-mode) - lsp-ui-sideline-enable) - (if (and (fboundp 'flycheck-posframe-mode) - (display-graphic-p)) - (flycheck-posframe-mode +1) - (flycheck-popup-tip-mode +1)))) diff --git a/modules/tools/flyspell/autoload.el b/modules/tools/flyspell/autoload.el deleted file mode 100644 index e33ab0df4..000000000 --- a/modules/tools/flyspell/autoload.el +++ /dev/null @@ -1,27 +0,0 @@ -;;; tools/flyspell/autoload.el -*- lexical-binding: t; -*- - -;;;###autodef -(defalias 'flyspell-mode! #'flyspell-mode) - -(defvar +flyspell--predicate-alist nil - "TODO") - -;;;###autodef -(defun set-flyspell-predicate! (modes predicate) - "TODO" - (declare (indent defun)) - (dolist (mode (doom-enlist modes) +flyspell--predicate-alist) - (add-to-list '+flyspell--predicate-alist (cons mode predicate)))) - -;;;###autoload -(defun +flyspell-init-predicate-h () - "TODO" - (when-let (pred (assq major-mode +flyspell--predicate-alist)) - (setq-local flyspell-generic-check-word-predicate (cdr pred)))) - -;;;###autoload -(defun +flyspell-correction-at-point-p (&optional point) - "TODO" - (cl-loop for ov in (overlays-at (or point (point))) - if (overlay-get ov 'flyspell-overlay) - return t)) diff --git a/modules/tools/flyspell/doctor.el b/modules/tools/flyspell/doctor.el deleted file mode 100644 index 9d1cb3286..000000000 --- a/modules/tools/flyspell/doctor.el +++ /dev/null @@ -1,4 +0,0 @@ - -(unless (or (executable-find "aspell") - (executable-find "hunspell")) - (warn! "Could not find aspell or hunspell. Flyspell will fall back to ispell, which may not work."))