emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[O] Support flymake with org-lint


From: Alex Branham
Subject: [O] Support flymake with org-lint
Date: Fri, 08 Jun 2018 11:50:28 -0500
User-agent: mu4e 1.0; emacs 26.1

Here's a patch that adds support for flymake in Emacs 26 and greater. It
uses org-lint.el as the backend. It can be pretty slow if you have a
large buffer open, so I don't think I'd recommend enabling it by
default. It's nice to be able to use e.g. flymake-goto-next-error to
navigate around the buffer though.

Alex

>From b53c4068cb64c152c417014916c7d8c11e4651fb Mon Sep 17 00:00:00 2001
From: Alex Branham <address@hidden>
Date: Wed, 6 Jun 2018 14:44:12 -0500
Subject: [PATCH] Add support for flymake

* lisp/org-flymake.el (org-flymake-org-lint-backend): New function
* lisp/org-flymake.el (org-flymake-setup): New function
---
 etc/ORG-NEWS        | 10 +++++++
 lisp/org-flymake.el | 63 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 73 insertions(+)
 create mode 100644 lisp/org-flymake.el

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 2a22be0d5..5bf5a2f71 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -311,7 +311,17 @@ You can set an agenda restriction lock with =C-x C-x <= or 
with =<= at the
 beginning of a headline when using Org speed commands.  Now, if there
 is already a restriction at point, hitting =<= again (or =C-x C-x <=) will
 remove it.
+*** Org now supports flymake in Emacs version 26.1 and greater
+To enable it in all org buffers, add:

+#+begin_src emacs-lisp
+(add-hook 'org-mode-hook #'org-flymake-setup)
+#+end_src
+
+to your Emacs configuration file.  This takes care of setting up the
+flymake backend (using ~org-lint~) and enables ~flymake-mode~ in org
+buffers.  Note that ~org-lint~ can be slow in large org buffers, so
+you may not want to enable this in all buffers by default.
 ** New commands and functions

 *** ~org-insert-structure-template~
diff --git a/lisp/org-flymake.el b/lisp/org-flymake.el
new file mode 100644
index 000000000..7462d98a6
--- /dev/null
+++ b/lisp/org-flymake.el
@@ -0,0 +1,63 @@
+;;; org-flymake.el --- Org support for flymake.el  -*- lexical-binding: t; -*-
+;;
+;; Copyright (C) 2018 Free Software Foundation, Inc.
+;;
+;; This file is a part of GNU Emcas.
+;;
+;; GNU Emacs is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+;;
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+;;
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.
+;;
+;;
+;;; Commentary:
+;; This file implements support for flymake.el in org mode buffers.
+;; To enable it permanently in all org buffers, add this to your Emacs
+;; configuration file:
+;;
+;; (add-hook 'org-mode-hook #'org-flymake-setup)
+;;
+;; Flymake supports multiple backends.  Currently we use `org-lint' only.
+
+;;; Code:
+
+(eval-when-compile
+  (require 'cl-lib))
+(require 'org-lint)
+(require 'seq)
+
+(defun org-flymake-org-lint-backend (report-fn &rest _args)
+  "A Flymake backend for `org-lint'.
+Calls REPORT-FN directly."
+  (let* ((report (org-lint--generate-reports
+                 (current-buffer) org-lint--checkers))
+        (report (mapcar
+                 (lambda (c) (seq-into (nth 0 (cdr c)) 'list))
+                 report)))
+    (funcall report-fn
+            (cl-loop
+             for (line _trust description _checkers) in report
+             for (beg . end) = (flymake-diag-region (current-buffer) 
(string-to-number line))
+             collect
+             (flymake-make-diagnostic (current-buffer) beg end :note 
description)))
+    report))
+
+;;;###autoload
+(defun org-flymake-setup ()
+  "Add `org-flymake' to `flymake-diagnostic-functions'."
+  (if (< emacs-major-version 26)
+      (user-error "Org-flymake requires Emacs 26.1 or greater")
+    (add-hook 'flymake-diagnostic-functions #'org-flymake-org-lint-backend nil 
t)
+    (flymake-mode)))
+
+(provide 'org-flymake)
+
+;;; org-flymake.el ends here
--
2.17.1



Attachment: 0001-Add-support-for-flymake.patch
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]