all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Theodor Thornhill <theo@thornhill.no>
To: Juri Linkov <juri@linkov.net>
Cc: 41858@debbugs.gnu.org
Subject: bug#41858: 28.0.50; [PATCH]: Make project-shell use universal argument
Date: Mon, 15 Jun 2020 06:50:53 +0000	[thread overview]
Message-ID: <87ftaw3jqx.fsf@thornhill.no> (raw)
In-Reply-To: <874krdclk2.fsf@mail.linkov.net>

[-- Attachment #1: Type: text/plain, Size: 1969 bytes --]

Hi, and thanks for looking at the code!

"Juri Linkov" <juri@linkov.net> writes:

[...]
> Thanks, it's a nice idea to prepend the project root dir name
> to the shell buffer name.

Cool!

[...]
> So eventually I arrived to the following line for the init file:
>
>   (add-hook 'shell-mode-hook 'rename-uniquely)
>
> that just appends a number to the buffer name,
> so your patch won't affect my usage at all,
> I'll continue getting new shell buffers every time
> after 'M-x project-shell'.
>
How about we just add this behaviour instead of appending the file-path? so we get the "<n>" appended to the shell buffer names. Then you can remove that line from init :)

> Regarding the C-u argument, I don't know maybe someone might want
> to use it.  But shouldn't the C-u argument of 'project-shell' be
> more compatible with the C-u argument of 'shell' in its behaviour?

I kind of agree, though it seems like the original "project-shell" was intended to be used only interactively. I kind of view it as a specialized case of "shell", maybe as a sort of "shell-dwim" but only for a very limited case. We are always free of course to add a normal shell buffer in root, and use it non-interactively in code.

However, I can add an "&optional buffer" argument to the code and do like it's done in "shell". It just seems like it is complicating the behaviour a little bit. What do you think?

In addition, how do I then avoid duplication of code between the interactive call and the default behaviour? Specifically, I am thinking of the 'default-directory' which is not set. I guess I have to set that twice then?

> Another possible point for better consistency between them
> is to use 'pop-to-buffer' (like in 'shell') instead of
> 'switch-to-buffer-other-window'.

Agreed. Done.

I've attached another patch for you to look at, with only the easy changes, awaiting some feedback on the other parts :)

Thanks again,

Theodor


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: project-shell.patch --]
[-- Type: text/x-patch; name=project-shell.patch, Size: 1187 bytes --]

diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index f3df44fa7b..218058b195 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -686,11 +686,20 @@ project-vc-dir
 
 ;;;###autoload
 (defun project-shell ()
-  "Open Shell in the current project."
+  "Open Shell in the current project.
+With \\[universal-argument] prefix, create subsequent shell buffers
+with uniquified names."
   (interactive)
-  (let ((default-directory (project-root (project-current t))))
-    ;; Use ‘create-file-buffer’ to uniquify shell buffer names.
-    (shell (create-file-buffer "*shell*"))))
+  (let* ((default-directory (project-root (project-current t)))
+         (default-project-shell-name
+           (concat "*" (file-name-nondirectory
+                        (directory-file-name
+                         (file-name-directory default-directory)))
+                   "-shell*"))
+         (shell-buffer (get-buffer default-project-shell-name)))
+    (if (and shell-buffer (not current-prefix-arg))
+        (pop-to-buffer shell-buffer)
+      (shell (generate-new-buffer-name default-project-shell-name)))))
 
 ;;;###autoload
 (defun project-eshell ()

  reply	other threads:[~2020-06-15  6:50 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-14 18:29 bug#41858: 28.0.50; [PATCH]: Make project-shell use universal argument Theodor Thornhill
2020-06-14 18:46 ` Dmitry Gutov
2020-06-14 18:51 ` bug#41858: Add the patch as a .patch Theodor Thornhill
2020-06-14 22:46 ` bug#41858: 28.0.50; [PATCH]: Make project-shell use universal argument Juri Linkov
2020-06-15  6:50   ` Theodor Thornhill [this message]
2020-06-15 23:01     ` Juri Linkov
2020-06-18  9:57       ` Theodor Thornhill
2020-06-18 13:28         ` Eli Zaretskii
2020-06-18 18:00           ` Theodor Thornhill
2020-06-20  1:03             ` Dmitry Gutov
2020-06-15 13:05   ` Dmitry Gutov
2020-06-15 14:53     ` Theodor Thornhill

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ftaw3jqx.fsf@thornhill.no \
    --to=theo@thornhill.no \
    --cc=41858@debbugs.gnu.org \
    --cc=juri@linkov.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.