emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Support flymake with org-lint
@ 2018-06-08 16:50 Alex Branham
  2018-06-11 21:09 ` Nicolas Goaziou
  0 siblings, 1 reply; 2+ messages in thread
From: Alex Branham @ 2018-06-08 16:50 UTC (permalink / raw)
  To: Org Mode List

[-- 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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: Support flymake with org-lint
  2018-06-08 16:50 Support flymake with org-lint Alex Branham
@ 2018-06-11 21:09 ` Nicolas Goaziou
  0 siblings, 0 replies; 2+ messages in thread
From: Nicolas Goaziou @ 2018-06-11 21:09 UTC (permalink / raw)
  To: Alex Branham; +Cc: Org Mode List

Hello,

Alex Branham <alex.branham@gmail.com> writes:

> Here's a patch that adds support for flymake in Emacs 26 and greater. 

Thank you.

Some comments follow.

> 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.

According to `flymake-diagnostic-functions', backend functions can use
asynchronous processes. This would be more usable if large buffers were
checked asynchronously.

> 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

It should be

* lisp/org-flymake.el: New file.

However, it could go in "org-lint.el" directly, if useful enough,
instead of a new library. This is also more logical since it uses
internal functions and variables from there.

> +(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))

The following may be more idiomatic. At least it uses neither cl-lib nor
seq:

    (funcall report-fn
             ;; Convert Lint reports into Flymake diagnostic objects.
             (mapcar
              (lambda (report)
                (pcase-let*
                    ((`(,_ [,line ,_ ,description ,_]) report)
                     (`(,beg . ,end) (flymake-diag-region (current-buffer)
                                                          (string-to-number line))))
                  (flymake-make-diagnostic (current-buffer) beg end :note description)))
              (org-lint--generate-reports (current-buffer) org-lint--checkers)))

Anyway, I would suggest to focus on asynchronous report generation.

WDYT?

Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-06-11 21:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-08 16:50 Support flymake with org-lint Alex Branham
2018-06-11 21:09 ` Nicolas Goaziou

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).