[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to get current filename and absolute path of the file in emacs?
From: |
Eric Hanchrow |
Subject: |
Re: How to get current filename and absolute path of the file in emacs? |
Date: |
Sun, 15 Apr 2007 21:30:19 -0700 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.0.97 (gnu/linux) |
>>>>> "QinGW" == QinGW <dealover@21cn.com> writes:
QinGW> I want to put current filename and file path to clipboard
QinGW> and I cant get it by short key.how can I implement it?
QinGW> Thank a lot.
This is what I use:
(setq x-select-enable-clipboard t)
(defun copy-buffer-file-name (use-backslashes)
"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. With argument,
uses backslashes instead of forward slashes."
(interactive "P")
(let ((fn (subst-char-in-string
?/
(if use-backslashes ?\\ ?/)
(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 "<f8>") 'copy-buffer-file-name)
--