unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Emanuel Berg <embe8573@student.uu.se>
To: help-gnu-emacs@gnu.org
Subject: Re: tilde in dired default-directory but not elsewhere
Date: Wed, 09 Jul 2014 18:47:37 +0200	[thread overview]
Message-ID: <87tx6qqy1i.fsf@debian.uxu> (raw)
In-Reply-To: mailman.5106.1404870369.1147.help-gnu-emacs@gnu.org

Michael Heerdegen <michael_heerdegen@web.de> writes:

> Due to the doc, it is unspecified, which means both
> cases are ok.

OK, in my case they show up differently in the mode
line so it is something I'd like to fix.

By the way the tilde can be annoying in quite a few
cases, not just in Emacs. You'd think for some source
that is "only you" (no sudo, setuid, etc.) it'd just
work with tilde in the source. But it doesn't and it is
frustrating because you think there is a bug somewhere
else. Then you change the tilde to the path and it
works.

In Emacs I can't recall it has been a problem except
for one case. I wanted a defun that would kill the path
of the file shown in a buffer. That way, I could write
a message on half the screen, and look at the file
(buffer) on the other half, and were I to mention the
selfsame file in the message, I'd just kill and yank
the path. Normally I always preach about how
educational (and pleasant) it is not to be lazy and to
type everything. But here I make an exception because
paths, contrary to code, are so boring to type - and if
it is boring, it is much easier to make mistakes which
of course won't benefit the reader of the post...

Anyway, I wrote some code to do that. Just looking at
it, there is something itchy about it. This is also
something I think definitely should be built-in (if it
isn't) in one way or another.

(defun get-tilde-path ()
  (interactive)
  (let((path (buffer-file-name)))
    (if path
        (let*((sudo-prefix (format "/sudo:root@%s:" (message-make-domain)))
              (home-path (getenv "HOME"))
              (path-no-home
               (replace-regexp-in-string home-path "~" path))
              (tilde-path
               (replace-regexp-in-string sudo-prefix "" path-no-home)))
          tilde-path ) )))

(defun kill-path ()
  (interactive)
  (if (string= major-mode "dired-mode")
      (progn
        (kill-new dired-directory)
        (message " Directory path killed.") )
    (let((path (get-tilde-path)))
      (if path
          (progn
            (kill-new (get-tilde-path))
            (message " Path killed.") )
        (prog1 nil
          (message " Can't kill path! (Why?)") )))))

> (Also note that default-directory is a buffer local
> variable, and you didn't tell in your recipe in which
> buffer you looked at the binding)

Of course I didn't change the buffer in between:

1. emacs -Q
2. C-h v default-directory RET
3. C-x C-f test.el RET
4. point 2, again

> I think you should use `abbreviate-file-name` in your
> mode-line expression.

OK, I'll try that.

-- 
underground experts united


  parent reply	other threads:[~2014-07-09 16:47 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-07 21:38 tilde in dired default-directory but not elsewhere Emanuel Berg
2014-07-08 18:27 ` Michael Heerdegen
     [not found] ` <mailman.5106.1404870369.1147.help-gnu-emacs@gnu.org>
2014-07-09 16:47   ` Emanuel Berg [this message]
2014-07-09 17:43   ` Emanuel Berg
2014-07-09 17:56     ` Michael Heerdegen
     [not found]     ` <mailman.5128.1404928614.1147.help-gnu-emacs@gnu.org>
2014-07-09 18:05       ` Emanuel Berg
2014-07-09 21:14         ` Michael Heerdegen

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=87tx6qqy1i.fsf@debian.uxu \
    --to=embe8573@student.uu.se \
    --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).