Skip to content

Commit

Permalink
Allow users to override the extension passed to vale checker (#43)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
krisbalintona and mohkale authored Jan 1, 2025
1 parent 29d593c commit 5de95ad
Showing 1 changed file with 33 additions and 4 deletions.
37 changes: 33 additions & 4 deletions src/checkers/flymake-collection-vale.el
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,36 @@
(eval-when-compile
(require 'flymake-collection-define))

(defun flymake-collection-vale-default-extension-function (buffer)
"Default function for `flymake-collection-vale-extension-function'.
This function will return the actual extension of the file associated
with BUFFER. If there is no extension, nil will be returned, causing
the omission of the \"--ext\" flag passed to vale."
(let* ((file-name (buffer-file-name buffer))
(extension (and file-name (file-name-extension file-name))))
(when extension
extension)))

(defcustom flymake-collection-vale-extension-function
'flymake-collection-vale-default-extension-function
"Function that returns the value of vale's \"--ext\" flag for the current file.
This function accepts one argument, a buffer, and returns the value of
the \"--ext\" flag (as a string), which is the extension of the file
associated with that buffer. The associated extension determines which
checking rules vale uses according to the user's configuration(s).
If nil is returned, or the value of this option is nil, the \"--ext\"
flag is omitted.
The default function will return the actual extension of the file. If
there is no extension, nil will be returned, omitting the \"--ext\"
flag.
Customizing this option can be useful if the user edits files without an
extension but would like them to be recognized as, say, org files."
:type 'function
:group 'flymake-collection)

;;;###autoload (autoload 'flymake-collection-vale "flymake-collection-vale")
(flymake-collection-define-enumerate flymake-collection-vale
"A prose syntax and style checker using vale.
Expand All @@ -43,10 +73,9 @@ See https://vale.sh/."
(error "Cannot find vale executable"))
:write-type 'pipe
:command `(,vale-exec
,@(let* ((file-name (buffer-file-name flymake-collection-source))
(extension (and file-name (file-name-extension file-name))))
(when extension
(list (concat "--ext=." extension))))
,@(when-let ((file-extension
(funcall flymake-collection-vale-extension-function flymake-collection-source)))
(concat "--ext=." file-extension))
"--output=JSON")
:generator
(cdaar
Expand Down

0 comments on commit 5de95ad

Please sign in to comment.