Created
August 16, 2017 14:18
-
-
Save offby1/12eb47295bdd71db17dceb9abdab5dcf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun copy-buffer-file-name () | |
"Puts the file name of the current buffer (or the current directory, | |
if the buffer isn't visiting a file) onto the kill ring, so that | |
it can be retrieved with \\[yank], or by another program." | |
(interactive) | |
(let ((fn (or | |
(buffer-file-name (current-buffer)) | |
;; Perhaps the buffer isn't visiting a file at all. In | |
;; that case, let's return the directory. | |
(expand-file-name default-directory)))) | |
(when (null fn) | |
(error "Buffer doesn't appear to be associated with any file or directory.")) | |
(kill-new fn) | |
(message "%s" fn) | |
fn)) | |
(global-set-key (kbd "C-/") 'copy-buffer-file-name) | |
(global-set-key (kbd "<f8>") 'copy-buffer-file-name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment