From bba77f4d0a20ccfcf98c3511c22e95363fd25bb9 Mon Sep 17 00:00:00 2001 From: Lin Sun Date: Sat, 28 Dec 2024 06:54:57 +0000 Subject: [PATCH 1/2] * layers/+spacemacs/spacemacs-defaults/funcs.el: Enhance copying file path for dired-mode --- layers/+spacemacs/spacemacs-defaults/funcs.el | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/layers/+spacemacs/spacemacs-defaults/funcs.el b/layers/+spacemacs/spacemacs-defaults/funcs.el index 4e1686a723d3..5ad127029c93 100644 --- a/layers/+spacemacs/spacemacs-defaults/funcs.el +++ b/layers/+spacemacs/spacemacs-defaults/funcs.el @@ -861,9 +861,15 @@ ones created by `magit' and `dired'." (user-error "Current buffer is not visiting a file or directory"))) (defun spacemacs/copy-file-path () - "Copy and show the file path of the current buffer." + "Copy and show the file path of the current buffer. If the buffer is a +dired buffer, the result will be the file path under cursor, otherwise +the result is directory path." (interactive) - (if-let* ((file-path (spacemacs--file-path))) + (if-let* ((file-path (or (spacemacs--file-path) + (and (derived-mode-p 'dired-mode) + (condition-case nil + (dired-get-file-for-visit) + (error default-directory)))))) (progn (kill-new file-path) (message "%s" file-path)) From 557f37d2ae6de7f0bc255ba6fafdea49681e7e10 Mon Sep 17 00:00:00 2001 From: "Aaron L. Zeng" Date: Tue, 31 Dec 2024 19:10:13 -0500 Subject: [PATCH 2/2] [defaults] Avoid unnecessary exception raising, also ensure truename --- layers/+spacemacs/spacemacs-defaults/funcs.el | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/layers/+spacemacs/spacemacs-defaults/funcs.el b/layers/+spacemacs/spacemacs-defaults/funcs.el index 5ad127029c93..f697a4e5acc1 100644 --- a/layers/+spacemacs/spacemacs-defaults/funcs.el +++ b/layers/+spacemacs/spacemacs-defaults/funcs.el @@ -861,15 +861,15 @@ ones created by `magit' and `dired'." (user-error "Current buffer is not visiting a file or directory"))) (defun spacemacs/copy-file-path () - "Copy and show the file path of the current buffer. If the buffer is a -dired buffer, the result will be the file path under cursor, otherwise -the result is directory path." + "Copy and show the file path of the current buffer. + +In Dired, the result will be the file path under cursor if any, +otherwise the listed directory's path." (interactive) (if-let* ((file-path (or (spacemacs--file-path) (and (derived-mode-p 'dired-mode) - (condition-case nil - (dired-get-file-for-visit) - (error default-directory)))))) + (dired-get-filename nil t)) + (spacemacs--directory-path)))) (progn (kill-new file-path) (message "%s" file-path))