unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Add project-name function
@ 2021-03-05 22:48 Ivan Sokolov
  2021-03-06 14:10 ` Philip Kaludercic
  0 siblings, 1 reply; 5+ messages in thread
From: Ivan Sokolov @ 2021-03-05 22:48 UTC (permalink / raw)
  To: emacs-devel

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

I hope I am doing everything right, this is my first patch for Emacs.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-lisp-progmodes-project.el-Add-project-name.patch --]
[-- Type: text/x-patch, Size: 2536 bytes --]

From 0aa1b0417f2fd4f8fdef24194c55304611711cfa Mon Sep 17 00:00:00 2001
From: Ivan Sokolov <ivan-p-sokolov@ya.ru>
Date: Sat, 6 Mar 2021 01:43:30 +0300
Subject: [PATCH] lisp/progmodes/project.el: Add 'project-name'

---
 lisp/progmodes/project.el | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index abe563bec0..3abae8606f 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -888,6 +888,13 @@ PREDICATE, HIST, and DEFAULT have the same meaning as in
   (interactive)
   (vc-dir (project-root (project-current t))))
 
+;;;###autoload
+(defun project-name (project)
+  "Return PROJECT's name."
+  (file-name-nondirectory
+   (directory-file-name
+    (project-root project))))
+
 ;;;###autoload
 (defun project-shell ()
   "Start an inferior shell in the current project's root directory.
@@ -896,12 +903,10 @@ switch to it.  Otherwise, create a new shell buffer.
 With \\[universal-argument] prefix arg, create a new inferior shell buffer even
 if one already exists."
   (interactive)
-  (let* ((default-directory (project-root (project-current t)))
+  (let* ((project (project-current t))
+         (default-directory (project-root project))
          (default-project-shell-name
-           (concat "*" (file-name-nondirectory
-                        (directory-file-name
-                         (file-name-directory default-directory)))
-                   "-shell*"))
+           (concat "*" (project-name project) "-shell*"))
          (shell-buffer (get-buffer default-project-shell-name)))
     (if (and shell-buffer (not current-prefix-arg))
         (pop-to-buffer shell-buffer)
@@ -916,12 +921,10 @@ With \\[universal-argument] prefix arg, create a new Eshell buffer even
 if one already exists."
   (interactive)
   (defvar eshell-buffer-name)
-  (let* ((default-directory (project-root (project-current t)))
+  (let* ((project (project-current t))
+         (default-directory (project-root project))
          (eshell-buffer-name
-          (concat "*" (file-name-nondirectory
-                       (directory-file-name
-                        (file-name-directory default-directory)))
-                  "-eshell*"))
+          (concat "*" (project-name project) "-eshell*"))
          (eshell-buffer (get-buffer eshell-buffer-name)))
     (if (and eshell-buffer (not current-prefix-arg))
         (pop-to-buffer eshell-buffer)

base-commit: ba33089d50a4f74b88cd7fc9d862d183d096c27d
-- 
2.30.1


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

* Re: Add project-name function
  2021-03-05 22:48 Add project-name function Ivan Sokolov
@ 2021-03-06 14:10 ` Philip Kaludercic
  2021-03-06 20:22   ` Dmitry Gutov
  0 siblings, 1 reply; 5+ messages in thread
From: Philip Kaludercic @ 2021-03-06 14:10 UTC (permalink / raw)
  To: Ivan Sokolov; +Cc: emacs-devel

Ivan Sokolov <ivan-p-sokolov@ya.ru> writes:

> I hope I am doing everything right, this is my first patch for Emacs.
>
> From 0aa1b0417f2fd4f8fdef24194c55304611711cfa Mon Sep 17 00:00:00 2001
> From: Ivan Sokolov <ivan-p-sokolov@ya.ru>
> Date: Sat, 6 Mar 2021 01:43:30 +0300
> Subject: [PATCH] lisp/progmodes/project.el: Add 'project-name'
>
> ---
>  lisp/progmodes/project.el | 23 +++++++++++++----------
>  1 file changed, 13 insertions(+), 10 deletions(-)
>
> diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
> index abe563bec0..3abae8606f 100644
> --- a/lisp/progmodes/project.el
> +++ b/lisp/progmodes/project.el
> @@ -888,6 +888,13 @@ PREDICATE, HIST, and DEFAULT have the same meaning as in
>    (interactive)
>    (vc-dir (project-root (project-current t))))
>  
> +;;;###autoload
> +(defun project-name (project)
> +  "Return PROJECT's name."

Without reading the rest of the code, I wasn't sure what a project's
name is. I think the docstring should explain that it just takes the
basename of the root directory.

It might be worth considering turning this into a method, in case a
project knows a better name.

> +  (file-name-nondirectory
> +   (directory-file-name
> +    (project-root project))))

-- 
	Philip K.



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

* Re: Add project-name function
  2021-03-06 14:10 ` Philip Kaludercic
@ 2021-03-06 20:22   ` Dmitry Gutov
  2021-03-06 20:51     ` Ivan Sokolov
  2021-03-06 20:53     ` Add " Ivan Sokolov
  0 siblings, 2 replies; 5+ messages in thread
From: Dmitry Gutov @ 2021-03-06 20:22 UTC (permalink / raw)
  To: Philip Kaludercic, Ivan Sokolov; +Cc: emacs-devel

Hi Ivan and Philip,

On 06.03.2021 16:10, Philip Kaludercic wrote:
> Ivan Sokolov<ivan-p-sokolov@ya.ru>  writes:
> 
>> I hope I am doing everything right, this is my first patch for Emacs.
>>
>>  From 0aa1b0417f2fd4f8fdef24194c55304611711cfa Mon Sep 17 00:00:00 2001
>> From: Ivan Sokolov<ivan-p-sokolov@ya.ru>
>> Date: Sat, 6 Mar 2021 01:43:30 +0300
>> Subject: [PATCH] lisp/progmodes/project.el: Add 'project-name'
>>
>> ---
>>   lisp/progmodes/project.el | 23 +++++++++++++----------
>>   1 file changed, 13 insertions(+), 10 deletions(-)
>>
>> diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
>> index abe563bec0..3abae8606f 100644
>> --- a/lisp/progmodes/project.el
>> +++ b/lisp/progmodes/project.el
>> @@ -888,6 +888,13 @@ PREDICATE, HIST, and DEFAULT have the same meaning as in
>>     (interactive)
>>     (vc-dir (project-root (project-current t))))
>>   
>> +;;;###autoload
>> +(defun project-name (project)
>> +  "Return PROJECT's name."
> Without reading the rest of the code, I wasn't sure what a project's
> name is. I think the docstring should explain that it just takes the
> basename of the root directory.
> 
> It might be worth considering turning this into a method, in case a
> project knows a better name.

The patch submission is fine (even though using the bug tracker next 
time would be preferable), and the point about the generic method is a 
good one too.

But I generally prefer to add new features to the API together with some 
accompanying usages inside the core. While the patch does that, we're 
currently discussing how to change both of the affected functions in a 
different way, and that change seems to be incompatible with the use of 
'project-name' in them.

Check this thread out: 
https://lists.gnu.org/archive/html/emacs-devel/2021-03/msg00083.html

What do you think about the behavior proposed there?



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

* Re:Add project-name function
  2021-03-06 20:22   ` Dmitry Gutov
@ 2021-03-06 20:51     ` Ivan Sokolov
  2021-03-06 20:53     ` Add " Ivan Sokolov
  1 sibling, 0 replies; 5+ messages in thread
From: Ivan Sokolov @ 2021-03-06 20:51 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: Philip Kaludercic, emacs-devel




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

* Re: Add project-name function
  2021-03-06 20:22   ` Dmitry Gutov
  2021-03-06 20:51     ` Ivan Sokolov
@ 2021-03-06 20:53     ` Ivan Sokolov
  1 sibling, 0 replies; 5+ messages in thread
From: Ivan Sokolov @ 2021-03-06 20:53 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: Philip Kaludercic, emacs-devel

I think we can continue the discussion in the aforementioned thread. And sorry for the empty message I accidentally  sent.



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

end of thread, other threads:[~2021-03-06 20:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-05 22:48 Add project-name function Ivan Sokolov
2021-03-06 14:10 ` Philip Kaludercic
2021-03-06 20:22   ` Dmitry Gutov
2021-03-06 20:51     ` Ivan Sokolov
2021-03-06 20:53     ` Add " Ivan Sokolov

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