unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* bug#70577: [PATCH] New command other-project-prefix
       [not found]     ` <e2d31f31-c6e2-4f1a-81fb-0e222096878e@gutov.dev>
@ 2024-04-28 12:13       ` Sean Whitton via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-04-28 15:56         ` Dmitry Gutov
  2024-04-28 16:46         ` Juri Linkov
  0 siblings, 2 replies; 3+ messages in thread
From: Sean Whitton via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-04-28 12:13 UTC (permalink / raw)
  To: Dmitry Gutov, Juri Linkov, emacs-devel; +Cc: 70577

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





^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: bug#70577: [PATCH] New command other-project-prefix
  2024-04-28 12:13       ` bug#70577: [PATCH] New command other-project-prefix Sean Whitton via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-04-28 15:56         ` Dmitry Gutov
  2024-04-28 16:46         ` Juri Linkov
  1 sibling, 0 replies; 3+ messages in thread
From: Dmitry Gutov @ 2024-04-28 15:56 UTC (permalink / raw)
  To: Sean Whitton, Juri Linkov, emacs-devel; +Cc: 70577

On 28/04/2024 15:13, Sean Whitton wrote:
> 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.

Makes sense. Maybe a helper function, not necessarily a macro.



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: bug#70577: [PATCH] New command other-project-prefix
  2024-04-28 12:13       ` bug#70577: [PATCH] New command other-project-prefix Sean Whitton via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-04-28 15:56         ` Dmitry Gutov
@ 2024-04-28 16:46         ` Juri Linkov
  1 sibling, 0 replies; 3+ messages in thread
From: Juri Linkov @ 2024-04-28 16:46 UTC (permalink / raw)
  To: Sean Whitton; +Cc: Dmitry Gutov, emacs-devel

>> +(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))
>
> 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.

'display-buffer-override-next-command' doesn't contain 'letrec', but
uses the same pattern, so it could benefit from the new macro indeed.



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-04-28 16:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <d29607f5-11e3-4a3a-a29b-d74967234a35@gutov.dev>
     [not found] ` <86le501ykg.fsf@mail.linkov.net>
     [not found]   ` <a8483157-e2dd-409f-8a6c-08f5e339defc@gutov.dev>
     [not found]     ` <e2d31f31-c6e2-4f1a-81fb-0e222096878e@gutov.dev>
2024-04-28 12:13       ` bug#70577: [PATCH] New command other-project-prefix Sean Whitton via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-04-28 15:56         ` Dmitry Gutov
2024-04-28 16:46         ` Juri Linkov

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).