aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorLars Ingebrigtsen2022-07-15 12:36:33 +0200
committerLars Ingebrigtsen2022-07-15 12:36:33 +0200
commit23bba37a78cfdbab0634846b962f474d987b6036 (patch)
tree5b99fb0bbe532976f3ddd4b0f3d25b6ed8751200 /lisp
parent6befaa02caee377acd11e7adf183a34c98afc819 (diff)
downloademacs-23bba37a78cfdbab0634846b962f474d987b6036.tar.gz
emacs-23bba37a78cfdbab0634846b962f474d987b6036.zip
Tweak how dired-copy-filename-as-kill handles file names with spaces
* lisp/dired.el (dired-copy-filename-as-kill): Quote files containing spaces (bug#48657).
Diffstat (limited to 'lisp')
-rw-r--r--lisp/dired.el39
1 files changed, 25 insertions, 14 deletions
diff --git a/lisp/dired.el b/lisp/dired.el
index 43563d969f1..59346a19014 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -3072,7 +3072,11 @@ If EOL, it should be an position to use instead of
3072 3072
3073(defun dired-copy-filename-as-kill (&optional arg) 3073(defun dired-copy-filename-as-kill (&optional arg)
3074 "Copy names of marked (or next ARG) files into the kill ring. 3074 "Copy names of marked (or next ARG) files into the kill ring.
3075The names are separated by a space. 3075If there are several names, they will be separated by a space,
3076and file names that have spaces or quote characters in them will
3077be quoted (with double quotes). (When there's a single file, no
3078quoting is done.)
3079
3076With a zero prefix arg, use the absolute file name of each marked file. 3080With a zero prefix arg, use the absolute file name of each marked file.
3077With \\[universal-argument], use the file name relative to the Dired buffer's 3081With \\[universal-argument], use the file name relative to the Dired buffer's
3078`default-directory'. (This still may contain slashes if in a subdirectory.) 3082`default-directory'. (This still may contain slashes if in a subdirectory.)
@@ -3082,19 +3086,26 @@ prefix arg and marked files are ignored in this case.
3082 3086
3083You can then feed the file name(s) to other commands with \\[yank]." 3087You can then feed the file name(s) to other commands with \\[yank]."
3084 (interactive "P") 3088 (interactive "P")
3085 (let ((string 3089 (let* ((files
3086 (or (dired-get-subdir) 3090 (or (ensure-list (dired-get-subdir))
3087 (mapconcat #'identity 3091 (if arg
3088 (if arg 3092 (cond ((zerop (prefix-numeric-value arg))
3089 (cond ((zerop (prefix-numeric-value arg)) 3093 (dired-get-marked-files))
3090 (dired-get-marked-files)) 3094 ((consp arg)
3091 ((consp arg) 3095 (dired-get-marked-files t))
3092 (dired-get-marked-files t)) 3096 (t
3093 (t 3097 (dired-get-marked-files
3094 (dired-get-marked-files 3098 'no-dir (prefix-numeric-value arg))))
3095 'no-dir (prefix-numeric-value arg)))) 3099 (dired-get-marked-files 'no-dir))))
3096 (dired-get-marked-files 'no-dir)) 3100 (string
3097 " ")))) 3101 (if (length= files 1)
3102 (car files)
3103 (mapconcat (lambda (file)
3104 (if (string-match-p "[ \"']" file)
3105 (format "%S" file)
3106 file))
3107 files
3108 " "))))
3098 (unless (string= string "") 3109 (unless (string= string "")
3099 (if (eq last-command 'kill-region) 3110 (if (eq last-command 'kill-region)
3100 (kill-append string nil) 3111 (kill-append string nil)