help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: tilde in dired default-directory but not elsewhere


From: Emanuel Berg
Subject: Re: tilde in dired default-directory but not elsewhere
Date: Wed, 09 Jul 2014 18:47:37 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]