all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#45134: Add project-switch-project-by-name
@ 2020-12-09 15:14 Rudolf Schlatte
  2020-12-09 15:21 ` Lars Ingebrigtsen
  2020-12-09 19:36 ` Dmitry Gutov
  0 siblings, 2 replies; 7+ messages in thread
From: Rudolf Schlatte @ 2020-12-09 15:14 UTC (permalink / raw)
  To: 45134

Certain “dashboard-type” packages present a list of projects and let the
user switch to one of them.  In that case, the project root is already
known, and project.el only needs to present the dispatch menu of
‘project-switch-commands’.  As an example, see
‘dashboard-projects-switch-function’ at
https://github.com/emacs-dashboard/emacs-dashboard/blob/75f0c46db03b40ec983dbf4aa81e2ccb2e4a16ef/dashboard-widgets.el#L696

This patch adds a function ‘project-switch-project-by-name’, analogous
to ‘projectile-switch-project-by-name’.  I hope the diff makes it
through unmangled..

I have signed papers for emacs, in case this is not a trivial patch.



diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index 449eadc3de..f83ad4f6fc 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -1280,12 +1280,19 @@ project-switch-project
 The available commands are presented as a dispatch menu
 made from `project-switch-commands'."
   (interactive)
-  (let ((dir (project-prompt-project-dir))
-        (choice nil))
+  (let ((dir (project-prompt-project-dir)))
+    (project-switch-project-by-name dir)))
+
+;;;###autoload
+(defun project-switch-project-by-name (project-root)
+  "\"Switch\" to the project in PROJECT-ROOT and run an Emacs command.
+The available commands are presented as a dispatch menu made from
+`project-switch-commands'."
+  (let ((choice nil))
     (while (not choice)
       (setq choice (assq (read-event (project--keymap-prompt))
                          project-switch-commands)))
-    (let ((default-directory dir)
+    (let ((default-directory project-root)
           (project-current-inhibit-prompt t))
       (call-interactively (nth 2 choice)))))
 





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

* bug#45134: Add project-switch-project-by-name
  2020-12-09 15:14 bug#45134: Add project-switch-project-by-name Rudolf Schlatte
@ 2020-12-09 15:21 ` Lars Ingebrigtsen
  2020-12-09 15:42   ` Rudolf Schlatte
  2020-12-09 19:36 ` Dmitry Gutov
  1 sibling, 1 reply; 7+ messages in thread
From: Lars Ingebrigtsen @ 2020-12-09 15:21 UTC (permalink / raw)
  To: Rudolf Schlatte; +Cc: 45134

Rudolf Schlatte <rudi@constantly.at> writes:

> Certain “dashboard-type” packages present a list of projects and let the
> user switch to one of them.  In that case, the project root is already
> known, and project.el only needs to present the dispatch menu of
> ‘project-switch-commands’.  As an example, see
> ‘dashboard-projects-switch-function’ at
> https://github.com/emacs-dashboard/emacs-dashboard/blob/75f0c46db03b40ec983dbf4aa81e2ccb2e4a16ef/dashboard-widgets.el#L696
>
> This patch adds a function ‘project-switch-project-by-name’, analogous
> to ‘projectile-switch-project-by-name’.  I hope the diff makes it
> through unmangled..

Makes sense to me.

> +(defun project-switch-project-by-name (project-root)
> +  "\"Switch\" to the project in PROJECT-ROOT and run an Emacs command.

But is this the best name for this function?  PROJECT-ROOT isn't the
name of the project, but a directory.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





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

* bug#45134: Add project-switch-project-by-name
  2020-12-09 15:21 ` Lars Ingebrigtsen
@ 2020-12-09 15:42   ` Rudolf Schlatte
  2020-12-09 15:47     ` Rudolf Schlatte
  0 siblings, 1 reply; 7+ messages in thread
From: Rudolf Schlatte @ 2020-12-09 15:42 UTC (permalink / raw)
  To: 45134

Lars Ingebrigtsen <larsi@gnus.org> writes:

> Rudolf Schlatte <rudi@constantly.at> writes:
>
>> Certain “dashboard-type” packages present a list of projects and let the
>> user switch to one of them.  In that case, the project root is already
>> known, and project.el only needs to present the dispatch menu of
>> ‘project-switch-commands’.  As an example, see
>> ‘dashboard-projects-switch-function’ at
>> https://github.com/emacs-dashboard/emacs-dashboard/blob/75f0c46db03b40ec983dbf4aa81e2ccb2e4a16ef/dashboard-widgets.el#L696
>>
>> This patch adds a function ‘project-switch-project-by-name’, analogous
>> to ‘projectile-switch-project-by-name’.  I hope the diff makes it
>> through unmangled..
>
> Makes sense to me.
>
>> +(defun project-switch-project-by-name (project-root)
>> +  "\"Switch\" to the project in PROJECT-ROOT and run an Emacs command.
>
> But is this the best name for this function?  PROJECT-ROOT isn't the
> name of the project, but a directory.

You mean the argument name?  Fine with renaming that - PROJECT-DIR or
DIR are all ok (DIR is used in ‘project-switch-project’ just above the
added function, so maybe that’s best).

Even though the argument is a directory, I chose the function name
‘project-switch-project-by-name’ to stay close to projectile, which uses
‘projectile-switch-project-by-name’ for the analogous function.






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

* bug#45134: Add project-switch-project-by-name
  2020-12-09 15:42   ` Rudolf Schlatte
@ 2020-12-09 15:47     ` Rudolf Schlatte
  0 siblings, 0 replies; 7+ messages in thread
From: Rudolf Schlatte @ 2020-12-09 15:47 UTC (permalink / raw)
  To: 45134

Rudolf Schlatte <rudi@constantly.at> writes:

> Lars Ingebrigtsen <larsi@gnus.org> writes:
>
>> Rudolf Schlatte <rudi@constantly.at> writes:
>>
>>> +(defun project-switch-project-by-name (project-root)
>>> +  "\"Switch\" to the project in PROJECT-ROOT and run an Emacs command.
>>
>> But is this the best name for this function?  PROJECT-ROOT isn't the
>> name of the project, but a directory.
>
> You mean the argument name?  Fine with renaming that - PROJECT-DIR or
> DIR are all ok (DIR is used in ‘project-switch-project’ just above the
> added function, so maybe that’s best).
>
> Even though the argument is a directory, I chose the function name
> ‘project-switch-project-by-name’ to stay close to projectile, which uses
> ‘projectile-switch-project-by-name’ for the analogous function.

L’esprit d’escalier kicking in ...  Of course it’s also fine to use
another function name; internal naming consistency is as important as
consistency with another project.  I’ll leave it up to the maintainers,
with thanks for considering the patch.  :)






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

* bug#45134: Add project-switch-project-by-name
  2020-12-09 15:14 bug#45134: Add project-switch-project-by-name Rudolf Schlatte
  2020-12-09 15:21 ` Lars Ingebrigtsen
@ 2020-12-09 19:36 ` Dmitry Gutov
  2020-12-09 20:21   ` Rudolf Schlatte
  1 sibling, 1 reply; 7+ messages in thread
From: Dmitry Gutov @ 2020-12-09 19:36 UTC (permalink / raw)
  To: Rudolf Schlatte, 45134

On 09.12.2020 17:14, Rudolf Schlatte wrote:
> Certain “dashboard-type” packages present a list of projects and let the
> user switch to one of them.  In that case, the project root is already
> known, and project.el only needs to present the dispatch menu of
> ‘project-switch-commands’.

So the idea is you know the directory in advance and only need to show 
the dispatch menu?

How about this instead?

diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index 449eadc3de..f7c6a55f44 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -1275,13 +1275,13 @@ project--keymap-prompt
     "  "))

  ;;;###autoload
-(defun project-switch-project ()
+(defun project-switch-project (dir)
    "\"Switch\" to another project by running an Emacs command.
  The available commands are presented as a dispatch menu
  made from `project-switch-commands'."
-  (interactive)
-  (let ((dir (project-prompt-project-dir))
-        (choice nil))
+  (interactive
+   (list (project-prompt-project-dir)))
+  (let ((choice nil))
      (while (not choice)
        (setq choice (assq (read-event (project--keymap-prompt))
                           project-switch-commands)))






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

* bug#45134: Add project-switch-project-by-name
  2020-12-09 19:36 ` Dmitry Gutov
@ 2020-12-09 20:21   ` Rudolf Schlatte
  2020-12-09 20:57     ` Dmitry Gutov
  0 siblings, 1 reply; 7+ messages in thread
From: Rudolf Schlatte @ 2020-12-09 20:21 UTC (permalink / raw)
  To: 45134

Dmitry Gutov <dgutov@yandex.ru> writes:

> On 09.12.2020 17:14, Rudolf Schlatte wrote:
>> Certain “dashboard-type” packages present a list of projects and let the
>> user switch to one of them.  In that case, the project root is already
>> known, and project.el only needs to present the dispatch menu of
>> ‘project-switch-commands’.
>
> So the idea is you know the directory in advance and only need to show
> the dispatch menu?

Yes, exactly.

> How about this instead?

Tested and works as expected, both invoked with ‘C-x p p’ where it
prompts for a project first, and from dashboard where it shows the
dispatch menu immediately for the chosen project.  Very nice!

> diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
> index 449eadc3de..f7c6a55f44 100644
> --- a/lisp/progmodes/project.el
> +++ b/lisp/progmodes/project.el
> @@ -1275,13 +1275,13 @@ project--keymap-prompt
>     "  "))
>
>  ;;;###autoload
> -(defun project-switch-project ()
> +(defun project-switch-project (dir)
>    "\"Switch\" to another project by running an Emacs command.
>  The available commands are presented as a dispatch menu
>  made from `project-switch-commands'."
> -  (interactive)
> -  (let ((dir (project-prompt-project-dir))
> -        (choice nil))
> +  (interactive
> +   (list (project-prompt-project-dir)))
> +  (let ((choice nil))
>      (while (not choice)
>        (setq choice (assq (read-event (project--keymap-prompt))
>                           project-switch-commands)))






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

* bug#45134: Add project-switch-project-by-name
  2020-12-09 20:21   ` Rudolf Schlatte
@ 2020-12-09 20:57     ` Dmitry Gutov
  0 siblings, 0 replies; 7+ messages in thread
From: Dmitry Gutov @ 2020-12-09 20:57 UTC (permalink / raw)
  To: Rudolf Schlatte, 45134-done

Version: 28.1

On 09.12.2020 22:21, Rudolf Schlatte wrote:
> Tested and works as expected, both invoked with ‘C-x p p’ where it
> prompts for a project first, and from dashboard where it shows the
> dispatch menu immediately for the chosen project.  Very nice!

Thanks for checking! Pushed in 5af6a87d51.





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

end of thread, other threads:[~2020-12-09 20:57 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-12-09 15:14 bug#45134: Add project-switch-project-by-name Rudolf Schlatte
2020-12-09 15:21 ` Lars Ingebrigtsen
2020-12-09 15:42   ` Rudolf Schlatte
2020-12-09 15:47     ` Rudolf Schlatte
2020-12-09 19:36 ` Dmitry Gutov
2020-12-09 20:21   ` Rudolf Schlatte
2020-12-09 20:57     ` Dmitry Gutov

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.