From 0c927816b3fc7264b29a7dfd40cfaa80f4528aa3 Mon Sep 17 00:00:00 2001 From: rekado Date: Wed, 16 Sep 2015 22:12:14 +0200 Subject: Add my/copy-buffer-file-name. --- lisp/init-my-stuff.el | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/lisp/init-my-stuff.el b/lisp/init-my-stuff.el index 3e670b9..b7bf92a 100644 --- a/lisp/init-my-stuff.el +++ b/lisp/init-my-stuff.el @@ -112,3 +112,24 @@ When repeated, a negative prefix arg switches direction." (unless (natnump n) (setq this-command 'comment-line-backward))) (global-set-key (kbd "C-;") 'my/endless/comment-line) + + +;; http://stackoverflow.com/a/18814469/519736 +(defun my/copy-buffer-file-name (choice) + "Copy the buffer-file-name to the kill-ring" + (interactive "cCopy Buffer Name (F) Full, (D) Directory, (N) Name") + (let ((new-kill-string) + (name (if (eq major-mode 'dired-mode) + (dired-get-filename) + (or (buffer-file-name) "")))) + (cond ((eq choice ?f) + (setq new-kill-string name)) + ((eq choice ?d) + (setq new-kill-string (file-name-directory name))) + ((eq choice ?n) + (setq new-kill-string (file-name-nondirectory name))) + (t (message "Quit"))) + (when new-kill-string + (message "%s copied" new-kill-string) + (kill-new new-kill-string)))) + -- cgit v1.2.3