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

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