From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "qingwuking@gmail.com" Newsgroups: gmane.emacs.help Subject: Re: How to get current filename and absolute path of the file in emacs? Date: 16 Apr 2007 02:35:32 -0700 Organization: http://groups.google.com Message-ID: <1176716132.597633.77330@d57g2000hsg.googlegroups.com> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="gb2312" Content-Transfer-Encoding: quoted-printable X-Trace: sea.gmane.org 1176719757 16041 80.91.229.12 (16 Apr 2007 10:35:57 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 16 Apr 2007 10:35:57 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Apr 16 12:35:52 2007 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1HdOYp-0006C9-Em for geh-help-gnu-emacs@m.gmane.org; Mon, 16 Apr 2007 12:35:51 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HdOdQ-0002ih-6d for geh-help-gnu-emacs@m.gmane.org; Mon, 16 Apr 2007 06:40:36 -0400 Original-Path: shelby.stanford.edu!newshub.stanford.edu!postnews.google.com!d57g2000hsg.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 38 Original-NNTP-Posting-Host: 220.231.9.237 Original-X-Trace: posting.google.com 1176716132 18682 127.0.0.1 (16 Apr 2007 09:35:32 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Mon, 16 Apr 2007 09:35:32 +0000 (UTC) In-Reply-To: User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i686; zh-CN; rv:1.8.1.1) Gecko/20061208 Firefox/2.0.0.1,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: d57g2000hsg.googlegroups.com; posting-host=220.231.9.237; posting-account=uWH2pQ0AAAAEj7SeC_wHiwbnp9OYGRBR Original-Xref: shelby.stanford.edu gnu.emacs.help:147118 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:42724 Archived-At: On 4=D4=C216=C8=D5, =CF=C2=CE=E712=CA=B130=B7=D6, Eric Hanchrow wrote: > >>>>> "QinGW" =3D=3D QinGW 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 dir= ectory.")) > (kill-new fn) > (message "%s" fn) > fn)) > > (global-set-key (kbd "") 'copy-buffer-file-name) > -- Thanks very much.