~manuel-uberti/flymake-proselint

09b5a7a7a516ed6b22f243847806636d25e9b732 — Philip Kaludercic 2 years ago 30c4baa
Add user option 'flymake-proselint-message-format'

* flymake-proselint.el (flymake-proselint): Add a group.
(flymake-proselint-message-format): Add a user option.
(flymake-proselint-sentinel-1): Use the user option.
1 files changed, 33 insertions(+), 17 deletions(-)

M flymake-proselint.el
M flymake-proselint.el => flymake-proselint.el +33 -17
@@ 35,6 35,21 @@
  (require 'pcase))
(require 'flymake)

(defgroup flymake-proselint ()
  "Flymake backend for proselint."
  :prefix "flymake-proselint-"
  :group 'flymake)

(defcustom flymake-proselint-message-format
  "%m%r"
  "A format string to generate diagnostic messages.
The following %-sequences are replaced:

  %m - the message text
  %r - replacement suggestions
  %c - the error code"
  :type 'string)

(defun flymake-proselint-sentinel-1 (source data)
  "Handle a successfully parsed DATA from SOURCE.
DATA is a list of error diagnostics that are converted into


@@ 49,23 64,24 @@ Flymake diagnostic objects."
               ("warning"	:warning)
               ("suggestion"	:note)
               (_		:error))
             (with-temp-buffer		;create a message
               (insert (plist-get err :message))
               (let ((replacements (plist-get err :replacements)))
                 (cond
                  ((or (eq replacements :null) (null replacements))
                   ;; There are no replacements.
                   )
                  ((stringp replacements)
                   (insert " (Replacement: " replacements ")"))
                  ((listp replacements)
                   (insert " (Replacements: "
                           (mapconcat
                            (lambda (r)
                              (plist-get r :unique))
                            replacements ", ")
                           ")"))))
               (buffer-string)))
             (format-spec
              flymake-proselint-message-format
              `((?m . ,(plist-get err :message))
                (?c . ,(plist-get err :check))
                (?r . ,(let ((replacements (plist-get err :replacements)))
                         (cond
                          ((or (eq replacements :null) (null replacements))
                           ;; There are no replacements.
                           "")
                          ((stringp replacements)
                           (concat " (Replacement: " replacements ")"))
                          ((listp replacements)
                           (concat " (Replacements: "
                                   (mapconcat
                                    (lambda (r)
                                      (plist-get r :unique))
                                    replacements ", ")
                                   ")"))))))))
            diags))
    diags))