[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 1c73c0b 1/3: Add new command 'checkdoc-dired'
From: |
Stefan Kangas |
Subject: |
master 1c73c0b 1/3: Add new command 'checkdoc-dired' |
Date: |
Tue, 21 Sep 2021 14:08:42 -0400 (EDT) |
branch: master
commit 1c73c0b33a9b10cdae1316ad9e0ba861af454b66
Author: Stefan Kangas <stefan@marxist.se>
Commit: Stefan Kangas <stefan@marxist.se>
Add new command 'checkdoc-dired'
* lisp/emacs-lisp/checkdoc.el (checkdoc-dired): New command.
(checkdoc--dired-skip-lines-re): New constant.
---
etc/NEWS | 4 ++++
lisp/emacs-lisp/checkdoc.el | 33 +++++++++++++++++++++++++++++++++
2 files changed, 37 insertions(+)
diff --git a/etc/NEWS b/etc/NEWS
index 00f46b3..d5b6919 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -2812,6 +2812,10 @@ In addition to verifying the format of the prompt for
'y-or-n-p',
checkdoc will now check the format of 'yes-or-no-p'.
---
+*** New command 'checkdoc-dired'.
+This can be used to run checkdoc on files from a Dired buffer.
+
+---
*** No longer checks for "A-" modifiers.
Checkdoc recommends usage of command substitutions ("\\[foo-command]")
in favor of writing keybindings like "C-c f". It now no longer warns
diff --git a/lisp/emacs-lisp/checkdoc.el b/lisp/emacs-lisp/checkdoc.el
index 07ae855..d797508 100644
--- a/lisp/emacs-lisp/checkdoc.el
+++ b/lisp/emacs-lisp/checkdoc.el
@@ -1070,6 +1070,39 @@ space at the end of each line."
(if (called-interactively-p 'interactive)
(message "Checkdoc: done."))))))
+(defconst checkdoc--dired-skip-lines-re
+ (rx (or (seq bol
+ (or ";; Generated from Unicode data files by unidat"
+ ";; This file is automatically generated from"
+ ";; Generated by the command "))
+ ".el --- automatically extracted autoloads -*- lexical-binding: t
-*-"
+ ";;; lisp/trampver.el. Generated from trampver.el.in by
configure."))
+ "Regexp that when it matches tells `checkdoc-dired' to skip a file.")
+
+(defun checkdoc-dired (files)
+ "In Dired, run `checkdoc' on marked files.
+Skip anything that doesn't have the Emacs Lisp library file
+extension (\".el\").
+When called from Lisp, FILES is a list of filenames."
+ (interactive
+ (list
+ (delq nil
+ (mapcar
+ ;; skip anything that doesn't look like an Emacs Lisp library
+ (lambda (f) (if (equal (file-name-extension f) "el") f nil))
+ (nreverse (dired-map-over-marks (dired-get-filename) nil)))))
+ dired-mode)
+ (if (null files)
+ (error "No files to run checkdoc on")
+ (save-window-excursion
+ (dolist (fil files)
+ (find-file fil)
+ (unless (and
+ (goto-char (point-min))
+ (re-search-forward checkdoc--dired-skip-lines-re nil t))
+ (checkdoc)))))
+ (message "checkdoc-dired: Successfully checked %d files" (length files)))
+
;;; Ispell interface for forcing a spell check
;;