6
6
; ; Keywords: grammar text docs tools convenience checker
7
7
; ; URL: https://github.com/PillFall/Emacs-LanguageTool.el
8
8
; ; Version: 1.2.0
9
- ; ; Package-Requires: ((emacs "27.0 "))
9
+ ; ; Package-Requires: ((emacs "27.1 "))
10
10
11
11
; ; This program is free software; you can redistribute it and/or modify
12
12
; ; it under the terms of the GNU General Public License as published by
32
32
(require 'languagetool-core )
33
33
(require 'languagetool-issue )
34
34
(require 'languagetool-java )
35
+ (eval-when-compile
36
+ (require 'subr-x ))
35
37
36
38
; ; Group definition:
37
39
38
40
(defgroup languagetool-console nil
39
- " LanguageTool command line parser and checking"
41
+ " LanguageTool command line parser and checking. "
40
42
:tag " Console"
41
43
:prefix " languagetool-console-"
42
44
:group 'languagetool )
@@ -74,7 +76,7 @@ Command Line.")
74
76
; ;; Function definitions:
75
77
76
78
(defun languagetool-console-class-p ()
77
- " Return nil if `languagetool-console-command' is not a Java class."
79
+ " Return non- nil if `languagetool-console-command' is a Java class."
78
80
(let ((regex (rx
79
81
line-start
80
82
(zero-or-more
@@ -90,7 +92,7 @@ Command Line.")
90
92
(string-match-p regex languagetool-console-command)))
91
93
92
94
(defun languagetool-console-command-exists-p ()
93
- " Return t is `languagetool-console-command' can be used or exists.
95
+ " Return non-nil if `languagetool-console-command' can be used or exists.
94
96
95
97
Also sets `languagetool-console-command' to a full path if needed
96
98
for this package to work."
@@ -104,63 +106,55 @@ for this package to work."
104
106
(unless (listp languagetool-console-arguments)
105
107
(error " LanguageTool Console Arguments must be a list of strings " ))
106
108
107
- (let (( arguments nil ) )
109
+ (let (arguments)
108
110
109
111
; ; Appends LanguageTool Console Command
110
112
(unless (languagetool-console-class-p)
111
- (setq arguments ( append arguments ( list " -jar" )) ))
112
- (setq arguments ( append arguments ( list languagetool-console-command)) )
113
+ (push " -jar" arguments ))
114
+ (push languagetool-console-command arguments )
113
115
114
116
; ; Appends the LanguageTool arguments
115
- (setq arguments ( append arguments languagetool-console-arguments) )
117
+ (push languagetool-console-arguments arguments )
116
118
117
119
; ; Appends the common arguments
118
- (setq arguments (append arguments
119
- (list " --encoding" " utf8" )
120
- (list " --json" )))
120
+ (push (list " --encoding" " utf8" " --json" ) arguments)
121
121
122
122
; ; Appends the correction language information
123
123
(if (string= languagetool-correction-language " auto" )
124
- (setq arguments ( append arguments ( list " --autoDetect" )) )
125
- (setq arguments ( append arguments ( list " --language" languagetool-correction-language)) ))
124
+ (push " --autoDetect" arguments )
125
+ (push ( list " --language" languagetool-correction-language) arguments ))
126
126
127
127
; ; Appends the mother tongue information
128
128
(when (stringp languagetool-mother-tongue)
129
- (setq arguments ( append arguments ( list " --mothertongue" languagetool-mother-tongue)) ))
129
+ (push ( list " --mothertongue" languagetool-mother-tongue) arguments ))
130
130
131
131
; ; Appends the disabled rules
132
- (let ((rules " " ))
133
- ; ; Global disabled rules
134
- (dolist (rule languagetool-disabled-rules)
135
- (if (string= rules " " )
136
- (setq rules (concat rules rule))
137
- (setq rules (concat rules " ," rule))))
138
- ; ; Local disabled rules
139
- (dolist (rule languagetool-local-disabled-rules)
140
- (if (string= rules " " )
141
- (setq rules (concat rules rule))
142
- (setq rules (concat rules " ," rule))))
132
+ (let ((rules (string-join (append languagetool-disabled-rules languagetool-local-disabled-rules) " ," )))
143
133
(unless (string= rules " " )
144
- (setq arguments ( append arguments ( list " --disable" rules)) )))
145
- arguments))
134
+ (push ( list " --disable" rules) arguments )))
135
+ (flatten-tree ( reverse arguments)) ))
146
136
147
137
(defun languagetool-console-write-debug-info (text )
148
138
" Write debug info in `languagetool-console-output-buffer-name' .
149
139
150
140
The argument TEXT is the region passed to LanguageTool for
151
141
checking."
152
- (insert (propertize " ----- LanguageTool Command:" 'face 'font-lock-warning-face )
153
- " \n\n " )
154
- (insert languagetool-java-bin " "
155
- (mapconcat (lambda (x ) (format " %s " x)) (append
156
- (languagetool-console-parse-arguments)
157
- (languagetool-java-parse-arguments)) " " )
158
- " \n\n\n\n " )
159
- (insert (propertize " ----- LanguageTool Text:" 'face 'font-lock-warning-face )
160
- " \n\n " )
161
- (insert text " \n\n\n\n " )
162
- (insert (propertize " ----- LanguageTool Output:" 'face 'font-lock-warning-face )
163
- " \n\n " ))
142
+ (insert
143
+ (propertize " ----- LanguageTool Command:" 'face 'font-lock-warning-face )
144
+ " \n\n "
145
+ (string-join
146
+ (append
147
+ (list languagetool-java-bin)
148
+ (languagetool-java-parse-arguments)
149
+ (languagetool-console-parse-arguments))
150
+ " " )
151
+ " \n\n\n\n "
152
+ (propertize " ----- LanguageTool Text:" 'face 'font-lock-warning-face )
153
+ " \n\n "
154
+ text
155
+ " \n\n\n\n "
156
+ (propertize " ----- LanguageTool Output:" 'face 'font-lock-warning-face )
157
+ " \n\n " ))
164
158
165
159
(defun languagetool-console-invoke-command-region (begin end )
166
160
" Invoke LanguageTool passing the current region to STDIN.
@@ -219,17 +213,17 @@ Found no errors.")
219
213
220
214
(defun languagetool-console-matches-exists-p ()
221
215
" Return t if issues where found by LanguageTool or nil otherwise."
222
- (/= 0 (length (cdr ( assoc 'matches languagetool-console-output-parsed) ))))
216
+ (/= 0 (length (alist-get 'matches languagetool-console-output-parsed))))
223
217
224
218
(defun languagetool-console-highlight-matches (begin )
225
219
" Highlight issues in the buffer.
226
220
227
221
BEGIN defines the start of the current region."
228
- (let ((corrections (cdr ( assoc 'matches languagetool-console-output-parsed) )))
222
+ (let ((corrections (alist-get 'matches languagetool-console-output-parsed)))
229
223
(dotimes (index (length corrections))
230
224
(let* ((correction (aref corrections index))
231
- (offset (cdr ( assoc 'offset correction) ))
232
- (size (cdr ( assoc 'length correction) ))
225
+ (offset (alist-get 'offset correction))
226
+ (size (alist-get 'length correction))
233
227
(start (+ begin offset))
234
228
(end (+ begin offset size))
235
229
(word (buffer-substring-no-properties start end)))
0 commit comments