unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#64531: [PATCH] Add new command vc-dir-copy-filename-as-kill
@ 2023-07-08  7:51 Ivan Sokolov
  2023-07-08  9:25 ` Eli Zaretskii
  2023-09-04 20:08 ` bug#64531: [PATCH v3] Add new commands for copying VC filenames Ivan Sokolov
  0 siblings, 2 replies; 13+ messages in thread
From: Ivan Sokolov @ 2023-07-08  7:51 UTC (permalink / raw)
  To: 64531

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

Hi!

This new command is inspired by `dired-copy-filename-as-kill', but has a
few differences, that can be easily reversed if there is such need.

Changes:
1. even single filename is quoted;
2. filenames are relative by default, prefix makes them absolute;
3. value of prefix argument does not matter, in dired it has to be 0.

I bound it to the `w' key because `w' is currently unbound in
vc-dir-mode-map and it is what is used in dired.



[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: [PATCH] Add new command vc-dir-copy-filename-as-kill --]
[-- Type: text/x-patch, Size: 1744 bytes --]

From d2edc8052d3f8a34b4f28f6721cb2b2ceca1d4a5 Mon Sep 17 00:00:00 2001
From: Ivan Sokolov <ivan-p-sokolov@ya.ru>
Date: Sat, 8 Jul 2023 10:34:18 +0300
Subject: [PATCH] Add new command vc-dir-copy-filename-as-kill

---
 lisp/vc/vc-dir.el | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/lisp/vc/vc-dir.el b/lisp/vc/vc-dir.el
index 53d58870b32..e348f1027ab 100644
--- a/lisp/vc/vc-dir.el
+++ b/lisp/vc/vc-dir.el
@@ -353,6 +353,7 @@ See `run-hooks'."
     (define-key map (kbd "M-s a C-s")   #'vc-dir-isearch)
     (define-key map (kbd "M-s a M-C-s") #'vc-dir-isearch-regexp)
     (define-key map "G" #'vc-dir-ignore)
+    (define-key map "w" #'vc-dir-copy-filename-as-kill)
 
     (let ((branch-map (make-sparse-keymap)))
       (define-key map "b" branch-map)
@@ -930,6 +931,24 @@ system."
   (interactive)
   (view-file (vc-dir-current-file)))
 
+(defun vc-dir-copy-filename-as-kill (&optional absolutep)
+  "Copy names of marked files (or file under cursor) into the kill ring.
+If there are severals names, they will be separated by a space.
+Names are always quoted using `shell-quote-argument'.
+
+If ABSOLUTEP use the absolute names, otherwise names are relative
+to the `default-directory'."
+  (interactive "P")
+  (let ((files (or (vc-dir-marked-files)
+                   (list (vc-dir-current-file)))))
+    (unless absolutep
+      (setq files (mapcar #'file-relative-name files)))
+    (let ((string (mapconcat #'shell-quote-argument files " ")))
+      (if (eq last-command 'kill-region)
+          (kill-append string nil)
+        (kill-new string))
+      (message "%s" string))))
+
 (defun vc-dir-isearch ()
   "Search for a string through all marked buffers using Isearch."
   (interactive)
-- 
2.40.1


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

* bug#64531: [PATCH] Add new command vc-dir-copy-filename-as-kill
  2023-07-08  7:51 bug#64531: [PATCH] Add new command vc-dir-copy-filename-as-kill Ivan Sokolov
@ 2023-07-08  9:25 ` Eli Zaretskii
  2023-08-08 13:44   ` bug#64531: [PATCH v2] " Ivan Sokolov
  2023-09-04 20:08 ` bug#64531: [PATCH v3] Add new commands for copying VC filenames Ivan Sokolov
  1 sibling, 1 reply; 13+ messages in thread
From: Eli Zaretskii @ 2023-07-08  9:25 UTC (permalink / raw)
  To: Ivan Sokolov; +Cc: 64531

> From: Ivan Sokolov <ivan-p-sokolov@ya.ru>
> Date: Sat, 08 Jul 2023 10:51:53 +0300
> 
> This new command is inspired by `dired-copy-filename-as-kill', but has a
> few differences, that can be easily reversed if there is such need.
> 
> Changes:
> 1. even single filename is quoted;
> 2. filenames are relative by default, prefix makes them absolute;
> 3. value of prefix argument does not matter, in dired it has to be 0.
> 
> I bound it to the `w' key because `w' is currently unbound in
> vc-dir-mode-map and it is what is used in dired.

Thanks.  However, new commands should be called out in NEWS, and
commands that are important enough should also be mentioned in the
user manual.

> +(defun vc-dir-copy-filename-as-kill (&optional absolutep)
> +  "Copy names of marked files (or file under cursor) into the kill ring.

This sentence is too general: it doesn't mention VC Dir, although
AFAIU it is specific to vc-dir.





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

* bug#64531: [PATCH v2] Add new command vc-dir-copy-filename-as-kill
  2023-07-08  9:25 ` Eli Zaretskii
@ 2023-08-08 13:44   ` Ivan Sokolov
  2023-08-08 13:56     ` Eli Zaretskii
  2023-08-19  8:06     ` Eli Zaretskii
  0 siblings, 2 replies; 13+ messages in thread
From: Ivan Sokolov @ 2023-08-08 13:44 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 64531

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

Eli Zaretskii <eliz@gnu.org> writes:

> However, new commands should be called out in NEWS, and commands that
> are important enough should also be mentioned in the user manual.

Added entry in NEWS, but not in the user manual, there is no such for
vc-dir afaik.

>> +(defun vc-dir-copy-filename-as-kill (&optional absolutep)
>> +  "Copy names of marked files (or file under cursor) into the kill ring.
>
> This sentence is too general: it doesn't mention VC Dir, although
> AFAIU it is specific to vc-dir.

Fixed.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: v2-0001-Add-new-command-vc-dir-copy-filename-as-kill.patch --]
[-- Type: text/x-patch, Size: 2386 bytes --]

From 88cb2e3407adf0245bc15a88896e1cd611d559c8 Mon Sep 17 00:00:00 2001
From: Ivan Sokolov <ivan-p-sokolov@ya.ru>
Date: Tue, 11 Jul 2023 18:19:57 +0300
Subject: [PATCH v2] Add new command vc-dir-copy-filename-as-kill

* lisp/vc/vc-dir.el (vc-dir-copy-filename-as-kill): New command.

(vc-dir-mode-map): Bind vc-dir-copy-filename-as-kill to `w'.
---
 etc/NEWS          |  3 +++
 lisp/vc/vc-dir.el | 18 ++++++++++++++++++
 2 files changed, 21 insertions(+)

diff --git a/etc/NEWS b/etc/NEWS
index 1a86c9e55e2..da3672e068b 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -154,6 +154,9 @@ This is a string or a list of strings that specifies the Git log
 switches for shortlogs, such as the one produced by 'C-x v L'.
 'vc-git-log-switches' is no longer used for shortlogs.
 
+*** New command 'vc-dir-copy-filename-as-kill'.
+This works like 'dired-copy-filename-as-kill' but in vc-dir buffers.
+
 ** Diff Mode
 
 +++
diff --git a/lisp/vc/vc-dir.el b/lisp/vc/vc-dir.el
index 53d58870b32..dc25467a3e9 100644
--- a/lisp/vc/vc-dir.el
+++ b/lisp/vc/vc-dir.el
@@ -353,6 +353,7 @@ See `run-hooks'."
     (define-key map (kbd "M-s a C-s")   #'vc-dir-isearch)
     (define-key map (kbd "M-s a M-C-s") #'vc-dir-isearch-regexp)
     (define-key map "G" #'vc-dir-ignore)
+    (define-key map "w" #'vc-dir-copy-filename-as-kill)
 
     (let ((branch-map (make-sparse-keymap)))
       (define-key map "b" branch-map)
@@ -930,6 +931,23 @@ system."
   (interactive)
   (view-file (vc-dir-current-file)))
 
+(defun vc-dir-copy-filename-as-kill (&optional absolutep)
+  "Copy filenames from the `vc-dir' buffer into the kill ring.
+If there are marked files, copy their names, otherwise copy the
+file at point.  Names will be separated by a space, each will be
+quoted using `shell-quote-argument'.  If ABSOLUTEP use absolute
+names, otherwise names are relative to the `default-directory'."
+  (interactive "P")
+  (let ((files (or (vc-dir-marked-files)
+                   (list (vc-dir-current-file)))))
+    (unless absolutep
+      (setq files (mapcar #'file-relative-name files)))
+    (let ((string (mapconcat #'shell-quote-argument files " ")))
+      (if (eq last-command 'kill-region)
+          (kill-append string nil)
+        (kill-new string))
+      (message "%s" string))))
+
 (defun vc-dir-isearch ()
   "Search for a string through all marked buffers using Isearch."
   (interactive)
-- 
2.41.0


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

* bug#64531: [PATCH v2] Add new command vc-dir-copy-filename-as-kill
  2023-08-08 13:44   ` bug#64531: [PATCH v2] " Ivan Sokolov
@ 2023-08-08 13:56     ` Eli Zaretskii
  2023-08-19  8:06     ` Eli Zaretskii
  1 sibling, 0 replies; 13+ messages in thread
From: Eli Zaretskii @ 2023-08-08 13:56 UTC (permalink / raw)
  To: Ivan Sokolov; +Cc: 64531

> From: Ivan Sokolov <ivan-p-sokolov@ya.ru>
> Cc: 64531@debbugs.gnu.org
> Date: Tue, 08 Aug 2023 16:44:56 +0300
> 
> Eli Zaretskii <eliz@gnu.org> writes:
> 
> > However, new commands should be called out in NEWS, and commands that
> > are important enough should also be mentioned in the user manual.
> 
> Added entry in NEWS, but not in the user manual, there is no such for
> vc-dir afaik.

vc-dir is described in the subsection "VC Directory Mode" and its
sub-subsections.

> +(defun vc-dir-copy-filename-as-kill (&optional absolutep)
> +  "Copy filenames from the `vc-dir' buffer into the kill ring.
> +If there are marked files, copy their names, otherwise copy the
> +file at point.  Names will be separated by a space, each will be
> +quoted using `shell-quote-argument'.  If ABSOLUTEP use absolute
                                                     ^
A comma is missing there.





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

* bug#64531: [PATCH v2] Add new command vc-dir-copy-filename-as-kill
  2023-08-08 13:44   ` bug#64531: [PATCH v2] " Ivan Sokolov
  2023-08-08 13:56     ` Eli Zaretskii
@ 2023-08-19  8:06     ` Eli Zaretskii
  2023-08-19 23:12       ` Ivan Sokolov
  2023-08-19 23:33       ` Dmitry Gutov
  1 sibling, 2 replies; 13+ messages in thread
From: Eli Zaretskii @ 2023-08-19  8:06 UTC (permalink / raw)
  To: Ivan Sokolov, Dmitry Gutov; +Cc: 64531

> From: Ivan Sokolov <ivan-p-sokolov@ya.ru>
> Cc: 64531@debbugs.gnu.org
> Date: Tue, 08 Aug 2023 16:44:56 +0300
> 
> Eli Zaretskii <eliz@gnu.org> writes:
> 
> > However, new commands should be called out in NEWS, and commands that
> > are important enough should also be mentioned in the user manual.
> 
> Added entry in NEWS, but not in the user manual, there is no such for
> vc-dir afaik.
> 
> >> +(defun vc-dir-copy-filename-as-kill (&optional absolutep)
> >> +  "Copy names of marked files (or file under cursor) into the kill ring.
> >
> > This sentence is too general: it doesn't mention VC Dir, although
> > AFAIU it is specific to vc-dir.
> 
> Fixed.

Dmitry, is this good to go in?

I still think it should be mention in the Emacs user manual, where we
document vc-dir.





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

* bug#64531: [PATCH v2] Add new command vc-dir-copy-filename-as-kill
  2023-08-19  8:06     ` Eli Zaretskii
@ 2023-08-19 23:12       ` Ivan Sokolov
  2023-08-20  6:20         ` Eli Zaretskii
  2023-08-19 23:33       ` Dmitry Gutov
  1 sibling, 1 reply; 13+ messages in thread
From: Ivan Sokolov @ 2023-08-19 23:12 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 64531, Dmitry Gutov

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Ivan Sokolov <ivan-p-sokolov@ya.ru>
>> Cc: 64531@debbugs.gnu.org
>> Date: Tue, 08 Aug 2023 16:44:56 +0300
>> 
>> Eli Zaretskii <eliz@gnu.org> writes:
>> 
>> > However, new commands should be called out in NEWS, and commands that
>> > are important enough should also be mentioned in the user manual.
>> 
>> Added entry in NEWS, but not in the user manual, there is no such for
>> vc-dir afaik.
>> 
>> >> +(defun vc-dir-copy-filename-as-kill (&optional absolutep)
>> >> +  "Copy names of marked files (or file under cursor) into the kill ring.
>> >
>> > This sentence is too general: it doesn't mention VC Dir, although
>> > AFAIU it is specific to vc-dir.
>> 
>> Fixed.
>
> Dmitry, is this good to go in?
>
> I still think it should be mention in the Emacs user manual, where we
> document vc-dir.

Hi, Eli!

I am working on the 3rd version of the patch with all the necessary
documentation and changes to the command which I will explain in the
cover letter.  Not sure when I'll finish it though.





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

* bug#64531: [PATCH v2] Add new command vc-dir-copy-filename-as-kill
  2023-08-19  8:06     ` Eli Zaretskii
  2023-08-19 23:12       ` Ivan Sokolov
@ 2023-08-19 23:33       ` Dmitry Gutov
  2023-08-20  6:26         ` Eli Zaretskii
  1 sibling, 1 reply; 13+ messages in thread
From: Dmitry Gutov @ 2023-08-19 23:33 UTC (permalink / raw)
  To: Eli Zaretskii, Ivan Sokolov; +Cc: 64531

Hi Eli,

On 19/08/2023 11:06, Eli Zaretskii wrote:
> Dmitry, is this good to go in?

I'm good with the binding and the general functionality.

The difference from dired-copy-filename-as-kill in handing of the prefix 
argument looks unfortunate (as a principle), but I'd rather leave it for 
you to judge. Perhaps changing the latter command's interface would be a 
better choice; I'm not sure why it works that way.

Implementation difference: instead of going through (format "%S"), this 
one uses shell-quote-argument. Is that good enough for Windows systems?

And one more difference which we might want to see fixed:

   (When there's a single file, no quoting is done.)

It seems like, at least, in some usage scenarios users would prefer to 
have copied filename not quoted. E.g. for subsequent use with find-file 
or... something similar. I don't really use this command all that much, 
so maybe I'm mistaken here, though.





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

* bug#64531: [PATCH v2] Add new command vc-dir-copy-filename-as-kill
  2023-08-19 23:12       ` Ivan Sokolov
@ 2023-08-20  6:20         ` Eli Zaretskii
  0 siblings, 0 replies; 13+ messages in thread
From: Eli Zaretskii @ 2023-08-20  6:20 UTC (permalink / raw)
  To: Ivan Sokolov; +Cc: 64531, dgutov

> From: Ivan Sokolov <ivan-p-sokolov@ya.ru>
> Cc: Dmitry Gutov <dgutov@yandex.ru>,  64531@debbugs.gnu.org
> Date: Sun, 20 Aug 2023 02:12:32 +0300
> 
> Eli Zaretskii <eliz@gnu.org> writes:
> 
> >> From: Ivan Sokolov <ivan-p-sokolov@ya.ru>
> >> Cc: 64531@debbugs.gnu.org
> >> Date: Tue, 08 Aug 2023 16:44:56 +0300
> >> 
> >> Eli Zaretskii <eliz@gnu.org> writes:
> >> 
> >> > However, new commands should be called out in NEWS, and commands that
> >> > are important enough should also be mentioned in the user manual.
> >> 
> >> Added entry in NEWS, but not in the user manual, there is no such for
> >> vc-dir afaik.
> >> 
> >> >> +(defun vc-dir-copy-filename-as-kill (&optional absolutep)
> >> >> +  "Copy names of marked files (or file under cursor) into the kill ring.
> >> >
> >> > This sentence is too general: it doesn't mention VC Dir, although
> >> > AFAIU it is specific to vc-dir.
> >> 
> >> Fixed.
> >
> > Dmitry, is this good to go in?
> >
> > I still think it should be mention in the Emacs user manual, where we
> > document vc-dir.
> 
> Hi, Eli!
> 
> I am working on the 3rd version of the patch with all the necessary
> documentation and changes to the command which I will explain in the
> cover letter.  Not sure when I'll finish it though.

Good to hear, and TIA.

There's no rush, so take your time.  (I will ping again if it takes
too long IMO ;-)





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

* bug#64531: [PATCH v2] Add new command vc-dir-copy-filename-as-kill
  2023-08-19 23:33       ` Dmitry Gutov
@ 2023-08-20  6:26         ` Eli Zaretskii
  2023-08-20 10:26           ` Dmitry Gutov
  0 siblings, 1 reply; 13+ messages in thread
From: Eli Zaretskii @ 2023-08-20  6:26 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: 64531, ivan-p-sokolov

> Date: Sun, 20 Aug 2023 02:33:59 +0300
> Cc: 64531@debbugs.gnu.org
> From: Dmitry Gutov <dgutov@yandex.ru>
> 
> The difference from dired-copy-filename-as-kill in handing of the prefix 
> argument looks unfortunate (as a principle), but I'd rather leave it for 
> you to judge. Perhaps changing the latter command's interface would be a 
> better choice; I'm not sure why it works that way.

What difference is that?  I must be missing something, since it sounds
like both commands use the argument to select absolute or relative
file names?

> Implementation difference: instead of going through (format "%S"), this 
> one uses shell-quote-argument. Is that good enough for Windows systems?

It depends on how the result will be used.  But maybe we should do the
same as dired-copy-filename-as-kill, just for consistency of the UX?

> And one more difference which we might want to see fixed:
> 
>    (When there's a single file, no quoting is done.)
> 
> It seems like, at least, in some usage scenarios users would prefer to 
> have copied filename not quoted. E.g. for subsequent use with find-file 
> or... something similar. I don't really use this command all that much, 
> so maybe I'm mistaken here, though.

There will always be cases when quoting gets in the way, but hopefully
they are rare.  The important thing, IMO, is that quoting is useful
for many/most uses of the file names in VC commands.  Is it?





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

* bug#64531: [PATCH v2] Add new command vc-dir-copy-filename-as-kill
  2023-08-20  6:26         ` Eli Zaretskii
@ 2023-08-20 10:26           ` Dmitry Gutov
  0 siblings, 0 replies; 13+ messages in thread
From: Dmitry Gutov @ 2023-08-20 10:26 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: ivan-p-sokolov, 64531

On 20/08/2023 09:26, Eli Zaretskii wrote:
>> Date: Sun, 20 Aug 2023 02:33:59 +0300
>> Cc: 64531@debbugs.gnu.org
>> From: Dmitry Gutov <dgutov@yandex.ru>
>>
>> The difference from dired-copy-filename-as-kill in handing of the prefix
>> argument looks unfortunate (as a principle), but I'd rather leave it for
>> you to judge. Perhaps changing the latter command's interface would be a
>> better choice; I'm not sure why it works that way.
> 
> What difference is that?  I must be missing something, since it sounds
> like both commands use the argument to select absolute or relative
> file names?

One of them mandates M-0 for that effect.

>> Implementation difference: instead of going through (format "%S"), this
>> one uses shell-quote-argument. Is that good enough for Windows systems?
> 
> It depends on how the result will be used.  But maybe we should do the
> same as dired-copy-filename-as-kill, just for consistency of the UX?

Maybe.

I imagine it might be used in a shell, but indeed there are different 
options.

>> And one more difference which we might want to see fixed:
>>
>>     (When there's a single file, no quoting is done.)
>>
>> It seems like, at least, in some usage scenarios users would prefer to
>> have copied filename not quoted. E.g. for subsequent use with find-file
>> or... something similar. I don't really use this command all that much,
>> so maybe I'm mistaken here, though.
> 
> There will always be cases when quoting gets in the way, but hopefully
> they are rare.  The important thing, IMO, is that quoting is useful
> for many/most uses of the file names in VC commands.  Is it?

When using 'M-!'? Maybe. I think consistency between 'w' commands is 
somewhat important, though.





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

* bug#64531: [PATCH v3] Add new commands for copying VC filenames
  2023-07-08  7:51 bug#64531: [PATCH] Add new command vc-dir-copy-filename-as-kill Ivan Sokolov
  2023-07-08  9:25 ` Eli Zaretskii
@ 2023-09-04 20:08 ` Ivan Sokolov
  2023-09-05 11:01   ` Eli Zaretskii
  1 sibling, 1 reply; 13+ messages in thread
From: Ivan Sokolov @ 2023-09-04 20:08 UTC (permalink / raw)
  To: 64531; +Cc: Eli Zaretskii, Dmitry Gutov

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

Hi, Eli and Dmitry!

I tried to write documentation for the previous version of the command
and came to the conclusion that I crammed too much functionality into
it.  So I divided the DWIM command into command for copying name at
point (bound to w) and command for copying marked files (bound to * w).

I also added new command for copying VC related filenames from
everywhere.  An appropriate binding would be C-x v w, but I am not sure
if I should use a top-level binding for such an insignificant command.

Quoting and prefix arguments now copy `dired-copy-filename-as-kill'.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: [PATCH] Add new commands for copying VC filenames --]
[-- Type: text/x-patch, Size: 7558 bytes --]

From 0baa37ff90fb58e43240586a401a6145da78b3f5 Mon Sep 17 00:00:00 2001
From: Ivan Sokolov <ivan-p-sokolov@ya.ru>
Date: Mon, 4 Sep 2023 22:33:32 +0300
Subject: [PATCH] Add new commands for copying VC filenames

---
 doc/emacs/maintaining.texi | 13 ++++++++++++
 etc/NEWS                   |  7 +++++++
 lisp/vc/vc-dir.el          | 20 +++++++++++++++++-
 lisp/vc/vc.el              | 43 +++++++++++++++++++++++++++++++-------
 4 files changed, 75 insertions(+), 8 deletions(-)

diff --git a/doc/emacs/maintaining.texi b/doc/emacs/maintaining.texi
index 2dad70d3d13..8e7e2365f0a 100644
--- a/doc/emacs/maintaining.texi
+++ b/doc/emacs/maintaining.texi
@@ -1388,6 +1388,13 @@ You can use this command to mark files that are in one of registered
 states, including edited, added or removed.
 (@code{vc-dir-mark-registered-files}).
 
+@findex vc-dir-copy-marked-files-as-kill
+@item * w
+This command copy names of marked files into the kill ring.  If prefix
+argument is 0 names are absolute, with other prefix arguments names
+are relative to the VC root directory.  Without prefix names are
+relative to the VC buffer directory.
+
 @item G
 Add the file under point to the list of files that the VC should
 ignore (@code{vc-dir-ignore}).  For instance, if the VC is Git, it
@@ -1407,6 +1414,12 @@ point is on a directory entry, unmark all files in that directory tree
 (@code{vc-dir-unmark-all-files}).  With a prefix argument, unmark all
 files and directories.
 
+@item w
+Copy the name of the file at point into the kill ring.  If prefix
+argument is 0 name is absolute, with other prefix arguments name is
+relative to the VC root directory.  Without prefix name is relative to
+the VC buffer directory.
+
 @item x
 Hide files with @samp{up-to-date} or @samp{ignored} status
 (@code{vc-dir-hide-up-to-date}).  With a prefix argument, hide items
diff --git a/etc/NEWS b/etc/NEWS
index c97df11042d..77192b23cb7 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -262,6 +262,13 @@ This is a string or a list of strings that specifies the Git log
 switches for shortlogs, such as the one produced by 'C-x v L'.
 'vc-git-log-switches' is no longer used for shortlogs.
 
+*** New commands for copying names of Version Controlled files
+Commands 'vc-dir-copy-filename-as-kill' and
+'vc-dir-copy-marked-files-as-kill' work like
+'dired-copy-filename-as-kill' but in VC-dir buffer.  Command
+'vc-copy-filename-as-kill' copies name of the interactively chosen
+file.
+
 ** Diff Mode
 
 +++
diff --git a/lisp/vc/vc-dir.el b/lisp/vc/vc-dir.el
index 53d58870b32..3a4b8dbd18d 100644
--- a/lisp/vc/vc-dir.el
+++ b/lisp/vc/vc-dir.el
@@ -353,6 +353,7 @@ See `run-hooks'."
     (define-key map (kbd "M-s a C-s")   #'vc-dir-isearch)
     (define-key map (kbd "M-s a M-C-s") #'vc-dir-isearch-regexp)
     (define-key map "G" #'vc-dir-ignore)
+    (define-key map "w" #'vc-dir-copy-filename-as-kill)
 
     (let ((branch-map (make-sparse-keymap)))
       (define-key map "b" branch-map)
@@ -367,7 +368,8 @@ See `run-hooks'."
     (let ((mark-map (make-sparse-keymap)))
       (define-key map "*" mark-map)
       (define-key mark-map "%" #'vc-dir-mark-by-regexp)
-      (define-key mark-map "r" #'vc-dir-mark-registered-files))
+      (define-key mark-map "r" #'vc-dir-mark-registered-files)
+      (define-key mark-map "w" #'vc-dir-copy-marked-files-as-kill))
 
     ;; Hook up the menu.
     (define-key map [menu-bar vc-dir-mode]
@@ -930,6 +932,22 @@ system."
   (interactive)
   (view-file (vc-dir-current-file)))
 
+(defun vc-dir-copy-filename-as-kill ()
+  "In VC-dir buffer copy name of the file at point into the kill ring.
+With a zero prefix arg, use the absolute file name.
+With \\[universal-argument], use the file name relative to `vc-root-dir'."
+  (interactive)
+  (vc--copy-filenames-as-kill (list (vc-dir-current-file))))
+
+(defun vc-dir-copy-marked-files-as-kill ()
+  "In VC-dir buffer copy names of the marked files into the kill ring.
+With a zero prefix arg, use the absolute file names.
+With \\[universal-argument], use the file names relative to `vc-root-dir'."
+  (interactive)
+  (if-let* ((files (vc-dir-marked-files)))
+      (vc--copy-filenames-as-kill files t)
+    (message "No marked files")))
+
 (defun vc-dir-isearch ()
   "Search for a string through all marked buffers using Isearch."
   (interactive)
diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el
index be7fa46c28e..9e352cfc467 100644
--- a/lisp/vc/vc.el
+++ b/lisp/vc/vc.el
@@ -1205,6 +1205,13 @@ BEWARE: this function may change the current buffer."
      (completing-read prompt (mapcar #'symbol-name backends)
                       nil 'require-match nil nil default))))
 
+(defun vc-read-file (prompt)
+  "Read file name, prompting with PROMPT.
+Default is the current file if it is under version control."
+  (read-file-name prompt nil (when (vc-backend buffer-file-name)
+                               buffer-file-name)
+                  t))
+
 ;; Here's the major entry point.
 
 ;;;###autoload
@@ -3261,10 +3268,7 @@ backend to NEW-BACKEND, and unregister FILE from the current backend.
   "Delete file and mark it as such in the version control system.
 If called interactively, read FILE, defaulting to the current
 buffer's file name if it's under version control."
-  (interactive (list (read-file-name "VC delete file: " nil
-                                     (when (vc-backend buffer-file-name)
-                                       buffer-file-name)
-                                     t)))
+  (interactive (list (vc-read-file "VC delete file: ")))
   (setq file (expand-file-name file))
   (let ((buf (get-file-buffer file))
         (backend (vc-backend file)))
@@ -3305,9 +3309,7 @@ buffer's file name if it's under version control."
   "Rename file OLD to NEW in both work area and repository.
 If called interactively, read OLD and NEW, defaulting OLD to the
 current buffer's file name if it's under version control."
-  (interactive (list (read-file-name "VC rename file: " nil
-                                     (when (vc-backend buffer-file-name)
-                                       buffer-file-name) t)
+  (interactive (list (vc-read-file "VC rename file: ")
                      (read-file-name "Rename to: ")))
   ;; in CL I would have said (setq new (merge-pathnames new old))
   (let ((old-base (file-name-nondirectory old)))
@@ -3340,6 +3342,33 @@ current buffer's file name if it's under version control."
 	(vc-mode-line new (vc-backend new))
 	(set-buffer-modified-p nil)))))
 
+(defun vc--copy-as-kill (str)
+  (if (eq last-command 'kill-region)
+      (kill-append str nil)
+    (kill-new str))
+  (message "%s" str))
+
+(defun vc--copy-filenames-as-kill (files &optional quote)
+  (vc--copy-as-kill
+   (mapconcat
+    (lambda (file)
+      (cond ((eq current-prefix-arg 0)
+             (setq file (expand-file-name file)))
+            ((consp current-prefix-arg)
+             (setq file (file-relative-name file (vc-root-dir)))))
+      (if (and quote (string-match-p "[\s\"']" file))
+          (format "%S" file)
+        file))
+    files " ")))
+
+;;;###autoload
+(defun vc-copy-filename-as-kill (file)
+  "Copy name of the FILE into the kill ring.
+With a zero prefix arg, use the absolute file name.
+With \\[universal-argument], use the file name relative to `vc-root-dir'."
+  (interactive (list (vc-read-file "VC copy filename as kill: ")))
+  (vc--copy-filenames-as-kill (list file)))
+
 ;;;###autoload
 (defun vc-update-change-log (&rest args)
   "Find change log file and add entries from recent version control logs.
-- 
2.41.0


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

* bug#64531: [PATCH v3] Add new commands for copying VC filenames
  2023-09-04 20:08 ` bug#64531: [PATCH v3] Add new commands for copying VC filenames Ivan Sokolov
@ 2023-09-05 11:01   ` Eli Zaretskii
  2023-10-19 23:39     ` Dmitry Gutov
  0 siblings, 1 reply; 13+ messages in thread
From: Eli Zaretskii @ 2023-09-05 11:01 UTC (permalink / raw)
  To: Ivan Sokolov; +Cc: 64531, dgutov

> From: Ivan Sokolov <ivan-p-sokolov@ya.ru>
> Cc: Eli Zaretskii <eliz@gnu.org>, Dmitry Gutov <dgutov@yandex.ru>
> Date: Mon, 04 Sep 2023 23:08:02 +0300
> 
> I tried to write documentation for the previous version of the command
> and came to the conclusion that I crammed too much functionality into
> it.  So I divided the DWIM command into command for copying name at
> point (bound to w) and command for copying marked files (bound to * w).
> 
> I also added new command for copying VC related filenames from
> everywhere.  An appropriate binding would be C-x v w, but I am not sure
> if I should use a top-level binding for such an insignificant command.
> 
> Quoting and prefix arguments now copy `dired-copy-filename-as-kill'.

Thanks, a few minor comments about the documentation parts:

> diff --git a/doc/emacs/maintaining.texi b/doc/emacs/maintaining.texi
> index 2dad70d3d13..8e7e2365f0a 100644
> --- a/doc/emacs/maintaining.texi
> +++ b/doc/emacs/maintaining.texi
> @@ -1388,6 +1388,13 @@ You can use this command to mark files that are in one of registered
>  states, including edited, added or removed.
>  (@code{vc-dir-mark-registered-files}).
>  
> +@findex vc-dir-copy-marked-files-as-kill
> +@item * w
> +This command copy names of marked files into the kill ring.  If prefix
                ^^^^
"copies"

> +argument is 0 names are absolute, with other prefix arguments names
> +are relative to the VC root directory.  Without prefix names are
> +relative to the VC buffer directory.

Our style is to describe the "normal" case first.  Like this:

  Normally, the copied file names are relative to the current buffer's
  default directory, but you can control that with the prefix
  argument.  With prefix argument of zero, the file names are copied
  in their absolute form; with any other value of prefix argument, the
  file names are relative to the root directory of the VCS repository.

> +@item w
> +Copy the name of the file at point into the kill ring.  If prefix
> +argument is 0 name is absolute, with other prefix arguments name is
> +relative to the VC root directory.  Without prefix name is relative to
> +the VC buffer directory.

This basically repeats the same text as above.  We usually first
describe the command in short, preferably in one sentence, and place
the detailed description further down.  Please try to follow these
conventions.





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

* bug#64531: [PATCH v3] Add new commands for copying VC filenames
  2023-09-05 11:01   ` Eli Zaretskii
@ 2023-10-19 23:39     ` Dmitry Gutov
  0 siblings, 0 replies; 13+ messages in thread
From: Dmitry Gutov @ 2023-10-19 23:39 UTC (permalink / raw)
  To: Eli Zaretskii, Ivan Sokolov; +Cc: 64531

On 05/09/2023 14:01, Eli Zaretskii wrote:
>> From: Ivan Sokolov<ivan-p-sokolov@ya.ru>
>> Cc: Eli Zaretskii<eliz@gnu.org>, Dmitry Gutov<dgutov@yandex.ru>
>> Date: Mon, 04 Sep 2023 23:08:02 +0300
>>
>> I tried to write documentation for the previous version of the command
>> and came to the conclusion that I crammed too much functionality into
>> it.  So I divided the DWIM command into command for copying name at
>> point (bound to w) and command for copying marked files (bound to * w).
>>
>> I also added new command for copying VC related filenames from
>> everywhere.  An appropriate binding would be C-x v w, but I am not sure
>> if I should use a top-level binding for such an insignificant command.
>>
>> Quoting and prefix arguments now copy `dired-copy-filename-as-kill'.
> Thanks, a few minor comments about the documentation parts:

Thank for the doc changes review.

The code looks good, FWIW.





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

end of thread, other threads:[~2023-10-19 23:39 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-08  7:51 bug#64531: [PATCH] Add new command vc-dir-copy-filename-as-kill Ivan Sokolov
2023-07-08  9:25 ` Eli Zaretskii
2023-08-08 13:44   ` bug#64531: [PATCH v2] " Ivan Sokolov
2023-08-08 13:56     ` Eli Zaretskii
2023-08-19  8:06     ` Eli Zaretskii
2023-08-19 23:12       ` Ivan Sokolov
2023-08-20  6:20         ` Eli Zaretskii
2023-08-19 23:33       ` Dmitry Gutov
2023-08-20  6:26         ` Eli Zaretskii
2023-08-20 10:26           ` Dmitry Gutov
2023-09-04 20:08 ` bug#64531: [PATCH v3] Add new commands for copying VC filenames Ivan Sokolov
2023-09-05 11:01   ` Eli Zaretskii
2023-10-19 23:39     ` Dmitry Gutov

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