diff options
| author | João Távora | 2017-10-05 02:42:01 +0100 |
|---|---|---|
| committer | João Távora | 2017-10-05 03:09:12 +0100 |
| commit | 7a1133f1ff002943ce32b5a05a7261bba520288c (patch) | |
| tree | daf4c60e7cfe4502eb5fca4532589ae8efc41eb6 /lisp | |
| parent | 3d8df4d63604fd64c9feb3b43c4b9fa2fc487347 (diff) | |
| download | emacs-7a1133f1ff002943ce32b5a05a7261bba520288c.tar.gz emacs-7a1133f1ff002943ce32b5a05a7261bba520288c.zip | |
Misc. minor adjustments to Flymake
- Add a half-decent minor-mode menu;
- Fix "waiting for backends" mode line message;
- Adjust the flymake-diag-region API;
- Autoload the flymake-log macro;
- Auto-disable the legacy backend in more situations;
- Fix a couple of warnings in legacy backend.
* lisp/progmodes/flymake-proc.el
(flymake-proc--diagnostics-for-pattern): Use new
flymake-diag-region.
* lisp/progmodes/flymake-proc.el
(flymake-proc-legacy-flymake): Do error when no
buffer-file-name or not writable.
(flymake-proc-legacy-flymake)
(flymake-proc-simple-cleanup): Don't reference flymake-last-change-time
* lisp/progmodes/flymake.el (flymake-diag-region):
Autoload. Take buffer as first argument.
* lisp/progmodes/flymake.el (flymake-switch-to-log-buffer):
New command.
(flymake-menu): Add a simple menu.
(flymake--mode-line-format): Use menu. Fix message. Switch to
log buffer when clicking exceptional warnings.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/progmodes/flymake-proc.el | 38 | ||||
| -rw-r--r-- | lisp/progmodes/flymake.el | 103 |
2 files changed, 80 insertions, 61 deletions
diff --git a/lisp/progmodes/flymake-proc.el b/lisp/progmodes/flymake-proc.el index 47ec27f611b..d08819713a3 100644 --- a/lisp/progmodes/flymake-proc.el +++ b/lisp/progmodes/flymake-proc.el | |||
| @@ -522,13 +522,13 @@ Create parent directories as needed." | |||
| 522 | for buffer = (and full-file | 522 | for buffer = (and full-file |
| 523 | (find-buffer-visiting full-file)) | 523 | (find-buffer-visiting full-file)) |
| 524 | if (and (eq buffer (process-buffer proc)) message) | 524 | if (and (eq buffer (process-buffer proc)) message) |
| 525 | collect (with-current-buffer buffer | 525 | collect (pcase-let ((`(,beg . ,end) |
| 526 | (pcase-let ((`(,beg . ,end) | 526 | (flymake-diag-region buffer line-number col-number))) |
| 527 | (flymake-diag-region line-number col-number))) | 527 | (flymake-make-diagnostic |
| 528 | (flymake-make-diagnostic | 528 | buffer beg end |
| 529 | buffer beg end | 529 | (with-current-buffer buffer |
| 530 | (guess-type flymake-proc-diagnostic-type-pred message) | 530 | (guess-type flymake-proc-diagnostic-type-pred message)) |
| 531 | message))) | 531 | message)) |
| 532 | else | 532 | else |
| 533 | do (flymake-log 2 "Reference to file %s is out of scope" fname)) | 533 | do (flymake-log 2 "Reference to file %s is out of scope" fname)) |
| 534 | (error | 534 | (error |
| @@ -742,16 +742,18 @@ can also be executed interactively independently of | |||
| 742 | "There's already a Flymake process running in this buffer") | 742 | "There's already a Flymake process running in this buffer") |
| 743 | (kill-process proc)))) | 743 | (kill-process proc)))) |
| 744 | (when | 744 | (when |
| 745 | ;; A number of situations make us not want to error right away | 745 | ;; This particular situation make us not want to error right |
| 746 | ;; (and disable ourselves), in case the situation changes in | 746 | ;; away (and disable ourselves), in case the situation changes |
| 747 | ;; the near future. | 747 | ;; in the near future. |
| 748 | (and buffer-file-name | 748 | (and (or (not flymake-proc-compilation-prevents-syntax-check) |
| 749 | ;; Since we write temp files in current dir, there's no point | ||
| 750 | ;; trying if the directory is read-only (bug#8954). | ||
| 751 | (file-writable-p (file-name-directory buffer-file-name)) | ||
| 752 | (or (not flymake-proc-compilation-prevents-syntax-check) | ||
| 753 | (not (flymake-proc--compilation-is-running)))) | 749 | (not (flymake-proc--compilation-is-running)))) |
| 754 | (let ((init-f (flymake-proc--get-init-function buffer-file-name))) | 750 | (let ((init-f |
| 751 | (and | ||
| 752 | buffer-file-name | ||
| 753 | ;; Since we write temp files in current dir, there's no point | ||
| 754 | ;; trying if the directory is read-only (bug#8954). | ||
| 755 | (file-writable-p (file-name-directory buffer-file-name)) | ||
| 756 | (flymake-proc--get-init-function buffer-file-name)))) | ||
| 755 | (unless init-f (error "Can find a suitable init function")) | 757 | (unless init-f (error "Can find a suitable init function")) |
| 756 | (flymake-proc--clear-buildfile-cache) | 758 | (flymake-proc--clear-buildfile-cache) |
| 757 | (flymake-proc--clear-project-include-dirs-cache) | 759 | (flymake-proc--clear-project-include-dirs-cache) |
| @@ -768,7 +770,6 @@ can also be executed interactively independently of | |||
| 768 | (flymake-log 0 "init function %s for %s failed, cleaning up" | 770 | (flymake-log 0 "init function %s for %s failed, cleaning up" |
| 769 | init-f buffer-file-name)) | 771 | init-f buffer-file-name)) |
| 770 | (t | 772 | (t |
| 771 | (setq flymake-last-change-time nil) | ||
| 772 | (setq proc | 773 | (setq proc |
| 773 | (let ((default-directory (or dir default-directory))) | 774 | (let ((default-directory (or dir default-directory))) |
| 774 | (when dir | 775 | (when dir |
| @@ -878,8 +879,7 @@ can also be executed interactively independently of | |||
| 878 | (defun flymake-proc-simple-cleanup () | 879 | (defun flymake-proc-simple-cleanup () |
| 879 | "Do cleanup after `flymake-proc-init-create-temp-buffer-copy'. | 880 | "Do cleanup after `flymake-proc-init-create-temp-buffer-copy'. |
| 880 | Delete temp file." | 881 | Delete temp file." |
| 881 | (flymake-proc--safe-delete-file flymake-proc--temp-source-file-name) | 882 | (flymake-proc--safe-delete-file flymake-proc--temp-source-file-name)) |
| 882 | (setq flymake-last-change-time nil)) | ||
| 883 | 883 | ||
| 884 | (defun flymake-proc-get-real-file-name (file-name-from-err-msg) | 884 | (defun flymake-proc-get-real-file-name (file-name-from-err-msg) |
| 885 | "Translate file name from error message to \"real\" file name. | 885 | "Translate file name from error message to \"real\" file name. |
diff --git a/lisp/progmodes/flymake.el b/lisp/progmodes/flymake.el index 0b28dc31cfc..acc0637ec35 100644 --- a/lisp/progmodes/flymake.el +++ b/lisp/progmodes/flymake.el | |||
| @@ -180,6 +180,11 @@ If nil, never start checking buffer automatically like this." | |||
| 180 | level) | 180 | level) |
| 181 | "*Flymake log*"))) | 181 | "*Flymake log*"))) |
| 182 | 182 | ||
| 183 | (defun flymake-switch-to-log-buffer () | ||
| 184 | "Go to the *Flymake log* buffer." | ||
| 185 | (interactive) | ||
| 186 | (switch-to-buffer "*Flymake log*")) | ||
| 187 | |||
| 183 | ;;;###autoload | 188 | ;;;###autoload |
| 184 | (defmacro flymake-log (level msg &rest args) | 189 | (defmacro flymake-log (level msg &rest args) |
| 185 | "Log, at level LEVEL, the message MSG formatted with ARGS. | 190 | "Log, at level LEVEL, the message MSG formatted with ARGS. |
| @@ -282,41 +287,43 @@ verify FILTER, a function, and sort them by COMPARE (using KEY)." | |||
| 282 | (define-obsolete-face-alias 'flymake-warnline 'flymake-warning "26.1") | 287 | (define-obsolete-face-alias 'flymake-warnline 'flymake-warning "26.1") |
| 283 | (define-obsolete-face-alias 'flymake-errline 'flymake-error "26.1") | 288 | (define-obsolete-face-alias 'flymake-errline 'flymake-error "26.1") |
| 284 | 289 | ||
| 285 | (defun flymake-diag-region (line &optional col) | 290 | ;;;###autoload |
| 286 | "Compute region (BEG . END) corresponding to LINE and COL. | 291 | (defun flymake-diag-region (buffer line &optional col) |
| 287 | If COL is nil, return a region just for LINE. | 292 | "Compute BUFFER's region (BEG . END) corresponding to LINE and COL. |
| 288 | Return nil if the region is invalid." | 293 | If COL is nil, return a region just for LINE. Return nil if the |
| 294 | region is invalid." | ||
| 289 | (condition-case-unless-debug _err | 295 | (condition-case-unless-debug _err |
| 290 | (let ((line (min (max line 1) | 296 | (with-current-buffer buffer |
| 291 | (line-number-at-pos (point-max) 'absolute)))) | 297 | (let ((line (min (max line 1) |
| 292 | (save-excursion | 298 | (line-number-at-pos (point-max) 'absolute)))) |
| 293 | (goto-char (point-min)) | 299 | (save-excursion |
| 294 | (forward-line (1- line)) | 300 | (goto-char (point-min)) |
| 295 | (cl-flet ((fallback-bol | 301 | (forward-line (1- line)) |
| 296 | () (progn (back-to-indentation) (point))) | 302 | (cl-flet ((fallback-bol |
| 297 | (fallback-eol | 303 | () (progn (back-to-indentation) (point))) |
| 298 | (beg) | 304 | (fallback-eol |
| 299 | (progn | 305 | (beg) |
| 300 | (end-of-line) | 306 | (progn |
| 301 | (skip-chars-backward " \t\f\t\n" beg) | 307 | (end-of-line) |
| 302 | (if (eq (point) beg) | 308 | (skip-chars-backward " \t\f\t\n" beg) |
| 303 | (line-beginning-position 2) | 309 | (if (eq (point) beg) |
| 304 | (point))))) | 310 | (line-beginning-position 2) |
| 305 | (if (and col (cl-plusp col)) | 311 | (point))))) |
| 306 | (let* ((beg (progn (forward-char (1- col)) | 312 | (if (and col (cl-plusp col)) |
| 307 | (point))) | 313 | (let* ((beg (progn (forward-char (1- col)) |
| 308 | (sexp-end (ignore-errors (end-of-thing 'sexp))) | 314 | (point))) |
| 309 | (end (or (and sexp-end | 315 | (sexp-end (ignore-errors (end-of-thing 'sexp))) |
| 310 | (not (= sexp-end beg)) | 316 | (end (or (and sexp-end |
| 311 | sexp-end) | 317 | (not (= sexp-end beg)) |
| 312 | (ignore-errors (goto-char (1+ beg))))) | 318 | sexp-end) |
| 313 | (safe-end (or end | 319 | (ignore-errors (goto-char (1+ beg))))) |
| 314 | (fallback-eol beg)))) | 320 | (safe-end (or end |
| 315 | (cons (if end beg (fallback-bol)) | 321 | (fallback-eol beg)))) |
| 316 | safe-end)) | 322 | (cons (if end beg (fallback-bol)) |
| 317 | (let* ((beg (fallback-bol)) | 323 | safe-end)) |
| 318 | (end (fallback-eol beg))) | 324 | (let* ((beg (fallback-bol)) |
| 319 | (cons beg end)))))) | 325 | (end (fallback-eol beg))) |
| 326 | (cons beg end))))))) | ||
| 320 | (error (flymake-error "Invalid region line=%s col=%s" line col)))) | 327 | (error (flymake-error "Invalid region line=%s col=%s" line col)))) |
| 321 | 328 | ||
| 322 | (defvar flymake-diagnostic-functions nil | 329 | (defvar flymake-diagnostic-functions nil |
| @@ -872,8 +879,17 @@ applied." | |||
| 872 | (flymake-goto-next-error (- (or n 1)) filter interactive)) | 879 | (flymake-goto-next-error (- (or n 1)) filter interactive)) |
| 873 | 880 | ||
| 874 | 881 | ||
| 875 | ;;; Mode-line fanciness | 882 | ;;; Mode-line and menu |
| 876 | ;;; | 883 | ;;; |
| 884 | (easy-menu-define flymake-menu flymake-mode-map "Flymake" | ||
| 885 | `("Flymake" | ||
| 886 | [ "Go to next error" flymake-goto-next-error t ] | ||
| 887 | [ "Go to previous error" flymake-goto-prev-error t ] | ||
| 888 | [ "Check now" flymake-start t ] | ||
| 889 | [ "Go to log buffer" flymake-switch-to-log-buffer t ] | ||
| 890 | "--" | ||
| 891 | [ "Turn off Flymake" flymake-mode t ])) | ||
| 892 | |||
| 877 | (defvar flymake--mode-line-format `(:eval (flymake--mode-line-format))) | 893 | (defvar flymake--mode-line-format `(:eval (flymake--mode-line-format))) |
| 878 | 894 | ||
| 879 | (put 'flymake--mode-line-format 'risky-local-variable t) | 895 | (put 'flymake--mode-line-format 'risky-local-variable t) |
| @@ -903,18 +919,16 @@ applied." | |||
| 903 | "mouse-1: go to log buffer ") | 919 | "mouse-1: go to log buffer ") |
| 904 | keymap | 920 | keymap |
| 905 | ,(let ((map (make-sparse-keymap))) | 921 | ,(let ((map (make-sparse-keymap))) |
| 906 | (define-key map [mode-line mouse-1] | 922 | (define-key map [mode-line down-mouse-1] |
| 907 | (lambda (_event) | 923 | flymake-menu) |
| 908 | (interactive "e") | ||
| 909 | (switch-to-buffer "*Flymake log*"))) | ||
| 910 | map)) | 924 | map)) |
| 911 | ,@(pcase-let ((`(,ind ,face ,explain) | 925 | ,@(pcase-let ((`(,ind ,face ,explain) |
| 912 | (cond ((null known) | 926 | (cond ((null known) |
| 913 | `("?" mode-line "No known backends")) | 927 | `("?" mode-line "No known backends")) |
| 914 | (some-waiting | 928 | (some-waiting |
| 915 | `("Wait" compilation-mode-line-run | 929 | `("Wait" compilation-mode-line-run |
| 916 | ,(format "Waiting for %s running backends" | 930 | ,(format "Waiting for %s running backend(s)" |
| 917 | (length running)))) | 931 | (length some-waiting)))) |
| 918 | (all-disabled | 932 | (all-disabled |
| 919 | `("!" compilation-mode-line-run | 933 | `("!" compilation-mode-line-run |
| 920 | "All backends disabled")) | 934 | "All backends disabled")) |
| @@ -924,7 +938,12 @@ applied." | |||
| 924 | `((":" | 938 | `((":" |
| 925 | (:propertize ,ind | 939 | (:propertize ,ind |
| 926 | face ,face | 940 | face ,face |
| 927 | help-echo ,explain))))) | 941 | help-echo ,explain |
| 942 | keymap | ||
| 943 | ,(let ((map (make-sparse-keymap))) | ||
| 944 | (define-key map [mode-line mouse-1] | ||
| 945 | 'flymake-switch-to-log-buffer) | ||
| 946 | map)))))) | ||
| 928 | ,@(unless (or all-disabled | 947 | ,@(unless (or all-disabled |
| 929 | (null known)) | 948 | (null known)) |
| 930 | (cl-loop | 949 | (cl-loop |