Commit 39c2d32a authored by Clément's avatar Clément Committed by Sebastian Wiesner

Fallback to current checker in flycheck-describe-checker

Closes GH-784 and closes GH-787
parent 60734484
......@@ -1790,11 +1790,10 @@ nil otherwise."
(defun flycheck-checker-at-point ()
"Return the Flycheck checker found at or before point.
Return 0 if there is no checker."
Return nil if there is no checker."
(let ((symbol (variable-at-point 'any-symbol)))
(if (and (symbolp symbol) (flycheck-valid-checker-p symbol))
symbol
0)))
(when (flycheck-valid-checker-p symbol)
symbol)))
(defun flycheck-describe-checker (checker)
"Display the documentation of CHECKER.
......@@ -1803,78 +1802,78 @@ CHECKER is a checker symbol.
Pop up a help buffer with the documentation of CHECKER."
(interactive
(let* ((checker (flycheck-checker-at-point))
(enable-recursive-minibuffers t)
(prompt (if (symbolp checker)
(format "Describe syntax checker (default %s): " checker)
"Describe syntax checker: "))
(reply (read-flycheck-checker prompt)))
(list (or reply checker))))
(if (or (null checker) (not (flycheck-valid-checker-p checker)))
(message "You didn't specify a Flycheck syntax checker.")
(help-setup-xref (list #'flycheck-describe-checker checker)
(called-interactively-p 'interactive))
(save-excursion
(with-help-window (help-buffer)
(let ((filename (flycheck-checker-get checker 'file))
(modes (flycheck-checker-get checker 'modes))
(predicate (flycheck-checker-get checker 'predicate))
(print-doc (flycheck-checker-get checker 'print-doc))
(next-checkers (flycheck-checker-get checker 'next-checkers)))
(princ (format "%s is a Flycheck syntax checker" checker))
(when filename
(princ (format " in `%s'" (file-name-nondirectory filename)))
(with-current-buffer standard-output
(save-excursion
(re-search-backward "`\\([^`']+\\)'" nil t)
(help-xref-button 1 'help-flycheck-checker-def checker filename))))
(princ ".\n\n")
(let ((modes-start (with-current-buffer standard-output (point-max))))
;; Track the start of the modes documentation, to properly re-fill
;; it later
(if (not modes)
;; Syntax checkers without modes must have a predicate
(princ " This syntax checker checks syntax if a custom predicate holds")
(princ " This syntax checker checks syntax in the major mode(s) ")
(princ (string-join
(mapcar (apply-partially #'format "`%s'") modes)
", "))
(when predicate
(princ ", and uses a custom predicate")))
(princ ".")
(when next-checkers
(princ " It runs the following checkers afterwards:"))
(with-current-buffer standard-output
(save-excursion
(fill-region-as-paragraph modes-start (point-max))))
(princ "\n")
(let* ((enable-recursive-minibuffers t)
(default (or (flycheck-checker-at-point)
(ignore-errors (flycheck-get-checker-for-buffer))))
(prompt (if default
(format "Describe syntax checker (default %s): " default)
"Describe syntax checker: ")))
(list (read-flycheck-checker prompt default))))
(unless (flycheck-valid-checker-p checker)
(user-error "You didn't specify a Flycheck syntax checker"))
(help-setup-xref (list #'flycheck-describe-checker checker)
(called-interactively-p 'interactive))
(save-excursion
(with-help-window (help-buffer)
(let ((filename (flycheck-checker-get checker 'file))
(modes (flycheck-checker-get checker 'modes))
(predicate (flycheck-checker-get checker 'predicate))
(print-doc (flycheck-checker-get checker 'print-doc))
(next-checkers (flycheck-checker-get checker 'next-checkers)))
(princ (format "%s is a Flycheck syntax checker" checker))
(when filename
(princ (format " in `%s'" (file-name-nondirectory filename)))
(with-current-buffer standard-output
(save-excursion
(re-search-backward "`\\([^`']+\\)'" nil t)
(help-xref-button 1 'help-flycheck-checker-def checker filename))))
(princ ".\n\n")
(let ((modes-start (with-current-buffer standard-output (point-max))))
;; Track the start of the modes documentation, to properly re-fill
;; it later
(if (not modes)
;; Syntax checkers without modes must have a predicate
(princ " This syntax checker checks syntax if a custom predicate holds")
(princ " This syntax checker checks syntax in the major mode(s) ")
(princ (string-join
(mapcar (apply-partially #'format "`%s'") modes)
", "))
(when predicate
(princ ", and uses a custom predicate")))
(princ ".")
(when next-checkers
(princ " It runs the following checkers afterwards:"))
(with-current-buffer standard-output
(save-excursion
(fill-region-as-paragraph modes-start (point-max))))
(princ "\n")
;; Print the list of next checkers
(when next-checkers
(princ "\n")
(let ((beg-checker-list (with-current-buffer standard-output
(point))))
(dolist (next-checker next-checkers)
(if (symbolp next-checker)
(princ (format " * `%s'\n" next-checker))
(princ (format " * `%s' (maximum level `%s')\n"
(cdr next-checker) (car next-checker)))))
;;
(with-current-buffer standard-output
(save-excursion
(while (re-search-backward "`\\([^`']+\\)'"
beg-checker-list t)
(when (flycheck-valid-checker-p
(intern-soft (match-string 1)))
(help-xref-button 1 'help-flycheck-checker-def checker
filename))))))))
;; Call the custom print-doc function of the checker, if present
(when print-doc
(funcall print-doc checker))
;; Ultimately, print the docstring
(princ "\nDocumentation:\n")
(princ (flycheck-checker-get checker 'documentation)))))))
;; Print the list of next checkers
(when next-checkers
(princ "\n")
(let ((beg-checker-list (with-current-buffer standard-output
(point))))
(dolist (next-checker next-checkers)
(if (symbolp next-checker)
(princ (format " * `%s'\n" next-checker))
(princ (format " * `%s' (maximum level `%s')\n"
(cdr next-checker) (car next-checker)))))
;;
(with-current-buffer standard-output
(save-excursion
(while (re-search-backward "`\\([^`']+\\)'"
beg-checker-list t)
(when (flycheck-valid-checker-p
(intern-soft (match-string 1)))
(help-xref-button 1 'help-flycheck-checker-def checker
filename))))))))
;; Call the custom print-doc function of the checker, if present
(when print-doc
(funcall print-doc checker))
;; Ultimately, print the docstring
(princ "\nDocumentation:\n")
(princ (flycheck-checker-get checker 'documentation))))))
;;; Syntax checker verification
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment