all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* tilde in dired default-directory but not elsewhere
@ 2014-07-07 21:38 Emanuel Berg
  2014-07-08 18:27 ` Michael Heerdegen
       [not found] ` <mailman.5106.1404870369.1147.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 7+ messages in thread
From: Emanuel Berg @ 2014-07-07 21:38 UTC (permalink / raw)
  To: help-gnu-emacs

I noticed this because I use default-directory in the
mode line.

But I managed to reproduce this with emacs -Q like
this:

First start it and do describe-variable
default-directory. You get the tilde. Then open a file
with an .el extension which should bring Emacs to
emacs-lisp-mode. Do the dance again and it says
/home/user/!

Do `cd', and you get the tilde in the suggestion - but
describe it, and you get the explicit path!

Is this as it should be, and if so, is there a reason?

Interesting tho it might be, what I really want is the
tilde in the mode line, always, showing the complete
path. I have a huge font I suppose so it happens that
the path overflows the width of the terminal if I get
deep in the file tree. Besides my eye is trained for ~
and it looks sort of weird to see the /home/user/
stuff.

-- 
underground experts united


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: tilde in dired default-directory but not elsewhere
  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>
  1 sibling, 0 replies; 7+ messages in thread
From: Michael Heerdegen @ 2014-07-08 18:27 UTC (permalink / raw)
  To: help-gnu-emacs

Hi Emanuel,

> First start it and do describe-variable
> default-directory. You get the tilde. Then open a file
> with an .el extension which should bring Emacs to
> emacs-lisp-mode. Do the dance again and it says
> /home/user/!
>
> Do `cd', and you get the tilde in the suggestion - but
> describe it, and you get the explicit path!
>
> Is this as it should be, and if so, is there a reason?

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

(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)

> Interesting tho it might be, what I really want is the
> tilde in the mode line, always, showing the complete
> path. I have a huge font I suppose so it happens that
> the path overflows the width of the terminal if I get
> deep in the file tree. Besides my eye is trained for ~
> and it looks sort of weird to see the /home/user/
> stuff.

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


Michael.




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: tilde in dired default-directory but not elsewhere
       [not found] ` <mailman.5106.1404870369.1147.help-gnu-emacs@gnu.org>
@ 2014-07-09 16:47   ` Emanuel Berg
  2014-07-09 17:43   ` Emanuel Berg
  1 sibling, 0 replies; 7+ messages in thread
From: Emanuel Berg @ 2014-07-09 16:47 UTC (permalink / raw)
  To: help-gnu-emacs

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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: tilde in dired default-directory but not elsewhere
       [not found] ` <mailman.5106.1404870369.1147.help-gnu-emacs@gnu.org>
  2014-07-09 16:47   ` Emanuel Berg
@ 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>
  1 sibling, 2 replies; 7+ messages in thread
From: Emanuel Berg @ 2014-07-09 17:43 UTC (permalink / raw)
  To: help-gnu-emacs

Michael Heerdegen <michael_heerdegen@web.de> writes:

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

Yes, this works:

(setq-default mode-line-format
              '(:eval (abbreviate-file-name (buffer-file-name))))

Now it will be interesting to see how much work is
required to make it work the right way for dired and
sudo buffers, not to mention all the "file-less"
modes...

On the bright side, `abbreviate-file-name' I can
probably also use to clean up the code I just posted,
that of killing the path!
              
-- 
underground experts united


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: tilde in dired default-directory but not elsewhere
  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>
  1 sibling, 0 replies; 7+ messages in thread
From: Michael Heerdegen @ 2014-07-09 17:56 UTC (permalink / raw)
  To: help-gnu-emacs

Emanuel Berg <embe8573@student.uu.se> writes:

> Now it will be interesting to see how much work is
> required to make it work the right way for dired and
> sudo buffers, not to mention all the "file-less"
> modes...

What use case do you have in mind?  Can you give an example?

Because, commands reading in file names typically call
`read-file-name-default`, which uses `abbreviate-file-name`.  That
means, dired for example should never prompt with /home/user/...

Michael.




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: tilde in dired default-directory but not elsewhere
       [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
  0 siblings, 1 reply; 7+ messages in thread
From: Emanuel Berg @ 2014-07-09 18:05 UTC (permalink / raw)
  To: help-gnu-emacs

Michael Heerdegen <michael_heerdegen@web.de> writes:

>> Now it will be interesting to see how much work is
>> required to make it work the right way for dired and
>> sudo buffers, not to mention all the "file-less"
>> modes...
>
> What use case do you have in mind?  Can you give an
> example?

Now I only speak of the mode line. I think I found a
way. First, define it for example like this (possibly
add some more, later).

(setq    column-number-mode  nil)
(setq    line-number-mode    nil)
(defvar  show-modified       t)
(defvar  show-path           t)
(defvar  show-modes          nil)

(setq-default mode-line-format
   `(" "
     (show-modified mode-line-modified)
     " "
     (show-path (:eval (abbreviate-file-name (buffer-file-name)) ))
     " "
     (show-modes mode-line-modes)
     (line-number-mode   "[%l] ")
     (column-number-mode "{%c}")
     ))

For the modes that should show different stuff, simply
change those variables (show-path etc.) locally.
     
-- 
underground experts united


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: tilde in dired default-directory but not elsewhere
  2014-07-09 18:05       ` Emanuel Berg
@ 2014-07-09 21:14         ` Michael Heerdegen
  0 siblings, 0 replies; 7+ messages in thread
From: Michael Heerdegen @ 2014-07-09 21:14 UTC (permalink / raw)
  To: help-gnu-emacs

Emanuel Berg <embe8573@student.uu.se> writes:

> (setq    column-number-mode  nil)
> (setq    line-number-mode    nil)
> (defvar  show-modified       t)
> (defvar  show-path           t)
> (defvar  show-modes          nil)
>
> (setq-default mode-line-format
>    `(" "
>      (show-modified mode-line-modified)
>      " "
>      (show-path (:eval (abbreviate-file-name (buffer-file-name)) ))
>      " "
>      (show-modes mode-line-modes)
>      (line-number-mode   "[%l] ")
>      (column-number-mode "{%c}")
>      ))

Looks like a reasonable approach.  Be careful with errors from :eval
expressions, e.g.

  (:eval (abbreviate-file-name (buffer-file-name)) )

will give you annoying error messages when redisplay is performed when
(buffer-file-name) yields nil.  Of course you can ensure that show-path
is always nil in this case ... but

    (:eval (and buffer-file-name (abbreviate-file-name buffer-file-name)))

is probably safer.


Michael.




^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2014-07-09 21:14 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.