* How to prevent Emacs from translating beginning of file path into "~"?
@ 2015-04-10 7:02 MBR
2015-04-10 8:01 ` Eli Zaretskii
2015-04-10 12:31 ` Stefan Monnier
0 siblings, 2 replies; 9+ messages in thread
From: MBR @ 2015-04-10 7:02 UTC (permalink / raw)
To: help-gnu-emacs
The Emacs command ^x-^f (find-file) fills the mini-buffer with the full
path to the current directory and then waits for you to type the
filename. I often I find it a useful way to copy the current directory
to the system's clipboard so I can paste the path into some other
application. For example, in Emacs I'll type:
^x-^f (put path to current directory into mini-buffer)
^a (go to beginning of line)
^k (kill from beginning to end of mini-buffer, with the
side effect of putting that string into the system clipboard)
^g (cancel out of mini-buffer)
At this point I can paste the path into any non-Emacs application by
typing CMD-v (in OS-X) or CTRL-v (in Windows or Linux).
But there's a problem. Current versions of Emacs (I'm currently running
Emacs 24.3.1 under OS-X) try to be smart and replace the beginning of
the path with "~" if it matches the logged in user's home directory.
Unfortunately, some applications don't understand paths that begin with "~".
Is it possible to configure Emacs to put the full path (beginning with
"/") into the mini-buffer, rather than just the path from the home
directory (beginning with "~")?
Mark Rosenthal
mbr@arlsoft.com
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to prevent Emacs from translating beginning of file path into "~"?
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
2015-04-10 12:31 ` Stefan Monnier
1 sibling, 1 reply; 9+ messages in thread
From: Eli Zaretskii @ 2015-04-10 8:01 UTC (permalink / raw)
To: help-gnu-emacs
> 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
> path to the current directory and then waits for you to type the
> filename. I often I find it a useful way to copy the current directory
> to the system's clipboard so I can paste the path into some other
> application. For example, in Emacs I'll type:
>
> ^x-^f (put path to current directory into mini-buffer)
> ^a (go to beginning of line)
> ^k (kill from beginning to end of mini-buffer, with the
> side effect of putting that string into the system clipboard)
> ^g (cancel out of mini-buffer)
>
> At this point I can paste the path into any non-Emacs application by
> typing CMD-v (in OS-X) or CTRL-v (in Windows or Linux).
>
> But there's a problem. Current versions of Emacs (I'm currently running
> Emacs 24.3.1 under OS-X) try to be smart and replace the beginning of
> the path with "~" if it matches the logged in user's home directory.
> Unfortunately, some applications don't understand paths that begin with "~".
>
> Is it possible to configure Emacs to put the full path (beginning with
> "/") into the mini-buffer, rather than just the path from the home
> directory (beginning with "~")?
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.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to prevent Emacs from translating beginning of file path into "~"?
2015-04-10 8:01 ` Eli Zaretskii
@ 2015-04-10 8:49 ` tomas
2015-04-10 9:16 ` Yuri Khan
0 siblings, 1 reply; 9+ messages in thread
From: tomas @ 2015-04-10 8:49 UTC (permalink / raw)
To: help-gnu-emacs
-----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-----
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to prevent Emacs from translating beginning of file path into "~"?
2015-04-10 8:49 ` tomas
@ 2015-04-10 9:16 ` Yuri Khan
2015-04-10 9:22 ` tomas
0 siblings, 1 reply; 9+ messages in thread
From: Yuri Khan @ 2015-04-10 9:16 UTC (permalink / raw)
To: tomas; +Cc: help-gnu-emacs@gnu.org
On Fri, Apr 10, 2015 at 2:49 PM, <tomas@tuxteam.de> wrote:
> 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
Might be beneficial to use dired-directory for dired buffers.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to prevent Emacs from translating beginning of file path into "~"?
2015-04-10 9:16 ` Yuri Khan
@ 2015-04-10 9:22 ` tomas
2015-04-11 5:35 ` Xavier Maillard
0 siblings, 1 reply; 9+ messages in thread
From: tomas @ 2015-04-10 9:22 UTC (permalink / raw)
To: Yuri Khan; +Cc: help-gnu-emacs@gnu.org
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Fri, Apr 10, 2015 at 03:16:07PM +0600, Yuri Khan wrote:
> On Fri, Apr 10, 2015 at 2:49 PM, <tomas@tuxteam.de> wrote:
>
> > 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
>
> Might be beneficial to use dired-directory for dired buffers.
Yep. Nice idea. Expanded version:
(defun copy-current-filename-as-kill ()
(interactive)
(let ((filename (or buffer-file-name
dired-directory)))
(kill-new
(or (and filename
(expand-file-name filename))
""))))
Just extend the (or ...) to taste for more cases :-)
Thanks
- -- tomás
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)
iEYEARECAAYFAlUnllkACgkQBcgs9XrR2kYyEACfVbmdPmhhRjAh0vDFrL4l4VFB
QhIAn2FiUIxdCTiKHhKQVqQpR+cbtTZn
=8YHw
-----END PGP SIGNATURE-----
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to prevent Emacs from translating beginning of file path into "~"?
2015-04-10 9:22 ` tomas
@ 2015-04-11 5:35 ` Xavier Maillard
2015-04-11 5:48 ` tomas
0 siblings, 1 reply; 9+ messages in thread
From: Xavier Maillard @ 2015-04-11 5:35 UTC (permalink / raw)
To: tomas; +Cc: help-gnu-emacs@gnu.org, Yuri Khan
tomas@tuxteam.de writes:
> On Fri, Apr 10, 2015 at 03:16:07PM +0600, Yuri Khan wrote:
>> On Fri, Apr 10, 2015 at 2:49 PM, <tomas@tuxteam.de> wrote:
>>
>> > 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
>>
>> Might be beneficial to use dired-directory for dired buffers.
>
> Yep. Nice idea. Expanded version:
Adopted. Thanks a lot !
-- Xavier.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to prevent Emacs from translating beginning of file path into "~"?
2015-04-11 5:35 ` Xavier Maillard
@ 2015-04-11 5:48 ` tomas
0 siblings, 0 replies; 9+ messages in thread
From: tomas @ 2015-04-11 5:48 UTC (permalink / raw)
To: Xavier Maillard; +Cc: help-gnu-emacs@gnu.org, Yuri Khan
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Sat, Apr 11, 2015 at 07:35:39AM +0200, Xavier Maillard wrote:
>
> tomas@tuxteam.de writes:
>
> > On Fri, Apr 10, 2015 at 03:16:07PM +0600, Yuri Khan wrote:
[...]
> Adopted. Thanks a lot !
C'est moi :-)
- -- t
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)
iEYEARECAAYFAlUotbgACgkQBcgs9XrR2kalqACfV5lywbPiX1404PN++f8jpvhs
8A4An3E8JXb8Bb6XY5NfsyJDnuuBjf38
=C7lR
-----END PGP SIGNATURE-----
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to prevent Emacs from translating beginning of file path into "~"?
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 12:31 ` Stefan Monnier
2015-04-11 21:37 ` MBR
1 sibling, 1 reply; 9+ messages in thread
From: Stefan Monnier @ 2015-04-10 12:31 UTC (permalink / raw)
To: help-gnu-emacs
> Unfortunately, some applications don't understand paths that begin with "~".
Hard to believe. I recommend you report these cases as bugs.
Stefan
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to prevent Emacs from translating beginning of file path into "~"?
2015-04-10 12:31 ` Stefan Monnier
@ 2015-04-11 21:37 ` MBR
0 siblings, 0 replies; 9+ messages in thread
From: MBR @ 2015-04-11 21:37 UTC (permalink / raw)
To: Stefan Monnier, help-gnu-emacs
On 4/10/15 8:31 AM, Stefan Monnier wrote:
>> Unfortunately, some applications don't understand paths that begin with "~".
> Hard to believe. I recommend you report these cases as bugs.
>
>
> Stefan
To do that I'd have to convince some standards body (IETF?, W3C?) to
modify RFC 1630 - not bloody likely. The applications I had in mind
when I said this are Firefox, Chrome, IE, Safari, and Opera when using
the "file" scheme. With just a few easy-to-type keystrokes, I can copy
the Emacs buffer's path and paste it into some browser's location bar
after first typing "file:". Viola - I'm looking at my desired directory!
Describing the exact keystrokes in words makes it sound complicated, but
actually typing it is pretty easy and far less error-prone than trying
to accurately type the full path into the location bar by hand.
In earlier versions of Emacs, this worked fine with all browsers,
regardless of what directory my Emacs buffer was in, because Emacs
wasn't trying to be smart about the home directory. But some version of
Emacs changed that, and it's been an annoyance ever since then.
Mark
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2015-04-11 21:37 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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
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).