-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathlanguagetool-issue.el
123 lines (100 loc) · 4.29 KB
/
languagetool-issue.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
;;; languagetool-issue.el --- LanguegeTool issue faces -*- lexical-binding: t; -*-
;; Copyright (C) 2020-2022 Joar Buitrago
;; Author: Joar Buitrago <[email protected]>
;; Keywords: grammar text docs tools convenience checker
;; URL: https://github.com/PillFall/Emacs-LanguageTool.el
;; Version: 1.3.0
;; Package-Requires: ((emacs "27.1"))
;; 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 of the License, 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:
;; LanguageTool correction faces. Get from LanguageTool API.
;;
;; Addition, Characters, Duplication, Formatting, Grammar,
;; Inconsistency, InconsistentEntities, Internationalization, Legal,
;; Length, LocaleSpecificContent, LocaleViolation, Markup,
;; Misspelling, Mistranslation, NonConformance, Numbers, Omission,
;; Other, PatternProblem, Register, Style, Terminology, Typographical,
;; Uncategorized, Untranslated, Whitespace
;;; Code:
;; Group definition:
(defgroup languagetool-issue nil
"LanguageTool faces for marking issues."
:tag "Issue Faces"
:prefix "languagetool-issue-"
:group 'languagetool)
;; Face definitions:
(defface languagetool-issue-default
'((((supports :underline (:style wave)))
:underline (:style wave :color "yellow"))
(t
:underline t :inherit error))
"LanguageTool face for default issues."
:group 'languagetool-issue)
(defface languagetool-issue-misspelling
'((((supports :underline (:style wave)))
:underline (:style wave :color "red"))
(t
:underline t :inherit error))
"LanguageTool face for misspelling errors."
:group 'languagetool-issue)
(defface languagetool-issue-grammar
'((((supports :underline (:style wave)))
:underline (:style wave :color "green"))
(t
:underline t :inherit error))
"LanguageTool face for grammar errors."
:group 'languagetool-issue)
(defface languagetool-issue-style
'((((supports :underline (:style wave)))
:underline (:style wave :color "blue"))
(t
:underline t :inherit error))
"LanguageTool face for style errors."
:group 'languagetool-issue)
(defcustom languagetool-issue-face-alist
'(("misspelling" . languagetool-issue-misspelling)
("grammar" . languagetool-issue-grammar)
("style" . languagetool-issue-style))
"Alist with issue type associated with it's face.
Each element is a cons cell with the form (ISSUE_TYPE . FACE_NAME)."
:group 'languagetool-issue
:type '(alist
:key-type (string :tag "Issue Type")
:value-type (face :tag "Face Name")))
;; Function definitions:
(defun languagetool-issue-get-face (issue-type)
"Return the face for ISSUE-TYPE."
(or (cdr (assoc issue-type languagetool-issue-face-alist))
'languagetool-issue-default))
(defun languagetool-issue-create-overlay (begin end correction)
"Create an overlay for corrections.
Create an overlay for correction in the region delimited by BEGIN
and END, parsing CORRECTION as overlay properties."
(save-excursion
(let* ((ov (make-overlay begin end))
(short-message (alist-get 'shortMessage correction))
(message (alist-get 'message correction))
(replacements (alist-get 'replacements correction))
(rule (alist-get 'rule correction))
(issue-type (alist-get 'issueType rule)))
(when (string= short-message "")
(setq short-message message))
(overlay-put ov 'languagetool-short-message short-message)
(overlay-put ov 'languagetool-message message)
(overlay-put ov 'languagetool-replacements replacements)
(overlay-put ov 'languagetool-rule rule)
(overlay-put ov 'help-echo short-message)
(overlay-put ov 'priority 1)
(overlay-put ov 'evaporate t)
(overlay-put ov 'face (languagetool-issue-get-face issue-type)))))
(provide 'languagetool-issue)
;;; languagetool-issue.el ends here