Skip to content

Commit

Permalink
Add avoidance rules
Browse files Browse the repository at this point in the history
  • Loading branch information
jcs090218 committed Aug 14, 2021
1 parent abab9e6 commit 5568fea
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions flycheck-grammarly.el
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
;; Description: Grammarly support for Flycheck.
;; Keyword: grammar check
;; Version: 0.2.3
;; Package-Requires: ((emacs "25.1") (flycheck "0.14") (grammarly "0.3.0"))
;; Package-Requires: ((emacs "25.1") (flycheck "0.14") (grammarly "0.3.0") (s "1.12.0"))
;; URL: https://github.com/emacs-grammarly/flycheck-grammarly

;; This file is NOT part of GNU Emacs.
Expand Down Expand Up @@ -38,6 +38,7 @@

(require 'flycheck)
(require 'grammarly)
(require 's)

(defgroup flycheck-grammarly nil
"Grammarly support for Flycheck."
Expand All @@ -56,6 +57,12 @@
:type 'float
:group 'flycheck-grammarly)

(defconst flycheck-grammarly--avoidance-rule
'((":" . "\n"))
"Replace character to another character to avoid from Grammarly API.
See #3.")

(defvar flycheck-grammarly--show-debug-message nil
"Show the debug message from this package.")

Expand Down Expand Up @@ -185,11 +192,17 @@
check-list)))
check-list))

(defun flycheck-grammarly--apply-avoidance-rule (str)
"Apply avoidance rule to STR."
(dolist (rule flycheck-grammarly--avoidance-rule)
(setq str (s-replace (car rule) (cdr rule) str)))
str)

(defun flycheck-grammarly--grammar-check ()
"Grammar check once."
(unless flycheck-grammarly--done-checking
(flycheck-grammarly--reset-request)
(grammarly-check-text (buffer-string))))
(grammarly-check-text (flycheck-grammarly--apply-avoidance-rule (buffer-string)))))

(defun flycheck-grammarly--start (checker callback)
"Flycheck start function for CHECKER, invoking CALLBACK."
Expand Down

0 comments on commit 5568fea

Please sign in to comment.