[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: |
address@hidden |
Subject: |
Re: How to get current filename and absolute path of the file in emacs? |
Date: |
16 Apr 2007 02:35:32 -0700 |
User-agent: |
G2/1.0 |
On 4月16日, 下午12时30分, Eric Hanchrow <off...@blarg.net> wrote:
> >>>>> "QinGW" == QinGW <dealo...@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)
> --
Thanks very much.