From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Sean Whitton via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs,gmane.emacs.devel Subject: bug#70577: [PATCH] New command other-project-prefix Date: Sun, 28 Apr 2024 13:13:13 +0100 Message-ID: <87wmohlm7a.fsf@zephyr.silentflame.com> References: <86le501ykg.fsf@mail.linkov.net> Reply-To: Sean Whitton Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="1852"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 70577@debbugs.gnu.org To: Dmitry Gutov , Juri Linkov , emacs-devel@gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Apr 28 14:14:07 2024 Return-path: Envelope-to: geb-bug-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 1s13Py-0000GP-74 for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 28 Apr 2024 14:14:07 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s13Pd-0001nZ-1q; Sun, 28 Apr 2024 08:13:45 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s13Pb-0001nE-Eu for bug-gnu-emacs@gnu.org; Sun, 28 Apr 2024 08:13:43 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s13Pb-0004P5-6G for bug-gnu-emacs@gnu.org; Sun, 28 Apr 2024 08:13:43 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1s13Pu-0000Nn-Gv for bug-gnu-emacs@gnu.org; Sun, 28 Apr 2024 08:14:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Sean Whitton Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 28 Apr 2024 12:14:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 70577 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 70577-submit@debbugs.gnu.org id=B70577.17143064241442 (code B ref 70577); Sun, 28 Apr 2024 12:14:02 +0000 Original-Received: (at 70577) by debbugs.gnu.org; 28 Apr 2024 12:13:44 +0000 Original-Received: from localhost ([127.0.0.1]:50240 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s13Pb-0000NC-MP for submit@debbugs.gnu.org; Sun, 28 Apr 2024 08:13:44 -0400 Original-Received: from wfout5-smtp.messagingengine.com ([64.147.123.148]:34819) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s13PZ-0000N4-7v for 70577@debbugs.gnu.org; Sun, 28 Apr 2024 08:13:42 -0400 Original-Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfout.west.internal (Postfix) with ESMTP id 4101A1C000FD; Sun, 28 Apr 2024 08:13:15 -0400 (EDT) Original-Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Sun, 28 Apr 2024 08:13:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=spwhitton.name; h=cc:cc:content-type:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm2; t=1714306394; x= 1714392794; bh=pJxBkUWzzeEO/0Mge+GkWdxc7uszPwMGfEffQU86lOI=; b=j EPjr1/pVIuakocWSuf8QYJILEAW9FxRlGgzNO4VUJQH2sZO1JClW4kJqY5rRBLEu xNZtfSYhRYkoW078aGnBf3s8CpvQTMU2GbQNFpIiVWmN6V9d+25uhKy+aZ1/6QX8 IPATMhjLDAGhElwdo8VZ1DhPtDxxMWMbYActKBogoNun8f5T+eVmzDdxCb2DcduD gKIFIT3gE/0dsGgzIN82Gs5qxgFc9aXpni+Ta15F+wVtQ6ln04W2onLWTWZ/rvIz a7d/dx93S4WKSyuJezqWIoyEmc0VPrufxGRNxFnq3cLvHIrvD2bt1AGLEvG0N5dv 9Pcr/idKmBg8AtH/QYPCg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1714306394; x=1714392794; bh=pJxBkUWzzeEO/0Mge+GkWdxc7usz PwMGfEffQU86lOI=; b=TayIWUaHU6Rs5C7rV2wMSm2PE51EjdJY5PXRL6JKa+st F+Tl+ThkR/rjG0nBDdEfbvnLcRxC+kwkM71l166mmJVMTCaRmfNGpMo/pYRExw5p FO53MQ5npcW+nyKnOp/t3qEumPVxmplkgH5zefaBaHiJBCpoPdF+SjeNqVN8zTjS 8tO9asgzabzppTAKvHdzAV8Op/xINkdQF+ZqoQ7XjfrnhvcQTdW/oRIdg52he/BK CbM831sYfiIlvjvTiYaQWqBTKzgWMvIaF0HmfPvhna7QDBpKN6yF5Bk4clHmFjRF 7c/MBBnII+11ubnCdjFo2u2LEaE9u/R7/sxlDF5Y4A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvddtgedgjeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefujghffffkfgggtgesthdttddttdertdenucfhrhhomhepufgvrghn ucghhhhithhtohhnuceoshhpfihhihhtthhonhesshhpfihhihhtthhonhdrnhgrmhgvqe enucggtffrrghtthgvrhhnpedtffdvffeuleeuvdetkedvveehgfehvdegvefghfevudek geegleevgeejkeetkeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrih hlfhhrohhmpehsphifhhhithhtohhnsehsphifhhhithhtohhnrdhnrghmvg X-ME-Proxy: Feedback-ID: i23c04076:Fastmail Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 28 Apr 2024 08:13:14 -0400 (EDT) Original-Received: by zephyr.silentflame.com (Postfix, from userid 1000) id 1C29794078C; Sun, 28 Apr 2024 13:13:13 +0100 (BST) In-Reply-To: (Dmitry Gutov's message of "Fri, 26 Apr 2024 19:20:58 +0300") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:284087 gmane.emacs.devel:318278 Archived-At: Hello, On Fri 26 Apr 2024 at 07:20pm +03, Dmitry Gutov wrote: > +;;;###autoload > +(defun other-project-prefix () > + "\"Switch\" to another project before running an Emacs command. > +Makes sure the next command invoked asks for the project to run it in." > + (interactive) > + (prefix-command-preserve-state) > + (letrec ((depth (minibuffer-depth)) > + (echofun (lambda () "[switch-project]")) > + (around-fun > + (lambda (command &rest _args) > + (advice-remove this-command around-fun) > + (unless (or (eq this-command 'other-project-prefix) > + (eq last-command-event help-char)) > + (let ((root (funcall project-prompter))) > + (if (or (string-prefix-p "project-" > + (symbol-name this-command)) > + (get this-command 'project-aware)) > + (let ((project-current-directory-override root)) > + (call-interactively command)) > + (let ((default-directory root)) > + (call-interactively command))))))) > + (prefun > + (lambda () > + (unless (> (minibuffer-depth) depth) > + (remove-hook 'pre-command-hook prefun) > + (remove-hook 'prefix-command-echo-keystrokes-functions echofun) > + (when (and this-command (symbolp this-command)) > + (advice-add this-command :around around-fun)))))) > + (add-hook 'pre-command-hook prefun) > + (add-hook 'prefix-command-echo-keystrokes-functions echofun) > + (let ((map (make-sparse-keymap))) > + (set-keymap-parent map project-prefix-map) > + ;; Doesn't work ;-( > + ;; (define-key map (vector help-char) > + ;; (lambda () (interactive) (help-form-show))) > + (set-transient-map map)) > + (message (concat "Type " (project--keymap-prompt) " or any global key")))) In passing, this pattern where you letrec a hook that removes itself, and also consider minibuffer-depth, is now in several places. The one I am thinking of is vc-edit-next-command but I based that on some code of Juri's somewhere. It would be good to factor out a macro for this pattern, I think. -- Sean Whitton