From 1ff0c58fee23356b3a3ef1c7fee24e22fa020356 Mon Sep 17 00:00:00 2001 From: Juri Linkov Date: Fri, 30 Jan 2026 09:41:42 +0200 Subject: [PATCH] New function 'checkdoc-batch' (bug#80199) * lisp/emacs-lisp/checkdoc.el (checkdoc--batch-flag): New variable. (checkdoc-rogue-spaces, checkdoc-message-text): Use it along the check for interactive calls to be able to collect errors in the diagnostic buffer. (checkdoc-show-diagnostics): Don't show the diagnostic buffer when 'checkdoc--batch-flag' is non-nil. (checkdoc-batch): New function to check the buffer and print the content of the diagnostic buffer. --- etc/NEWS | 5 +++++ lisp/emacs-lisp/checkdoc.el | 29 +++++++++++++++++++++++++---- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index 1838a1ec3e5..eca0c070783 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -2087,6 +2087,11 @@ for docstrings where symbols 'nil' and 't' are in quotes. In most cases, having it enabled leads to a large amount of false positives. +--- +*** New function 'checkdoc-batch'. +It checks the buffer in batch mode, prints all found errors +and signals the first found error. + *** New file-local variable 'lisp-indent-local-overrides'. This variable can be used to locally override the indent specification of symbols. diff --git a/lisp/emacs-lisp/checkdoc.el b/lisp/emacs-lisp/checkdoc.el index c9f9082a27a..fd226b89fda 100644 --- a/lisp/emacs-lisp/checkdoc.el +++ b/lisp/emacs-lisp/checkdoc.el @@ -381,6 +381,9 @@ large number of libraries means it is impractical to fix all of these warnings masse. In almost any other case, setting this to anything but t is likely to be counter-productive.") +(defvar checkdoc--batch-flag nil + "Non-nil in batch mode.") + (defun checkdoc-list-of-strings-p (obj) "Return t when OBJ is a list of strings." (declare (obsolete list-of-strings-p "29.1")) @@ -1063,12 +1066,13 @@ Optional argument INTERACT permits more interactive fixing." (e (checkdoc-rogue-space-check-engine nil nil interact)) (checkdoc-generate-compile-warnings-flag (or take-notes checkdoc-generate-compile-warnings-flag))) - (if (not (called-interactively-p 'interactive)) + (if (not (or (called-interactively-p 'interactive) checkdoc--batch-flag)) e (if e (message "%s" (checkdoc-error-text e)) (checkdoc-show-diagnostics) - (message "Space Check: done."))))) + (if (called-interactively-p 'interactive) + (message "Space Check: done.")))))) ;;;###autoload (defun checkdoc-message-text (&optional take-notes) @@ -1081,7 +1085,7 @@ Optional argument TAKE-NOTES causes all errors to be logged." (checkdoc-generate-compile-warnings-flag (or take-notes checkdoc-generate-compile-warnings-flag))) (setq e (checkdoc-message-text-search)) - (if (not (called-interactively-p 'interactive)) + (if (not (or (called-interactively-p 'interactive) checkdoc--batch-flag)) e (if e (user-error "%s" (checkdoc-error-text e)) @@ -2819,7 +2823,7 @@ function called to create the messages." (defun checkdoc-show-diagnostics () "Display the checkdoc diagnostic buffer in a temporary window." - (if checkdoc-pending-errors + (if (and checkdoc-pending-errors (not checkdoc--batch-flag)) (let* ((b (get-buffer checkdoc-diagnostic-buffer)) (win (if b (display-buffer b)))) (when win @@ -2832,6 +2836,23 @@ function called to create the messages." (setq checkdoc-pending-errors nil) nil))) + +;;;###autoload +(defun checkdoc-batch () + "Check current buffer in batch mode. +Report any errors and signal the first found error." + (when noninteractive + (let ((checkdoc-autofix-flag nil) + (checkdoc--batch-flag t)) + (checkdoc-current-buffer t) + (when checkdoc-pending-errors + (when-let* ((b (get-buffer checkdoc-diagnostic-buffer))) + (with-current-buffer b + (princ (buffer-string))) + (terpri)) + (checkdoc-current-buffer))))) + + (defun checkdoc-get-keywords () "Return a list of package keywords for the current file." (save-excursion