-
Notifications
You must be signed in to change notification settings - Fork 4
/
wucuo-flyspell-org-verify.el
63 lines (50 loc) · 1.96 KB
/
wucuo-flyspell-org-verify.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
;;; wucuo-flyspell-org-verify.el --- verify typo in org file -*- lexical-binding: t -*-
;; Copyright (C) 2020 Chen Bin
;;
;; This file is NOT part of GNU Emacs.
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program; if not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;;
;;; Code:
(require 'wucuo-sdk)
(defun wucuo-org-mode-code-snippet-p ()
"Code snippet embedded in org file?"
(let* (rlt
(begin-regexp "^[ \t]*#\\+begin_\\(src\\|html\\|latex\\|example\\)")
(end-regexp "^[ \t]*#\\+end_\\(src\\|html\\|latex\\|example\\)")
(case-fold-search t)
b e)
(save-excursion
(if (setq b (re-search-backward begin-regexp nil t))
(setq e (re-search-forward end-regexp nil t))))
(if (and b e (< (point) e)) (setq rlt t))
rlt))
;;;###autoload
(defun wucuo-flyspell-org-verify ()
"Verify typo in org file."
(let* ((f (wucuo-sdk-get-font-face (1- (point))))
(rlt t))
(cond
;; skip checking in below fonts
((memq f '(org-verbatim org-code))
(setq rlt nil))
;; skip checking property lines
((string-match "^[ \t]+:[A-Z]+:[ \t]+" (wucuo-sdk-current-line))
(setq rlt nil))
;; skipping checking in code snippet
;; slow test should be placed at last
((wucuo-org-mode-code-snippet-p)
(setq rlt nil)))
;; If rlt is t, it's a typo. If nil, not a typo.
rlt))
(provide 'wucuo-flyspell-org-verify)
;;; wucuo-flyspell-org-verify.el ends here