aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorJoão Távora2017-08-17 14:18:00 +0100
committerJoão Távora2017-08-17 14:18:00 +0100
commit13993c46a21495167517f76d2e36b6c09ac5e89e (patch)
tree31002875c3e8f9cb3e41575afed1e3c56f0d864a /lisp
parenteb34f7f5a29e7bf62326ecb6e693f28878be28cd (diff)
downloademacs-13993c46a21495167517f76d2e36b6c09ac5e89e.tar.gz
emacs-13993c46a21495167517f76d2e36b6c09ac5e89e.zip
Add flymake-backends defcustom
* lisp/progmodes/flymake-proc.el (flymake-proc-can-syntax-check-buffer): Rename from flymake-can-syntax-check-file. Suitable for adding to flymake-backends. (flymake-proc-start-syntax-check): Rename from flymake-start-syntax-check. Don't check again if buffer can be checked. (add-to-list flymake-backends): Hook only flymake-ui.el * lisp/progmodes/flymake-ui.el (flymake-backends): New defcustom. (flymake-on-timer-event, flymake-after-change-function) (flymake-after-save-hook, flymake-find-file-hook): Call new flymake--start-syntax-check-buffer and flymake--can-syntax-check-buffer. (flymake-mode): Call flymake--can-syntax-check-buffer and set flymake-backend. (flymake--backend): New buffer-local variable.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/progmodes/flymake-proc.el23
-rw-r--r--lisp/progmodes/flymake-ui.el84
2 files changed, 73 insertions, 34 deletions
diff --git a/lisp/progmodes/flymake-proc.el b/lisp/progmodes/flymake-proc.el
index 8a2fede2df5..30555559e60 100644
--- a/lisp/progmodes/flymake-proc.el
+++ b/lisp/progmodes/flymake-proc.el
@@ -120,10 +120,12 @@ NAME is the file name function to use, default `flymake-get-real-file-name'."
120 (flymake-log 3 "file %s, init=%s" file-name (car mode-and-masks)) 120 (flymake-log 3 "file %s, init=%s" file-name (car mode-and-masks))
121 mode-and-masks)) 121 mode-and-masks))
122 122
123(defun flymake-can-syntax-check-file (file-name) 123(defun flymake-proc-can-syntax-check-buffer ()
124 "Determine whether we can syntax check FILE-NAME. 124 "Determine whether we can syntax check current buffer.
125Return nil if we cannot, non-nil if we can." 125Return nil if we cannot, non-nil if
126 (if (flymake-get-init-function file-name) t nil)) 126we can."
127 (and buffer-file-name
128 (if (flymake-get-init-function buffer-file-name) t nil)))
127 129
128(defun flymake-get-init-function (file-name) 130(defun flymake-get-init-function (file-name)
129 "Return init function to be used for the file." 131 "Return init function to be used for the file."
@@ -714,12 +716,11 @@ Return its components if so, nil otherwise."
714 (error 716 (error
715 (flymake-log 1 "Failed to delete dir %s, error ignored" dir-name)))) 717 (flymake-log 1 "Failed to delete dir %s, error ignored" dir-name))))
716 718
717(defun flymake-start-syntax-check () 719(defun flymake-proc-start-syntax-check ()
718 "Start syntax checking for current buffer." 720 "Start syntax checking for current buffer."
719 (interactive) 721 (interactive)
720 (flymake-log 3 "flymake is running: %s" flymake-is-running) 722 (flymake-log 3 "flymake is running: %s" flymake-is-running)
721 (when (and (not flymake-is-running) 723 (when (not flymake-is-running)
722 (flymake-can-syntax-check-file buffer-file-name))
723 (when (or (not flymake-compilation-prevents-syntax-check) 724 (when (or (not flymake-compilation-prevents-syntax-check)
724 (not (flymake-compilation-is-running))) ;+ (flymake-rep-ort-status buffer "COMP") 725 (not (flymake-compilation-is-running))) ;+ (flymake-rep-ort-status buffer "COMP")
725 (flymake-clear-buildfile-cache) 726 (flymake-clear-buildfile-cache)
@@ -1084,5 +1085,13 @@ Use CREATE-TEMP-F for creating temp copy."
1084 (list "val" (flymake-init-create-temp-buffer-copy 1085 (list "val" (flymake-init-create-temp-buffer-copy
1085 'flymake-create-temp-inplace)))) 1086 'flymake-create-temp-inplace))))
1086 1087
1088
1089;;;; Hook onto flymake-ui
1090
1091(add-to-list 'flymake-backends
1092 `(flymake-proc-can-syntax-check-buffer
1093 .
1094 flymake-proc-start-syntax-check))
1095
1087(provide 'flymake-proc) 1096(provide 'flymake-proc)
1088;;; flymake-proc.el ends here 1097;;; flymake-proc.el ends here
diff --git a/lisp/progmodes/flymake-ui.el b/lisp/progmodes/flymake-ui.el
index c1dffb4e7ef..3fb1ecaa7f0 100644
--- a/lisp/progmodes/flymake-ui.el
+++ b/lisp/progmodes/flymake-ui.el
@@ -108,6 +108,17 @@ See `flymake-error-bitmap' and `flymake-warning-bitmap'."
108 :group 'flymake 108 :group 'flymake
109 :type 'integer) 109 :type 'integer)
110 110
111(defcustom flymake-backends '()
112 "Ordered list of backends providing syntax check information for a buffer.
113Value is an alist of conses (PREDICATE . CHECKER). Both PREDICATE
114and CHECKER are functions called with a single argument, the
115buffer in which `flymake-mode' was enabled. PREDICATE is expected
116to (quickly) return t or nil if the buffer can be syntax checked
117by CHECKER, which in can performs more morose operations,
118possibly asynchronously."
119 :group 'flymake
120 :type 'alist)
121
111(defvar-local flymake-timer nil 122(defvar-local flymake-timer nil
112 "Timer for starting syntax check.") 123 "Timer for starting syntax check.")
113 124
@@ -368,7 +379,7 @@ For the format of LINE-ERR-INFO, see `flymake-ler-make-ler'."
368 379
369 (setq flymake-last-change-time nil) 380 (setq flymake-last-change-time nil)
370 (flymake-log 3 "starting syntax check as more than 1 second passed since last change") 381 (flymake-log 3 "starting syntax check as more than 1 second passed since last change")
371 (flymake-start-syntax-check))))) 382 (flymake--start-syntax-check)))))
372 383
373(define-obsolete-function-alias 'flymake-display-err-menu-for-current-line 384(define-obsolete-function-alias 'flymake-display-err-menu-for-current-line
374 'flymake-popup-current-error-menu "24.4") 385 'flymake-popup-current-error-menu "24.4")
@@ -442,6 +453,20 @@ For the format of LINE-ERR-INFO, see `flymake-ler-make-ler'."
442 (flymake-log 0 "switched OFF Flymake mode for buffer %s due to fatal status %s, warning %s" 453 (flymake-log 0 "switched OFF Flymake mode for buffer %s due to fatal status %s, warning %s"
443 (buffer-name) status warning)) 454 (buffer-name) status warning))
444 455
456(defvar-local flymake--backend nil
457 "The currently active backend selected by `flymake-mode'")
458
459(defun flymake--can-syntax-check-buffer (buffer)
460 (let ((all flymake-backends)
461 (candidate))
462 (catch 'done
463 (while (setq candidate (pop all))
464 (when (with-current-buffer buffer (funcall (car candidate)))
465 (throw 'done (cdr candidate)))))))
466
467(defun flymake--start-syntax-check ()
468 (funcall flymake--backend))
469
445;;;###autoload 470;;;###autoload
446(define-minor-mode flymake-mode nil 471(define-minor-mode flymake-mode nil
447 :group 'flymake :lighter flymake-mode-line 472 :group 'flymake :lighter flymake-mode-line
@@ -449,31 +474,36 @@ For the format of LINE-ERR-INFO, see `flymake-ler-make-ler'."
449 474
450 ;; Turning the mode ON. 475 ;; Turning the mode ON.
451 (flymake-mode 476 (flymake-mode
452 (cond 477 (let* ((backend (flymake--can-syntax-check-buffer (current-buffer))))
453 ((not buffer-file-name) 478 (cond
454 (message "Flymake unable to run without a buffer file name")) 479 ((not backend)
455 ((not (flymake-can-syntax-check-file buffer-file-name)) 480 (flymake-log 2 "flymake cannot check syntax in buffer %s" (buffer-name)))
456 (flymake-log 2 "flymake cannot check syntax in buffer %s" (buffer-name))) 481 (t
457 (t 482 (setq flymake--backend backend)
458 (add-hook 'after-change-functions 'flymake-after-change-function nil t) 483
459 (add-hook 'after-save-hook 'flymake-after-save-hook nil t) 484 (add-hook 'after-change-functions 'flymake-after-change-function nil t)
460 (add-hook 'kill-buffer-hook 'flymake-kill-buffer-hook nil t) 485 (add-hook 'after-save-hook 'flymake-after-save-hook nil t)
461 ;;+(add-hook 'find-file-hook 'flymake-find-file-hook) 486 (add-hook 'kill-buffer-hook 'flymake-kill-buffer-hook nil t)
462 487 ;;+(add-hook 'find-file-hook 'flymake-find-file-hook)
463 (flymake-report-status "" "") 488
464 489 (flymake-report-status "" "")
465 (setq flymake-timer 490
466 (run-at-time nil 1 'flymake-on-timer-event (current-buffer))) 491 (setq flymake-timer
467 492 (run-at-time nil 1 'flymake-on-timer-event (current-buffer)))
468 (when (and flymake-start-syntax-check-on-find-file 493
469 ;; Since we write temp files in current dir, there's no point 494 (when (and flymake-start-syntax-check-on-find-file
470 ;; trying if the directory is read-only (bug#8954). 495 ;; Since we write temp files in current dir, there's no point
471 (file-writable-p (file-name-directory buffer-file-name))) 496 ;; trying if the directory is read-only (bug#8954).
472 (with-demoted-errors 497 (file-writable-p (file-name-directory buffer-file-name)))
473 (flymake-start-syntax-check)))))) 498 (with-demoted-errors
499 (flymake--start-syntax-check)))))
500 )
501 )
474 502
475 ;; Turning the mode OFF. 503 ;; Turning the mode OFF.
476 (t 504 (t
505 (setq flymake--backend nil)
506
477 (remove-hook 'after-change-functions 'flymake-after-change-function t) 507 (remove-hook 'after-change-functions 'flymake-after-change-function t)
478 (remove-hook 'after-save-hook 'flymake-after-save-hook t) 508 (remove-hook 'after-save-hook 'flymake-after-save-hook t)
479 (remove-hook 'kill-buffer-hook 'flymake-kill-buffer-hook t) 509 (remove-hook 'kill-buffer-hook 'flymake-kill-buffer-hook t)
@@ -505,14 +535,14 @@ For the format of LINE-ERR-INFO, see `flymake-ler-make-ler'."
505 (let((new-text (buffer-substring start stop))) 535 (let((new-text (buffer-substring start stop)))
506 (when (and flymake-start-syntax-check-on-newline (equal new-text "\n")) 536 (when (and flymake-start-syntax-check-on-newline (equal new-text "\n"))
507 (flymake-log 3 "starting syntax check as new-line has been seen") 537 (flymake-log 3 "starting syntax check as new-line has been seen")
508 (flymake-start-syntax-check)) 538 (flymake--start-syntax-check))
509 (setq flymake-last-change-time (float-time)))) 539 (setq flymake-last-change-time (float-time))))
510 540
511(defun flymake-after-save-hook () 541(defun flymake-after-save-hook ()
512 (if (local-variable-p 'flymake-mode (current-buffer)) ; (???) other way to determine whether flymake is active in buffer being saved? 542 (if (local-variable-p 'flymake-mode (current-buffer)) ; (???) other way to determine whether flymake is active in buffer being saved?
513 (progn 543 (progn
514 (flymake-log 3 "starting syntax check as buffer was saved") 544 (flymake-log 3 "starting syntax check as buffer was saved")
515 (flymake-start-syntax-check)))) ; no more mode 3. cannot start check if mode 3 (to temp copies) is active - (???) 545 (flymake--start-syntax-check)))) ; no more mode 3. cannot start check if mode 3 (to temp copies) is active - (???)
516 546
517(defun flymake-kill-buffer-hook () 547(defun flymake-kill-buffer-hook ()
518 (when flymake-timer 548 (when flymake-timer
@@ -523,10 +553,10 @@ For the format of LINE-ERR-INFO, see `flymake-ler-make-ler'."
523(defun flymake-find-file-hook () 553(defun flymake-find-file-hook ()
524 ;;+(when flymake-start-syntax-check-on-find-file 554 ;;+(when flymake-start-syntax-check-on-find-file
525 ;;+ (flymake-log 3 "starting syntax check on file open") 555 ;;+ (flymake-log 3 "starting syntax check on file open")
526 ;;+ (flymake-start-syntax-check) 556 ;;+ (flymake--start-syntax-check)
527 ;;+) 557 ;;+)
528 (when (and (not (local-variable-p 'flymake-mode (current-buffer))) 558 (when (and (not (local-variable-p 'flymake-mode (current-buffer)))
529 (flymake-can-syntax-check-file buffer-file-name)) 559 (flymake--can-syntax-check-buffer (current-buffer)))
530 (flymake-mode) 560 (flymake-mode)
531 (flymake-log 3 "automatically turned ON flymake mode"))) 561 (flymake-log 3 "automatically turned ON flymake mode")))
532 562