jeremy-compostella / org-msg

OrgMsg is a GNU/Emacs global minor mode mixing up Org mode and Message mode to compose and reply to emails in a Outlook HTML friendly style.
GNU General Public License v3.0
281 stars 61 forks source link

Cannot get proselint to load as checker #192

Open atanasj opened 5 months ago

atanasj commented 5 months ago

I want to use proselint as a grammar checker in org-msg-edit-mode. I can get it working by running consult-flycheck in message-mode, but not when using org-msg.

Some advice about how to get this working would be truly appreciated. Can someone please help / share their experience to help me get this working?

jeremy-compostella commented 3 months ago

I installed the flymake-proselint package and the following configuration seems to be working for me:

(defun org-msg-flymake-proselint-backend (report-fn &rest _args)
  "Flymake backend for Proselint.
REPORT-FN is the flymake reporter function.  See the Info
node (flymake) Backend functions for more details."
  (unless (executable-find flymake-proselint-executable)
    (user-error "Executable proselint not found on PATH"))

  (when (process-live-p flymake-proselint--flymake-proc)
    (kill-process flymake-proselint--flymake-proc))

  (let ((proc (make-process
               :name "proselint-flymake" :noquery t :connection-type 'pipe
               :buffer (generate-new-buffer " *proselint-flymake*")
               :command
               (if-let* ((conf (flymake-proselint-generate-configuration)))
                   (list flymake-proselint-executable "--config" conf "--json" "-")
                 (list flymake-proselint-executable "--json" "-"))
               :sentinel #'flymake-proselint-sentinel)))
    (process-put proc 'source (current-buffer))
    (process-put proc 'report-fn report-fn)
    (setq flymake-proselint--flymake-proc proc)
    (save-restriction
      (widen)
      (process-send-region proc (point-min) (org-msg-end))
      (process-send-eof proc))))

(defun org-msg-flymake-proselint-setup ()
  "Enable Flymake backend proselint."
  (add-hook 'flymake-diagnostic-functions #'org-msg-flymake-proselint-backend nil t))

(add-hook 'org-msg-edit-mode-hook #'flymake-mode)
(add-hook 'org-msg-edit-mode-hook #'org-msg-flymake-proselint-setup)