[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/typescript-mode 7172a23d86 072/222: Add a custom predicate
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/typescript-mode 7172a23d86 072/222: Add a custom predicate for flyspell-prog-mode. |
Date: |
Sun, 6 Feb 2022 16:59:18 -0500 (EST) |
branch: elpa/typescript-mode
commit 7172a23d86d7b40c1b850429d805f3a39bdf3baa
Author: Louis-Dominique Dubeau <ldd@lddubeau.com>
Commit: Louis-Dominique Dubeau <ldd@lddubeau.com>
Add a custom predicate for flyspell-prog-mode.
---
typescript-mode-tests.el | 41 +++++++++++++++++++++++++++++++++++++++++
typescript-mode.el | 33 +++++++++++++++++++++++++++++++++
2 files changed, 74 insertions(+)
diff --git a/typescript-mode-tests.el b/typescript-mode-tests.el
index cbc25dccdf..9a4725afc5 100644
--- a/typescript-mode-tests.el
+++ b/typescript-mode-tests.el
@@ -236,6 +236,47 @@ fontified as documentation."
(should (eq (text-property-not-all loc (point-max) 'face
font-lock-string-face)
(1- (point-max)))))))
+(defun flyspell-predicate-test (search-for)
+ "This function runs a test on
+`typescript--flyspell-mode-predicate'. `SEARCH-FOR' is a string
+to search for in the current buffer before running
+`typescript--flyspell-mode-predicate'. This test checks that the
+point has not moved. It returns the value of returned by the
+invocation of `typescript--flyspell-mode-predicate'."
+ (search-forward search-for)
+ (let ((point-before (point)))
+ (prog1
+ (typescript--flyspell-mode-predicate)
+ ;; We should not have moved.
+ (should (eq (point) point-before)))
+ ))
+
+(ert-deftest flyspell-mode-predicate-skips-what-it-should ()
+ "Check that the custom flyspell predicate filters strings in
+import... from...."
+ (let (flyspell-generic-progmode-verify)
+ (fset 'flyspell-generic-progmode-verify (lambda () t))
+ ;; In the following searches we search for the starting quote of the
strings
+ ;; to avoid hitting keywords. Moreover, the end position of the search is
important.
+ ;; Flyspell puts point at the end of the word before calling the
predicate. We must
+ ;; replicate that behavior here.
+ (test-with-temp-buffer
+ "import 'a';\nimport { x } from 'b';\nconst foo = 'c';import { x }\nfrom
'd';"
+ (should (not (flyspell-predicate-test "'a")))
+ (should (not (flyspell-predicate-test "'b")))
+ (should (flyspell-predicate-test "'c"))
+ (should (not (flyspell-predicate-test "'d"))))
+ (test-with-temp-buffer
+ ;; This is valid TypeScript.
+ "const from = 'a';"
+ (should (flyspell-predicate-test "'a")))
+ (test-with-temp-buffer
+ ;; TypeScript does not allow a function named "import" but object
+ ;; members may be named "import". So this *can* be valid
+ ;; TypeScript.
+ "x.import('a');"
+ (should (flyspell-predicate-test "'a")))))
+
(provide 'typescript-mode-tests)
;;; typescript-mode-tests.el ends here
diff --git a/typescript-mode.el b/typescript-mode.el
index 7f5f4c4375..0379c011c5 100644
--- a/typescript-mode.el
+++ b/typescript-mode.el
@@ -1739,6 +1739,36 @@ and searches for the next token to be highlighted."
'(0 font-lock-variable-name-face))))
"Level three font lock for `typescript-mode'.")
+(defun typescript--flyspell-mode-predicate ()
+ "A custom predicate to help `flyspell-prog-mode' determine whether a word
should be checked."
+ ;; We depend on fontification for our results. font-lock-ensure is defined on
+ ;; Emacs 25 and over. Earlier versions use font-lock-fontify-buffer.
+ (if (fboundp 'font-lock-ensure)
+ (font-lock-ensure)
+ (font-lock-fontify-buffer))
+ (and
+ ;; Check with the default method that flyspell provides.
+ (flyspell-generic-progmode-verify)
+
+ ;;
+ ;; And eliminate cases specific to our mode we don't want to have
+ ;; spell-checked.
+ ;;
+
+ ;; Don't check the module names in import statements.
+ (save-excursion
+ (not (let* ((parse (syntax-ppss (1- (point))))
+ (string-start-pos (and (nth 3 parse)
+ (nth 8 parse))))
+ (and string-start-pos
+ (save-match-data
+ ;; Move to back to the start of the string, then past any ws
+ ;; and then past any non-ws to see if we have "from" or
"import".
+ (goto-char string-start-pos)
+ (typescript--backward-syntactic-ws)
+ (skip-syntax-backward "^-" (point-at-bol))
+ (looking-at "from\\|import\\s-"))))))))
+
(defun typescript--inside-pitem-p (pitem)
"Return whether point is inside the given pitem's header or body."
(typescript--ensure-cache)
@@ -2475,6 +2505,9 @@ Key bindings:
(with-no-warnings
(font-lock-fontify-buffer))))
+;; Set our custom predicate for flyspell prog mode
+(put 'typescript-mode 'flyspell-mode-predicate
+ 'typescript--flyspell-mode-predicate)
;;;###autoload
(eval-after-load 'folding
- [nongnu] elpa/typescript-mode dd832751ab 217/222: Merge pull request #156 from zkry/fix-dot-after-exclamation-indentation, (continued)
- [nongnu] elpa/typescript-mode dd832751ab 217/222: Merge pull request #156 from zkry/fix-dot-after-exclamation-indentation, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 4249a20d6d 187/222: Added file for indent test case, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode c5e7788ce9 044/222: Merge pull request #28 from ananthakumaran/testing, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 99c2b74ac3 059/222: Make current-column function internal., ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 89d22c4e18 051/222: Don't interpret forward slash in list as operator., ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 393ac6db0f 081/222: add tests for regexp font locking, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 361564c4a9 057/222: typescript-current-column: Dont cause side-effects., ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode d155a4b623 063/222: Revert indent of complex parameters., ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode e0b4a6cb31 055/222: Merge pull request #36 from lddubeau/feature/improved-tslint-regex, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode bce2e73cf2 107/222: Remove unused dependencies, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 7172a23d86 072/222: Add a custom predicate for flyspell-prog-mode.,
ELPA Syncer <=
- [nongnu] elpa/typescript-mode d8501770f6 103/222: Fix indentation of multiple curly braces in sequence., ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode a09e9c78f9 108/222: Highlight class names., ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 7c6fd0f4a8 115/222: Document how to handle ANSI codes in error messages., ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 9796425fdb 113/222: Add support for new type "unknown"., ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 39b7ba9e54 117/222: Distinguish type arguments from lesser/greater than. (Fixes #81), ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 30f8b8feb4 122/222: Merge pull request #87 from Ailrun/add-jsdoc-tags, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 29282a32b7 124/222: add never type, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 8910e12525 129/222: Add autoload cookie with safe-local-var for typescript-indent-level, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode fbaad515c9 132/222: Merge pull request #89 from Ailrun/update-jsdoc-tests, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 32146510b8 147/222: Pin our dist to Trusty., ELPA Syncer, 2022/02/06