From 9f8b867af194b1cf9943dd0ac84e36b4b1d47a7b Mon Sep 17 00:00:00 2001 From: syl20bnr Date: Tue, 11 Sep 2018 14:55:00 -0400 Subject: [PATCH] Add SPC f y n and SPC f y N to copy the name of a file --- doc/DOCUMENTATION.org | 2 ++ layers/+spacemacs/spacemacs-defaults/funcs.el | 15 +++++++++++++++ .../+spacemacs/spacemacs-defaults/keybindings.el | 2 ++ 3 files changed, 19 insertions(+) diff --git a/doc/DOCUMENTATION.org b/doc/DOCUMENTATION.org index 230cbc17b..6cfc44d97 100644 --- a/doc/DOCUMENTATION.org +++ b/doc/DOCUMENTATION.org @@ -2395,6 +2395,8 @@ Files manipulation commands (start with ~f~): | ~SPC f y c~ | show and copy current file absolute path with line and column number in the minibuffer | | ~SPC f y d~ | show and copy current directory absolute path in the minibuffer | | ~SPC f y l~ | show and copy current file absolute path with line number in the minibuffer | +| ~SPC f y n~ | show and copy current file name with extensionin the minibuffer | +| ~SPC f y N~ | show and copy current file name without extensionin the minibuffer | | ~SPC f y y~ | show and copy current file absolute path in the minibuffer | **** Frame manipulation key bindings diff --git a/layers/+spacemacs/spacemacs-defaults/funcs.el b/layers/+spacemacs/spacemacs-defaults/funcs.el index 2fc7c93a2..be56037e7 100644 --- a/layers/+spacemacs/spacemacs-defaults/funcs.el +++ b/layers/+spacemacs/spacemacs-defaults/funcs.el @@ -565,6 +565,21 @@ ones created by `magit' and `dired'." (message "%s" (kill-new file-path)) (message "WARNING: Current buffer is not attached to a file!"))) +(defun spacemacs/copy-file-name () + "Copy and show the file name of the current buffer." + (interactive) + (if-let (file-name (file-name-nondirectory (spacemacs--file-path))) + (message "%s" (kill-new file-name)) + (message "WARNING: Current buffer is not attached to a file!"))) + +(defun spacemacs/copy-file-name-base () + "Copy and show the file name without its final extension of the current +buffer." + (interactive) + (if-let (file-name (file-name-base (spacemacs--file-path))) + (message "%s" (kill-new file-name)) + (message "WARNING: Current buffer is not attached to a file!"))) + (defun spacemacs/copy-file-path-with-line () "Copy and show the file path of the current buffer, including line number." (interactive) diff --git a/layers/+spacemacs/spacemacs-defaults/keybindings.el b/layers/+spacemacs/spacemacs-defaults/keybindings.el index e2d942e40..ae3997f70 100644 --- a/layers/+spacemacs/spacemacs-defaults/keybindings.el +++ b/layers/+spacemacs/spacemacs-defaults/keybindings.el @@ -228,6 +228,8 @@ "fyc" 'spacemacs/copy-file-path-with-line-column "fyd" 'spacemacs/copy-directory-path "fyl" 'spacemacs/copy-file-path-with-line + "fyn" 'spacemacs/copy-file-name + "fyN" 'spacemacs/copy-file-name-base "fyy" 'spacemacs/copy-file-path) ;; frame ---------------------------------------------------------------------- (spacemacs/set-leader-keys