From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: "Philip K." Newsgroups: gmane.emacs.help Subject: Re: PROPOSAL: Repurpose one key and reserve it for third-party packages Date: Thu, 11 Feb 2021 16:47:45 +0100 Message-ID: <87y2fua9ni.fsf@posteo.net> References: <7ef75c33936136eb3a20@heytings.org> <8735y56naf.fsf@posteo.net> <8ed9b43502ae9a36b057@heytings.org> <87tuqk6d9d.fsf@posteo.net> <3966473cc1ab9f104724@heytings.org> <87o8gr1oom.fsf@posteo.net> <87lfbubthl.fsf@posteo.net> Mime-Version: 1.0 Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="28197"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) Cc: help-gnu-emacs@gnu.org To: Gregory Heytings Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Thu Feb 11 16:48:51 2021 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lAED5-0007GL-57 for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 11 Feb 2021 16:48:51 +0100 Original-Received: from localhost ([::1]:49510 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lAED4-0007SG-7y for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 11 Feb 2021 10:48:50 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:52566) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lAEC8-0007BI-DY for help-gnu-emacs@gnu.org; Thu, 11 Feb 2021 10:47:52 -0500 Original-Received: from mout02.posteo.de ([185.67.36.66]:46783) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lAEC5-0006iQ-E9 for help-gnu-emacs@gnu.org; Thu, 11 Feb 2021 10:47:52 -0500 Original-Received: from submission (posteo.de [89.146.220.130]) by mout02.posteo.de (Postfix) with ESMTPS id 2BB132400FD for ; Thu, 11 Feb 2021 16:47:47 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1613058467; bh=0g3POb/Tfh2zvHRVqGusl6xrtBW/aojGItVYtWKOF2g=; h=From:To:Cc:Subject:Date:From; b=RAa7PKbvmGhiAY1HM54DMAsSJIX3JB6c8NelRcDTEZ3OMGaQiBI3nNZw/slNJ0FUL /hddcjLqdUo3d5wiCwMcxiJywZ7ZUakDdeD0t+8k/jRTGKlfClfhE2ouvE68Mq7VNd ygUHO2a8FbyKPUmP8eludCulavkjcx1ljX7voqno9mde6aLKEQHX0NKVm1ExhqMlwY hfb67y7TCcw5C9cTsJz7crjzmvbqr62iXmxjxVAPeFFLdj5uhLl26HHW2USN8cT9Tr 2SyHAWdVcuzzjSZo3941DIpZGRR91rxJqEiK8aPAZEbIoqhywFOyi1auGMBIZdtUM/ Wdn13aaLIwX/g== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4Dc1H61TMmz6tmS; Thu, 11 Feb 2021 16:47:46 +0100 (CET) In-Reply-To: <87lfbubthl.fsf@posteo.net> (Philip K.'s message of "Thu, 11 Feb 2021 14:53:58 +0100") Received-SPF: pass client-ip=185.67.36.66; envelope-from=philipk@posteo.net; helo=mout02.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:127814 Archived-At: --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain "Philip K." writes: > All in all, I don't have a problem with Emacs being able to support it, > but as I've shown with the example in my last message, it doesn't need > to be done automatically, nor does it require a separate key. It's > ultimately up to the user what he or she wants to do, and clever > behind-your-back customization seems more harmful and confusing than the > current state of affairs. Just for the sake of it, this is a draft of how this could look like: --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Add-package-suggest-configuration.patch Content-Transfer-Encoding: quoted-printable From=203e78e4e61462f116a56224e0750401e9b9596e1f Mon Sep 17 00:00:00 2001 From: Philip K Date: Thu, 11 Feb 2021 16:30:09 +0100 Subject: [PATCH] Add package-suggest-configuration =2D-- lisp/emacs-lisp/package.el | 99 ++++++++++++++++++++++++++++++++------ 1 file changed, 85 insertions(+), 14 deletions(-) diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el index 90b7b88d58..6ddd363003 100644 =2D-- a/lisp/emacs-lisp/package.el +++ b/lisp/emacs-lisp/package.el @@ -145,6 +145,7 @@ =20 (require 'cl-lib) (eval-when-compile (require 'subr-x)) +(eval-when-compile (require 'pcase)) (eval-when-compile (require 'epg)) ;For setf accessors. (require 'seq) =20 @@ -2087,6 +2088,88 @@ package--archives-initialize (unless package-archive-contents (package-refresh-contents))) =20 +(defcustom package-ignore-suggestions nil + "Should package-" + :type '(choice (const :tag "Ask the user" nil) + (const :tag "Never ask" t) + (set :tag "Ignore certain suggestions" + (const :tag "Keybindings" key) + (const :tag "User Options" option) + (const :tag "Hooks" hook))) + :version "28.1") + +(defvar pacakge-configuration-suggestions nil + "An alist of advertised default configuration. +Each entry has the form (PACKAGE . SUGGESTIONS), where PACAKGE is +a symbol designating the package, and SUGGESTIONS is another +alist. SUGGESTIONS have the form (TYPE . DATA), where TYPE says +what kind of a suggestion is being made and DATA is the content +of the suggestion. Currently, the following values for TYPE are +understood: + +- `key', where DATA has the form (KEY FUNCTION). It suggests + binding FUNCTION globally to KEY, unless KEY is already bound. + KEY is passed to the function `kbd'. + +- `option', where DATA has the form (OPT VAL). It setting the + symbol OPT to the value VAL. + +- `hook', where DATA has the form (HOOK FUNCTION). It suggests + adding FUNCTION to the hook HOOK. + +All other values for TYPE are ignored.") + +(defun package--query-name (&optional kind verb) + "Query the user for a package name. +If KIND is nil, prompt for all kinds of packages. If KIND is +`installed' only prompt for installed packages. If KIND is +`not-installed', only prompt for packages that have not been +installed. VERB modified to prompt." + ;; Initialize the package system to get the list of package + ;; symbols for completion. + (package--archives-initialize) + (intern (completing-read + (format "%s package: " (or verb "Select")) + (delq nil (mapcar (lambda (elt) + (when (cond + ((eq kind 'installed) + (package-installed-p (car elt))) + ((eq kind 'not-installed) + (not (package-installed-p (car elt)= ))) + ((null kind)) + (t (error "Invalid kind"))) + (symbol-name (car elt)))) + package-archive-contents)) + nil t))) + +(defun package-suggest-configuration (package &optional dont-load) + "Query the user to automatically configure PACKAGE. +If DONT-LOAD is non-nil, do not load the new customization." + (interactive (list (package--query-name 'installed) current-prefix-arg)) + (unless (and (not (called-interactively-p 'any)) + (eq package-ignore-suggestions t)) + (let ((temp-buffer-show-function #'ignore) + (save-silently t)) + (with-temp-buffer + (with-output-to-temp-buffer (current-buffer) + (dolist (sug (cdr (assq package pacakge-configuration-suggestion= s))) + (unless (memq (car sug) package-ignore-suggestions) + (terpri nil t) + (pcase sug + (`(key ,key ,fn) + (when (yes-or-no-p (format "Bind %s to \"%s\"?" fn key)) + (prin1 `(global-set-key (kbd ,key) #',fn)))) + (`(option ,opt ,val) + (when (yes-or-no-p (format "Set option %s to %S?" opt val= )) + (prin1 `(customize-set-variable ',opt ,val)))) + (`(hook ,hook ,fn) + (when (yes-or-no-p (format "Add %s to hook %S?" fn hook)) + (prin1 `(add-hook ',hook #',fn))))))) + (unless dont-load + (eval-buffer)) + (append-to-file (point-min) (point-max) + (or custom-file user-init-file))))))) + ;;;###autoload (defun package-install (pkg &optional dont-select) "Install the package PKG. @@ -2103,20 +2186,7 @@ package-install =20 If PKG is a `package-desc' and it is already installed, don't try to install it but still mark it as selected." =2D (interactive =2D (progn =2D ;; Initialize the package system to get the list of package =2D ;; symbols for completion. =2D (package--archives-initialize) =2D (list (intern (completing-read =2D "Install package: " =2D (delq nil =2D (mapcar (lambda (elt) =2D (unless (package-installed-p (car el= t)) =2D (symbol-name (car elt)))) =2D package-archive-contents)) =2D nil t)) =2D nil))) + (interactive (list (package--query-name 'not-installed "Install"))) (package--archives-initialize) (add-hook 'post-command-hook #'package-menu--post-refresh) (let ((name (if (package-desc-p pkg) @@ -2134,6 +2204,7 @@ package-install (progn (package-download-transaction transaction) (package--quickstart-maybe-refresh) + (package-suggest-configuration pkg) (message "Package `%s' installed." name)) (message "`%s' is already installed" name)))) =20 =2D-=20 2.29.2 --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable =2D-=20 Philip K. --=-=-=-- --==-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQGzBAEBCAAdFiEEbW+YL3e0aNnYosjIGB9bla4wszYFAmAlUaEACgkQGB9bla4w szZeAgv5AfapWafD/uWffg1VgLspOHgLZWRV8aoGGWIFLet10/XjeIfdg9jVFkid EMUaCTDdmiUvJCe+chGWISZpfz8GVwUdI//5OeKaOqI2sOSjb6Ao6ayr78zEQ9H6 qxutlLyq9e3UhYMxo26eIji7CWK7ZDoTCg8u5jPw/SHrUR680267LJwi03Mb1nG6 ltK6ZHRjlZahcVpeQe3dUePuVNertRZKMRqESrzNsKPmimMlcq+hFaWC8ALHrCJP 2QymjMoDcIZ7NoncVWMWWK8vPGLKVg8lln4dbJyo5pfU3YwZr+mIv/RYdq0vbhav igsFPEGuwpIpiMPcxV1RLS3qJoJL+bFpIpx224X/qVFbU2sJ6PM2jqHgQ3RfDKsh jCI+zDuOtwP0IJG0P2hMBxugowokYP26kJjCjNi1SN6QuWjPO+4LutrssLJUDT3x GXQN8DhN5ARIKiDgzOZwmm2bclTDqP1L+P8s5tu6sIx5xAQrv6bcEFu3RCEZedM8 TUo68MFO =L4CG -----END PGP SIGNATURE----- --==-=-=--