emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Alex Branham <alex.branham@gmail.com>
To: Org Mode List <emacs-orgmode@gnu.org>
Subject: Support flymake with org-lint
Date: Fri, 08 Jun 2018 11:50:28 -0500	[thread overview]
Message-ID: <87k1r9te7f.fsf@gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 4101 bytes --]

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 <branham@utexas.edu>
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




[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-support-for-flymake.patch --]
[-- Type: text/x-patch, Size: 3784 bytes --]

From b53c4068cb64c152c417014916c7d8c11e4651fb Mon Sep 17 00:00:00 2001
From: Alex Branham <branham@utexas.edu>
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


             reply	other threads:[~2018-06-08 16:48 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-08 16:50 Alex Branham [this message]
2018-06-11 21:09 ` Support flymake with org-lint Nicolas Goaziou

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87k1r9te7f.fsf@gmail.com \
    --to=alex.branham@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).