From 0cb99c51a3aa7453a524ab7498fb982416308875 Mon Sep 17 00:00:00 2001 From: Philip Kaludercic Date: Wed, 6 Nov 2024 21:09:57 +0100 Subject: Add command to scrape ELPA for package suggestions * admin/scrape-elpa.el (scrape-elpa): Add new command. * etc/package-autosuggest.eld: Generate file using 'scrape-elpa'. --- admin/scrape-elpa.el | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 admin/scrape-elpa.el (limited to 'admin') diff --git a/admin/scrape-elpa.el b/admin/scrape-elpa.el new file mode 100644 index 00000000000..78dbd7349d0 --- /dev/null +++ b/admin/scrape-elpa.el @@ -0,0 +1,78 @@ +;;; scrape-elpa.el --- Collect ELPA package suggestions -*- lexical-binding: t; -*- + +;; Copyright (C) 2024 Free Software Foundation, Inc. + +;; Author: Philip Kaludercic +;; 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 . + +;;; 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 build-all\" 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..." + (let ((inhibit-message t)) + (with-temp-buffer + (insert-file-contents file) + (condition-case nil + (while t + (pcase (read (current-buffer)) + (`(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 `(,mode ,variable ,regexp)) + (princ (concat " ;from " file))))) + (end-of-file nil)))))) + (insert "\n)\n"))) + +(provide 'scrape-elpa) +;;; scrape-elpa.el ends here -- cgit v1.2.1 From bf72666d41e643a842f1a18950f83874e88d588d Mon Sep 17 00:00:00 2001 From: Philip Kaludercic Date: Thu, 7 Nov 2024 15:26:01 +0100 Subject: Update 'package-autosuggest' database * admin/scrape-elpa.el (scrape-elpa): Detect 'add-to-list' expressions that are "hidden" under a 'progn'. * etc/package-autosuggest.eld: Re-generate database with more packages (after having run "make autoloads") and with the above improvement. --- admin/scrape-elpa.el | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'admin') diff --git a/admin/scrape-elpa.el b/admin/scrape-elpa.el index 78dbd7349d0..0b04ba79982 100644 --- a/admin/scrape-elpa.el +++ b/admin/scrape-elpa.el @@ -29,7 +29,7 @@ "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 build-all\" in both directories). +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: " @@ -60,17 +60,18 @@ Please review the results before updating the autosuggest database!" (insert-file-contents file) (condition-case nil (while t - (pcase (read (current-buffer)) - (`(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 `(,mode ,variable ,regexp)) - (princ (concat " ;from " file))))) + (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 `(,mode ,variable ,regexp)) + (princ (concat " ;from " file)))))) (end-of-file nil)))))) (insert "\n)\n"))) -- cgit v1.2.1 From 450c49af1c629c06669732ca12869f747f773963 Mon Sep 17 00:00:00 2001 From: Philip Kaludercic Date: Thu, 7 Nov 2024 15:56:52 +0100 Subject: Distinguish between suggested packages and major modes * admin/scrape-elpa.el (scrape-elpa): Infer package names from autoloads file. * etc/package-autosuggest.eld: Recompute database. * lisp/emacs-lisp/package.el (package-autosuggest-database): Update documentation to clarify how the major mode can be explicitly indicated. (package--suggestion-applies-p): Handle the optional fourth element. --- admin/scrape-elpa.el | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'admin') diff --git a/admin/scrape-elpa.el b/admin/scrape-elpa.el index 0b04ba79982..ef2b189883e 100644 --- a/admin/scrape-elpa.el +++ b/admin/scrape-elpa.el @@ -55,7 +55,9 @@ Please review the results before updating the autosuggest database!" dir "-autoloads\\.el\\'")) directories)) "Scraping files..." - (let ((inhibit-message t)) + (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 @@ -70,7 +72,8 @@ Please review the results before updating the autosuggest database!" '(,(and (pred stringp) regexp) . ,(and (pred symbolp) mode))) (terpri) - (prin1 `(,mode ,variable ,regexp)) + (prin1 (append (list pkg variable regexp) + (and (not (eq pkg mode)) (list mode)))) (princ (concat " ;from " file)))))) (end-of-file nil)))))) (insert "\n)\n"))) -- cgit v1.2.1 From 40f15ff2dd124e2f7263f0c2c14badb20222a1c3 Mon Sep 17 00:00:00 2001 From: Philip Kaludercic Date: Thu, 7 Nov 2024 16:10:13 +0100 Subject: Drop comments indicating origin of package sugggestions * admin/scrape-elpa.el (scrape-elpa): Do it. * etc/package-autosuggest.eld: Regenerate file. --- admin/scrape-elpa.el | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'admin') diff --git a/admin/scrape-elpa.el b/admin/scrape-elpa.el index ef2b189883e..bf3846c0fcb 100644 --- a/admin/scrape-elpa.el +++ b/admin/scrape-elpa.el @@ -73,8 +73,7 @@ Please review the results before updating the autosuggest database!" ,(and (pred symbolp) mode))) (terpri) (prin1 (append (list pkg variable regexp) - (and (not (eq pkg mode)) (list mode)))) - (princ (concat " ;from " file)))))) + (and (not (eq pkg mode)) (list mode)))))))) (end-of-file nil)))))) (insert "\n)\n"))) -- cgit v1.2.1