summaryrefslogtreecommitdiff
path: root/admin
diff options
context:
space:
mode:
authorPhilip Kaludercic <philipk@posteo.net>2026-01-25 15:43:20 +0100
committerPhilip Kaludercic <philipk@posteo.net>2026-01-25 15:43:20 +0100
commit5a53e277482293e49430b2e53499904fa8c6a5f5 (patch)
treee39dd80e43d3944c91f07c03c74102dc48364187 /admin
parent0fcf1003013bc6af86cb54773788747fbafc6f85 (diff)
parent2a88c6dc3c36f726275554f1b93e32fd726e415c (diff)
Merge branch 'feature/package-autosuggest'
Diffstat (limited to 'admin')
-rw-r--r--admin/scrape-elpa.el81
1 files changed, 81 insertions, 0 deletions
diff --git a/admin/scrape-elpa.el b/admin/scrape-elpa.el
new file mode 100644
index 00000000000..bf3846c0fcb
--- /dev/null
+++ b/admin/scrape-elpa.el
@@ -0,0 +1,81 @@
+;;; scrape-elpa.el --- Collect ELPA package suggestions -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2024 Free Software Foundation, Inc.
+
+;; Author: Philip Kaludercic <philipk@posteo.net>
+;; Keywords: tools
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; This file defines an administrative command to update the
+;; `package-autosuggest' database.
+
+;;; Code:
+
+(defun scrape-elpa (&rest directories)
+ "Scrape autoload files in DIRECTORIES for package suggestions.
+This file will automatically update \"package-autosuggest.eld\", but not
+save it. You should invoke this command with built GNU ELPA and NonGNU
+ELPA checkouts (i.e. having run \"make autoloads\" in both directories).
+Please review the results before updating the autosuggest database!"
+ (interactive (completing-read-multiple
+ "ELPA directories to scrape: "
+ #'completion-file-name-table
+ #'file-directory-p))
+ (with-current-buffer
+ (find-file (expand-file-name "package-autosuggest.eld" data-directory))
+ (erase-buffer)
+ (lisp-data-mode)
+ (insert ";; The contents of this file are loaded into `package-autosuggest-database'
+;; and were automatically generate by scraping ELPA for auto-loaded
+;; code using the `scrape-elpa' command. Please avoid updating this
+;; file manually!
+
+")
+ (fill-paragraph)
+ (insert "(")
+ (let ((standard-output (current-buffer)))
+ (dolist-with-progress-reporter
+ (file (mapcan
+ (lambda (dir)
+ (directory-files-recursively
+ dir "-autoloads\\.el\\'"))
+ directories))
+ "Scraping files..."
+ (and-let* (((string-match "/\\([^/]+?\\)-autoloads\\.el\\'" file))
+ (pkg (intern (match-string 1 file)))
+ (inhibit-message t))
+ (with-temp-buffer
+ (insert-file-contents file)
+ (condition-case nil
+ (while t
+ (dolist (exp (macroexp-unprogn (read (current-buffer))))
+ (pcase exp
+ (`(add-to-list
+ ',(and (or 'interpreter-mode-alist
+ 'magic-mode-alist
+ 'auto-mode-alist)
+ variable)
+ '(,(and (pred stringp) regexp) .
+ ,(and (pred symbolp) mode)))
+ (terpri)
+ (prin1 (append (list pkg variable regexp)
+ (and (not (eq pkg mode)) (list mode))))))))
+ (end-of-file nil))))))
+ (insert "\n)\n")))
+
+(provide 'scrape-elpa)
+;;; scrape-elpa.el ends here