branch: elpa/flymake-collection
commit 5de95adb4c4981cee2f6152ef934230d7b2934eb
Author: Kristoffer Balintona <krisbalint...@gmail.com>
Commit: GitHub <nore...@github.com>

    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 <mohk...@kisara.moe>
---
 src/checkers/flymake-collection-vale.el | 37 +++++++++++++++++++++++++++++----
 1 file changed, 33 insertions(+), 4 deletions(-)

diff --git a/src/checkers/flymake-collection-vale.el 
b/src/checkers/flymake-collection-vale.el
index a02105bf77..50e7ede521 100644
--- a/src/checkers/flymake-collection-vale.el
+++ b/src/checkers/flymake-collection-vale.el
@@ -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.
@@ -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

Reply via email to