unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: <tomas@tuxteam.de>
To: help-gnu-emacs@gnu.org
Subject: Re: How to prevent Emacs from translating beginning of file path into "~"?
Date: Fri, 10 Apr 2015 10:49:46 +0200	[thread overview]
Message-ID: <20150410084946.GA32197@tuxteam.de> (raw)
In-Reply-To: <83bniwv2bv.fsf@gnu.org>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Fri, Apr 10, 2015 at 11:01:56AM +0300, Eli Zaretskii wrote:
> > Date: Fri, 10 Apr 2015 03:02:09 -0400
> > From: MBR <mbr@arlsoft.com>
> > 
> > The Emacs command ^x-^f (find-file) fills the mini-buffer with the full 

[...]

> What you need instead of this complicated method is a simple command
> that will copy the current buffer's default-directory to the
> clipboard.  That command should use expand-file-name, which will
> expand any "~" into its full absolute file name.

Indeed. And since I've found myself contorting my ways to achieve
that too (C-h v buffer-file-name or some such monstrosity), it seems
to be a useful thing to have. Thus a quick shot here:

  (defun copy-current-filename-as-kill ()
    (interactive)
    (kill-new
     (or (and buffer-file-name
              (expand-file-name buffer-file-name))
         "")))

Bind that to a global key like so:

  (global-set-key (kbd "C-c f") 'copy-current-filename-as-kill)

In this case it's bound to CONTROL-c f. Note that this is one of
the keys customarily reserved to users. Modfy binding to taste.

What can be modified too is the value copied to the kill ring
(mumble mumble "clipboard" mumble) when the current buffer has
no obvious file name -- I'm doing "" here (not copying anything
would be an option too, but could have surprising results when
you yank (mumble "paste" mumble) what you think was the last
file name and get half a bufferful of text, because that was
whatever you copied before).

HTH
- -- tomás
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)

iEYEARECAAYFAlUnjqoACgkQBcgs9XrR2kboKgCfdjbP3S6BOwB4JJyx+2cPxIc9
pBgAn0O6L0BId4zY1NmrpJiThglp+bV5
=K+cL
-----END PGP SIGNATURE-----



  reply	other threads:[~2015-04-10  8:49 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-10  7:02 How to prevent Emacs from translating beginning of file path into "~"? MBR
2015-04-10  8:01 ` Eli Zaretskii
2015-04-10  8:49   ` tomas [this message]
2015-04-10  9:16     ` Yuri Khan
2015-04-10  9:22       ` tomas
2015-04-11  5:35         ` Xavier Maillard
2015-04-11  5:48           ` tomas
2015-04-10 12:31 ` Stefan Monnier
2015-04-11 21:37   ` MBR

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150410084946.GA32197@tuxteam.de \
    --to=tomas@tuxteam.de \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).