aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoão Távora2017-10-01 13:30:38 +0100
committerJoão Távora2017-10-03 14:18:55 +0100
commit30ea272fe472ed77eab40179f43bb7bee5184912 (patch)
treed9f10b68676c1d0bc13ad4a242ffe41fccb4dde7
parent2e84179a291c6fce57d5e6c44121d77160487615 (diff)
downloademacs-30ea272fe472ed77eab40179f43bb7bee5184912.tar.gz
emacs-30ea272fe472ed77eab40179f43bb7bee5184912.zip
Hook Flymake onto proper checkdoc and byte-compile interfaces
The interfaces in bytecomp.el and checkdoc.el are mostly boilerplate, with little knowledge of actual internals or thought given to the usefulness of said interfaces in contexts other than Flymake's. * lisp/emacs-lisp/bytecomp.el (byte-compile-log-warning-function): New variable. (byte-compile-log-warning): Use it. (byte-compile--log-warning-for-byte-compile): New function. * lisp/emacs-lisp/checkdoc.el (checkdoc-create-error-function): New variable. (checkdoc-create-error): Use it. (checkdoc--create-error-for-checkdoc): New function.xo * lisp/progmodes/flymake-elisp.el (flymake-elisp--checkdoc-1): Use checkdoc-create-error-function. (flymake-elisp--batch-byte-compile): Use byte-compile-log-warning-function.
-rw-r--r--lisp/emacs-lisp/bytecomp.el22
-rw-r--r--lisp/emacs-lisp/checkdoc.el19
-rw-r--r--lisp/progmodes/flymake-elisp.el38
3 files changed, 57 insertions, 22 deletions
diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el
index 1b42961f1a4..590db570c56 100644
--- a/lisp/emacs-lisp/bytecomp.el
+++ b/lisp/emacs-lisp/bytecomp.el
@@ -1183,7 +1183,29 @@ Each function's symbol gets added to `byte-compile-noruntime-functions'."
1183 (compilation-forget-errors) 1183 (compilation-forget-errors)
1184 pt)))) 1184 pt))))
1185 1185
1186(defvar byte-compile-log-warning-function
1187 #'byte-compile--log-warning-for-byte-compile
1188 "Function called when encountering a warning or error.
1189Called with arguments (STRING POSITION FILL LEVEL). STRING is a
1190message describing the problem. POSITION is a buffer position
1191where the problem was detected. FILL is a prefix as in
1192`warning-fill-prefix'. LEVEL is the level of the
1193problem (`:warning' or `:error'). POSITION, FILL and LEVEL may be
1194nil.")
1195
1186(defun byte-compile-log-warning (string &optional fill level) 1196(defun byte-compile-log-warning (string &optional fill level)
1197 "Log a byte-compilation warning.
1198STRING, FILL and LEVEL are as described in
1199`byte-compile-log-warning-function', which see."
1200 (funcall byte-compile-log-warning-function
1201 string byte-compile-last-position
1202 fill
1203 level))
1204
1205(defun byte-compile--log-warning-for-byte-compile (string &optional
1206 _position
1207 fill
1208 level)
1187 "Log a message STRING in `byte-compile-log-buffer'. 1209 "Log a message STRING in `byte-compile-log-buffer'.
1188Also log the current function and file if not already done. If 1210Also log the current function and file if not already done. If
1189FILL is non-nil, set `warning-fill-prefix' to four spaces. LEVEL 1211FILL is non-nil, set `warning-fill-prefix' to four spaces. LEVEL
diff --git a/lisp/emacs-lisp/checkdoc.el b/lisp/emacs-lisp/checkdoc.el
index 7997ba6014c..72f82f26f6f 100644
--- a/lisp/emacs-lisp/checkdoc.el
+++ b/lisp/emacs-lisp/checkdoc.el
@@ -1147,14 +1147,27 @@ Prefix argument is the same as for `checkdoc-defun'"
1147;; features and behaviors, so we need some ways of specifying 1147;; features and behaviors, so we need some ways of specifying
1148;; them, and making them easier to use in the wacked-out interfaces 1148;; them, and making them easier to use in the wacked-out interfaces
1149;; people are requesting 1149;; people are requesting
1150(defun checkdoc-create-error (text start end &optional unfixable) 1150(defvar checkdoc-create-error-function #'checkdoc--create-error-for-checkdoc
1151 "Used to create the return error text returned from all engines. 1151 "Function called when Checkdoc encounters an error.
1152Should accept as arguments (TEXT START END &optional UNFIXABLE).
1153
1152TEXT is the descriptive text of the error. START and END define the region 1154TEXT is the descriptive text of the error. START and END define the region
1153it is sensible to highlight when describing the problem. 1155it is sensible to highlight when describing the problem.
1154Optional argument UNFIXABLE means that the error has no auto-fix available. 1156Optional argument UNFIXABLE means that the error has no auto-fix available.
1155 1157
1156A list of the form (TEXT START END UNFIXABLE) is returned if we are not 1158A list of the form (TEXT START END UNFIXABLE) is returned if we are not
1157generating a buffered list of errors." 1159generating a buffered list of errors.")
1160
1161(defun checkdoc-create-error (text start end &optional unfixable)
1162 "Used to create the return error text returned from all engines.
1163TEXT, START, END and UNFIXABLE conform to
1164`checkdoc-create-error-function', which see."
1165 (funcall checkdoc-create-error-function text start end unfixable))
1166
1167(defun checkdoc--create-error-for-checkdoc (text start end &optional unfixable)
1168 "Create an error for Checkdoc.
1169TEXT, START, END and UNFIXABLE conform to
1170`checkdoc-create-error-function', which see."
1158 (if checkdoc-generate-compile-warnings-flag 1171 (if checkdoc-generate-compile-warnings-flag
1159 (progn (checkdoc-error start text) 1172 (progn (checkdoc-error start text)
1160 nil) 1173 nil)
diff --git a/lisp/progmodes/flymake-elisp.el b/lisp/progmodes/flymake-elisp.el
index b42767c3fac..b433dc24e12 100644
--- a/lisp/progmodes/flymake-elisp.el
+++ b/lisp/progmodes/flymake-elisp.el
@@ -32,18 +32,18 @@
32(defun flymake-elisp--checkdoc-1 () 32(defun flymake-elisp--checkdoc-1 ()
33 "Do actual work for `flymake-elisp-checkdoc'." 33 "Do actual work for `flymake-elisp-checkdoc'."
34 (let (collected) 34 (let (collected)
35 (cl-letf (((symbol-function 'checkdoc-create-error) 35 (let* ((checkdoc-create-error-function
36 (lambda (text start end &optional unfixable) 36 (lambda (text start end &optional unfixable)
37 (push (list text start end unfixable) collected) 37 (push (list text start end unfixable) collected)
38 nil))) 38 nil))
39 (let* ((checkdoc-autofix-flag nil) 39 (checkdoc-autofix-flag nil)
40 (checkdoc-generate-compile-warnings-flag nil) 40 (checkdoc-generate-compile-warnings-flag nil)
41 (buf (generate-new-buffer " *checkdoc-temp*")) 41 (buf (generate-new-buffer " *checkdoc-temp*"))
42 (checkdoc-diagnostic-buffer buf)) 42 (checkdoc-diagnostic-buffer buf))
43 (unwind-protect 43 (unwind-protect
44 (save-excursion 44 (save-excursion
45 (checkdoc-current-buffer t)) 45 (checkdoc-current-buffer t))
46 (kill-buffer buf)))) 46 (kill-buffer buf)))
47 collected)) 47 collected))
48 48
49;;;###autoload 49;;;###autoload
@@ -165,14 +165,14 @@ Runs in a batch-mode Emacs. Interactively use variable
165 (byte-compile-dest-file-function 165 (byte-compile-dest-file-function
166 (lambda (source) 166 (lambda (source)
167 (setq dummy-elc-file (make-temp-file (file-name-nondirectory source))))) 167 (setq dummy-elc-file (make-temp-file (file-name-nondirectory source)))))
168 (collected)) 168 (collected)
169 (byte-compile-log-warning-function
170 (lambda (string &optional position fill level)
171 (push (list string position fill level)
172 collected)
173 t)))
169 (unwind-protect 174 (unwind-protect
170 (cl-letf (((symbol-function 'byte-compile-log-warning) 175 (byte-compile-file file)
171 (lambda (string &optional fill level)
172 (push (list string byte-compile-last-position fill level)
173 collected)
174 t)))
175 (byte-compile-file file))
176 (ignore-errors 176 (ignore-errors
177 (delete-file dummy-elc-file) 177 (delete-file dummy-elc-file)
178 (kill-buffer byte-compile-log-buffer))) 178 (kill-buffer byte-compile-log-buffer)))