Skip to content

Commit 5de95ad

Browse files
Allow users to override the extension passed to vale checker (#43)
* feat: Allow users to override the extension passed to vale checker Exposes an option, `flymake-collection-vale-extension-function`, that is a function that returns the extension (value of the --ext flag passed to vale) of the current file. The default value, the function `flymake-collection-vale-default-extension-function`, preserves the previous behavior of the vale checker. * chore: Add workflow_dispatch option * fix: Pass flymake-collection-source as an argument Previously flymake-collection-vale-default-extension-function tried to access the value of flymake-collection-source directly. This is erroneous since that variable is only accessible within the form defining the checker. To fix this, we let flymake-collection-vale-default-extension-function accept a buffer as an argument and call flymake-collection-vale-extension-function with flymake-collection-source as the argument. --------- Co-authored-by: Mohsin Kaleem <mohkale@kisara.moe>
1 parent 29d593c commit 5de95ad

File tree

1 file changed

+33
-4
lines changed

1 file changed

+33
-4
lines changed

src/checkers/flymake-collection-vale.el

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,36 @@
3232
(eval-when-compile
3333
(require 'flymake-collection-define))
3434

35+
(defun flymake-collection-vale-default-extension-function (buffer)
36+
"Default function for `flymake-collection-vale-extension-function'.
37+
This function will return the actual extension of the file associated
38+
with BUFFER. If there is no extension, nil will be returned, causing
39+
the omission of the \"--ext\" flag passed to vale."
40+
(let* ((file-name (buffer-file-name buffer))
41+
(extension (and file-name (file-name-extension file-name))))
42+
(when extension
43+
extension)))
44+
45+
(defcustom flymake-collection-vale-extension-function
46+
'flymake-collection-vale-default-extension-function
47+
"Function that returns the value of vale's \"--ext\" flag for the current file.
48+
This function accepts one argument, a buffer, and returns the value of
49+
the \"--ext\" flag (as a string), which is the extension of the file
50+
associated with that buffer. The associated extension determines which
51+
checking rules vale uses according to the user's configuration(s).
52+
53+
If nil is returned, or the value of this option is nil, the \"--ext\"
54+
flag is omitted.
55+
56+
The default function will return the actual extension of the file. If
57+
there is no extension, nil will be returned, omitting the \"--ext\"
58+
flag.
59+
60+
Customizing this option can be useful if the user edits files without an
61+
extension but would like them to be recognized as, say, org files."
62+
:type 'function
63+
:group 'flymake-collection)
64+
3565
;;;###autoload (autoload 'flymake-collection-vale "flymake-collection-vale")
3666
(flymake-collection-define-enumerate flymake-collection-vale
3767
"A prose syntax and style checker using vale.
@@ -43,10 +73,9 @@ See https://vale.sh/."
4373
(error "Cannot find vale executable"))
4474
:write-type 'pipe
4575
:command `(,vale-exec
46-
,@(let* ((file-name (buffer-file-name flymake-collection-source))
47-
(extension (and file-name (file-name-extension file-name))))
48-
(when extension
49-
(list (concat "--ext=." extension))))
76+
,@(when-let ((file-extension
77+
(funcall flymake-collection-vale-extension-function flymake-collection-source)))
78+
(concat "--ext=." file-extension))
5079
"--output=JSON")
5180
:generator
5281
(cdaar

0 commit comments

Comments
 (0)