unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Abbreviated filenames for display
@ 2005-04-26 18:31 Michael Mauger
  2005-04-26 20:01 ` Kevin Rodgers
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Michael Mauger @ 2005-04-26 18:31 UTC (permalink / raw)


This is not a critical need but it has been bugging me for a while.

I have three locations of files that I use regularly.  One is local on my w32 
machine, the other two are on Unix machines.  I use Tramp and everything works 
beatifully.  I have something like the following in my .emacs:

   (putenv "D0" "~/My Documents/Projects/xyz")
   (putenv "D1" "/sshx:myuser@unix1.abc.def.com:/home/myuser")
   (putenv "D2" "/sshx:myuser@unix2.abc.def.com:/home/myuser")

This allows me to specify remote files easily at the C-x C-f prompt, with a 
string like:

    Find File: $D2/proj/xyz/src/x.sql

The "$D2" gets expanded and my fingers don't fall off for excess wear.

What I'd like to be able to do, especially in the recentf menu or buffer lists, 
is to replace the long Tramp prefix with a shorter string that allows me to see 
what machine the file is from quicker.  Ideally, I'd like to be able to replace 
the leading portion of the file path with environment variable names I use when 
entering the file name.

For example, rather than showing me

    /sshx:myuser@unix2.abc.def.com:/home/myuser/proj/xyz/src/x.sql

as the filename, I want:

    $D2/proj/xyz/src/x.sql

Part of my problem is that the Unix host names are long and very similar and 
they hold two different but similarly structured directory trees (think, test 
and production files).  I've made the mistake of opening the file on the wrong 
host more than once because I didn't notice the host name difference in my 
haste.  (I'm a little ADHD as well, so I do it more often than I like to admit.)

I've played around with file name handlers, but quickly got lost.

Any ideas?  

-- Michael

PS. I'm on an up-to-date CVS HEAD build.  I'm elisp capable, so don't be shy.

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

* Re: Abbreviated filenames for display
  2005-04-26 18:31 Abbreviated filenames for display Michael Mauger
@ 2005-04-26 20:01 ` Kevin Rodgers
  2005-04-26 20:44 ` Michael Mauger
  2005-04-26 20:51 ` Michael Albinus
  2 siblings, 0 replies; 7+ messages in thread
From: Kevin Rodgers @ 2005-04-26 20:01 UTC (permalink / raw)


Michael Mauger wrote:
> This is not a critical need but it has been bugging me for a while.
> 
> I have three locations of files that I use regularly.  One is local on my w32 
> machine, the other two are on Unix machines.  I use Tramp and everything works 
> beatifully.  I have something like the following in my .emacs:
> 
>    (putenv "D0" "~/My Documents/Projects/xyz")
>    (putenv "D1" "/sshx:myuser@unix1.abc.def.com:/home/myuser")
>    (putenv "D2" "/sshx:myuser@unix2.abc.def.com:/home/myuser")
> 
> This allows me to specify remote files easily at the C-x C-f prompt, with a 
> string like:
> 
>     Find File: $D2/proj/xyz/src/x.sql
> 
> The "$D2" gets expanded and my fingers don't fall off for excess wear.
> 
> What I'd like to be able to do, especially in the recentf menu or buffer lists, 
> is to replace the long Tramp prefix with a shorter string that allows me to see 
> what machine the file is from quicker.  Ideally, I'd like to be able to replace 
> the leading portion of the file path with environment variable names I use when 
> entering the file name.
> 
> For example, rather than showing me
> 
>     /sshx:myuser@unix2.abc.def.com:/home/myuser/proj/xyz/src/x.sql
> 
> as the filename, I want:
> 
>     $D2/proj/xyz/src/x.sql
> 
> Part of my problem is that the Unix host names are long and very similar and 
> they hold two different but similarly structured directory trees (think, test 
> and production files).  I've made the mistake of opening the file on the wrong 
> host more than once because I didn't notice the host name difference in my 
> haste.  (I'm a little ADHD as well, so I do it more often than I like to admit.)
> 
> I've played around with file name handlers, but quickly got lost.

Does it make sense to put environment variables in directory-abbrev-alist?

(setq directory-abbrev-alist
       (list (cons (getenv "D0") "D0")
             (cons (getenv "D1") "D1")
             (cons (getenv "D2") "D2")))

-- 
Kevin Rodgers

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

* Re: Abbreviated filenames for display
       [not found] <mailman.3088.1114541205.2895.help-gnu-emacs@gnu.org>
@ 2005-04-26 20:04 ` kin
  2005-04-26 22:12 ` Peter Lee
  1 sibling, 0 replies; 7+ messages in thread
From: kin @ 2005-04-26 20:04 UTC (permalink / raw)


You could use substitute-in-file-name in a find-file defadvice.

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

* Re: Abbreviated filenames for display
  2005-04-26 18:31 Abbreviated filenames for display Michael Mauger
  2005-04-26 20:01 ` Kevin Rodgers
@ 2005-04-26 20:44 ` Michael Mauger
  2005-04-26 20:51 ` Michael Albinus
  2 siblings, 0 replies; 7+ messages in thread
From: Michael Mauger @ 2005-04-26 20:44 UTC (permalink / raw)


Additional item below:

Michael Mauger <mmaug <at> yahoo.com> writes:

> 
> This is not a critical need but it has been bugging me for a while.
> 
> I have three locations of files that I use regularly.  One is local on my w32 
> machine, the other two are on Unix machines.  I use Tramp and everything 
works 
> beatifully.  I have something like the following in my .emacs:
> 
>    (putenv "D0" "~/My Documents/Projects/xyz")
>    (putenv "D1" "/sshx:myuser@unix1.abc.def.com:/home/myuser")
>    (putenv "D2" "/sshx:myuser@unix2.abc.def.com:/home/myuser")
> 
> This allows me to specify remote files easily at the C-x C-f prompt, with a 
> string like:
> 
>     Find File: $D2/proj/xyz/src/x.sql
> 
> The "$D2" gets expanded and my fingers don't fall off for excess wear.
> 

One additional point -- I have tried to use `directory-abbrev-alist' but it 
gets applied and the result expanded multiple times so that you end up with a 
mess.

For example:

   (setq directory-abbrev-alist
     '(("~/My Documents/Projects/xyz" . "$D0")
       ("/sshx:myuser@unix1.abc.def.com:/home/myuser" . "$D1")
       ("/sshx:myuser@unix2.abc.def.com:/home/myuser" . "$D2")))

I end up with filenames like:

   $D2/proj/xyz/src/$D2/proj/xyz/src/$D2/proj/xyz/src/$D2/proj/xyz/src/x.sql

Thanks again.

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

* Re: Abbreviated filenames for display
  2005-04-26 18:31 Abbreviated filenames for display Michael Mauger
  2005-04-26 20:01 ` Kevin Rodgers
  2005-04-26 20:44 ` Michael Mauger
@ 2005-04-26 20:51 ` Michael Albinus
  2 siblings, 0 replies; 7+ messages in thread
From: Michael Albinus @ 2005-04-26 20:51 UTC (permalink / raw)
  Cc: help-gnu-emacs

Michael Mauger <mmaug@yahoo.com> writes:

> What I'd like to be able to do, especially in the recentf menu or buffer lists, 
> is to replace the long Tramp prefix with a shorter string that allows me to see 
> what machine the file is from quicker.  Ideally, I'd like to be able to replace 
> the leading portion of the file path with environment variable names I use when 
> entering the file name.
>
> Any ideas?  

In <http://www.gnu.org/software/tramp/#Frequently-Asked-Questions>,
several approaches are discussed shortening Tramp file names. I
haven't checked, but maybe one of them is useful for the display as
well.

There is also a recipe for a host indication in the mode line. 

> -- Michael
>
> PS. I'm on an up-to-date CVS HEAD build.  I'm elisp capable, so don't be shy.

Best regards, Michael.

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

* Re: Abbreviated filenames for display
@ 2005-04-26 21:57 Michael Mauger
  0 siblings, 0 replies; 7+ messages in thread
From: Michael Mauger @ 2005-04-26 21:57 UTC (permalink / raw)
  Cc: help-gnu-emacs

--- Michael Albinus <michael.albinus@gmx.de> wrote:
> Michael Mauger <mmaug@yahoo.com> writes:
> 
> > Any ideas?  
> 
> In <http://www.gnu.org/software/tramp/#Frequently-Asked-Questions>,
> several approaches are discussed shortening Tramp file names. I
> haven't checked, but maybe one of them is useful for the display as
> well.
> 

Thanks.  These are useful, but as you suspected they address the entry
problem rather than display.  I currently use the environment variable
substitution which works nicely with ido.el (it does expansion so that
completion is available).  

`cygwin-mount.el' interferes with the `directory-abbrev-alist' solution
because it grabs the abbreviation and expands it relative to the Cygwin
root directory before the abbreviation is expanded.  Maybe if this can be
corrected, I can use the `directory-abbrev-alist' solution because it
seems to do much of what I want.

> There is also a recipe for a host indication in the mode line. 
> 

This is useful and I've modified it for my use.

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

* Re: Abbreviated filenames for display
       [not found] <mailman.3088.1114541205.2895.help-gnu-emacs@gnu.org>
  2005-04-26 20:04 ` kin
@ 2005-04-26 22:12 ` Peter Lee
  1 sibling, 0 replies; 7+ messages in thread
From: Peter Lee @ 2005-04-26 22:12 UTC (permalink / raw)


>>>> Michael Mauger writes:

    >    (putenv "D0" "~/My Documents/Projects/xyz")
    >    (putenv "D1" "/sshx:myuser@unix1.abc.def.com:/home/myuser")
    >    (putenv "D2" "/sshx:myuser@unix2.abc.def.com:/home/myuser")

You can also use abbrev.

(define-abbrev global-abbrev-table "D0" "~/My Documents/Projects/xyz")
(define-abbrev global-abbrev-table "D1" "/sshx:myuser@unix1.abc.def.com:/home/myuser")
(define-abbrev global-abbrev-table "D2" "/sshx:myuser@unix2.abc.def.com:/home/myuser")

and then type C-x C-f D0[C-x ']

,----[ C-h k C-x ' ]
| C-x ' runs the command expand-abbrev
|    which is an interactive built-in function in `C source code'.
| It is bound to C-x ', C-x a ', C-x a e.
| (expand-abbrev)
| 
| Expand the abbrev before point, if there is an abbrev there.
| Effective when explicitly called even when `abbrev-mode' is nil.
| Returns the abbrev symbol, if expansion took place.
`----


    > For example, rather than showing me
    >     /sshx:myuser@unix2.abc.def.com:/home/myuser/proj/xyz/src/x.sql
    > as the filename, I want:
    >     $D2/proj/xyz/src/x.sql

Take a look at uniquify.el.  It comes with cvs emacs... I don't
remember if it was part of 21.3 or not... if it wasn't you can search
around for it via google.  It's a nice package for this type of thing
and you can probably configure it to give you what you want.

(require 'uniquify)
(setq uniquify-buffer-name-style 'post-forward)

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

end of thread, other threads:[~2005-04-26 22:12 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-04-26 18:31 Abbreviated filenames for display Michael Mauger
2005-04-26 20:01 ` Kevin Rodgers
2005-04-26 20:44 ` Michael Mauger
2005-04-26 20:51 ` Michael Albinus
  -- strict thread matches above, loose matches on Subject: below --
2005-04-26 21:57 Michael Mauger
     [not found] <mailman.3088.1114541205.2895.help-gnu-emacs@gnu.org>
2005-04-26 20:04 ` kin
2005-04-26 22:12 ` Peter Lee

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