all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Looking for CDPATH functionality in emacs.
@ 2011-01-03 18:55 Steven W. Orr
  2011-01-03 19:08 ` Thien-Thi Nguyen
                   ` (5 more replies)
  0 siblings, 6 replies; 9+ messages in thread
From: Steven W. Orr @ 2011-01-03 18:55 UTC (permalink / raw
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 2388 bytes --]

This is a bit long, so all I can do is apologise.

I have a number of directories that I use frequently. From the bash side of
things I set the CDPATH variable in bash to :d1:d2:d3 and then I can just go
to places inside d[123] and it just works. I also have the bash variable
cdable_vars set to allow me to say

d4=/path/to/d4

followed by

cd d4

and it all works peachy keen.

What I'd like to do in emacs is to be able to visit a file in some directory
that I favor (somehow) so that it will automagically find it without having to
slog through the whole path to get there.

I did find file-cache-find-directory which looks like it's half of what I
want. But that has two problems:

1. I added this to my .emacs

(file-cache-add-directory "/path/to/special/dir")

I saw no special behavior when I ran this, either from my .emacs or interactively.

2. I normally visit files using my own my-visit-file function:

(defun my-visit-file (arg)
  "Visit a file using completion. If there is only one window with
nothing in it, then do not split the current window. "
  (interactive "Fmy-visit-file :")
  (if (and (one-window-p) (zerop (buffer-size)))
      (find-file arg t)
      (find-file-other-window arg t)))

I use this function so that if I visit a file from an empty buffer, I won't
end up with two windows.

The problem is that if I had run file-cache-add-directory, the find-file
function starts in the directory of where the current buffer is. I'd like to
make it so that if I supplied a C-u to my-visit-file then it would *not* start
from that current directory. Instead, it should give me a prompt as if I had
done a C-a C-k to get rid of the directory.

So, if you made it this far, here's the recap:

1. Does anything already exist that smells like what I want?
2. Can I fix my-visit-file so that a C-u will prevent the default prompt from
being the current directory of the file I'm starting from? (But I do still
want filename completion.)
3. Does anyone have a better idea?

MTIA :-)

-- 
Time flies like the wind. Fruit flies like a banana. Stranger things have  .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at syslang.net


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 261 bytes --]

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

* Re: Looking for CDPATH functionality in emacs.
  2011-01-03 18:55 Looking for CDPATH functionality in emacs Steven W. Orr
@ 2011-01-03 19:08 ` Thien-Thi Nguyen
  2011-01-03 19:20 ` Drew Adams
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: Thien-Thi Nguyen @ 2011-01-03 19:08 UTC (permalink / raw
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 778 bytes --]

() "Steven W. Orr" <steveo@syslang.net>
() Mon, 03 Jan 2011 13:55:01 -0500

   1. Does anything already exist that smells like what I want?

Probably smells regardless, but FWIW, i use ‘jamenv-from-file’
(attached) with a ~/.directory-env-vars that looks like:

--8<---------------cut here---------------start------------->8---
;;; -*- emacs-lisp -*-
;;; comments start with ";"
;;; lines of form "- VAR" clear env var VAR
;;; lines of form "VAR VALUE" set env var VAR to VALUE

;; clear
- OLDPWD
- PAGER
- PWD

;; set
D               ~/build/tastiera-dura
G               ~/build/GNU
GG              ~/build/GNU/GG
--8<---------------cut here---------------end--------------->8---

Then, to get to, say ~/build/GNU, i type ‘C-x C-f $G RET’.


[-- Attachment #2: jamenv.el --]
[-- Type: application/emacs-lisp, Size: 1911 bytes --]

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

* RE: Looking for CDPATH functionality in emacs.
  2011-01-03 18:55 Looking for CDPATH functionality in emacs Steven W. Orr
  2011-01-03 19:08 ` Thien-Thi Nguyen
@ 2011-01-03 19:20 ` Drew Adams
  2011-01-03 20:16 ` Peter Dyballa
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: Drew Adams @ 2011-01-03 19:20 UTC (permalink / raw
  To: 'Steven W. Orr', help-gnu-emacs

You might want to look at Emacs bookmarks.  They provide a quick, named,
persistent way to get to a directory (or file) of your choice.  The target can
be local or remote.

(If you use Bookmark+ then a Dired-buffer bookmark saves also the markings,
inserted subdirs, and hidden ("omitted") files and subdirs, which can be handy.
http://www.emacswiki.org/BookmarkPlus)




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

* Re: Looking for CDPATH functionality in emacs.
  2011-01-03 18:55 Looking for CDPATH functionality in emacs Steven W. Orr
  2011-01-03 19:08 ` Thien-Thi Nguyen
  2011-01-03 19:20 ` Drew Adams
@ 2011-01-03 20:16 ` Peter Dyballa
  2011-01-04  4:42 ` Le Wang
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: Peter Dyballa @ 2011-01-03 20:16 UTC (permalink / raw
  To: Steven W. Orr; +Cc: help-gnu-emacs


Am 03.01.2011 um 19:55 schrieb Steven W. Orr:

> I have a number of directories that I use frequently


Desktop is fine (session.el adds some nice things). Start-up might  
take a minute or two more...

--
Greetings

   Pete

The light at the end of the tunnel has been turned off due to budget  
cuts.




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

* Re: Looking for CDPATH functionality in emacs.
  2011-01-03 18:55 Looking for CDPATH functionality in emacs Steven W. Orr
                   ` (2 preceding siblings ...)
  2011-01-03 20:16 ` Peter Dyballa
@ 2011-01-04  4:42 ` Le Wang
  2011-01-04  9:43   ` Le Wang
  2011-01-04  5:55 ` Kevin Rodgers
  2011-01-06  0:37 ` DevZero
  5 siblings, 1 reply; 9+ messages in thread
From: Le Wang @ 2011-01-04  4:42 UTC (permalink / raw
  To: Steven W. Orr; +Cc: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 1405 bytes --]

On Tue, Jan 4, 2011 at 2:55 AM, Steven W. Orr <steveo@syslang.net> wrote:

> So, if you made it this far, here's the recap:
>
> 1. Does anything already exist that smells like what I want?
>

Yes, abbrev (see below).  I don't use them heavily myself, but here is a
tutorial: http://xahlee.org/emacs/emacs_abbrev_mode.html


> 2. Can I fix my-visit-file so that a C-u will prevent the default prompt
> from
> being the current directory of the file I'm starting from? (But I do still
> want filename completion.)
>

Read the filename yourself, so you can have control:

(defun my-visit-file (arg)
 "Visit a file using completion. If there is only one window with
nothing in it, then do not split the current window. "
 (interactive "P")
 (let ((insert-default-directory t)
       my-file)
   (when (equal arg '(4))
     (setq insert-default-directory nil))
   (setq my-file (read-file-name "my-visit-file: "))
   (if (and (one-window-p) (zerop (buffer-size)))
       (find-file my-file)
     (find-file-(or  )ther-window my-file))))

(define-abbrev-table 'global-abbrev-table
  '(("spec" "/path/to/special/dir" nil 0)))


You can read the doc on `read-file-name' and `insert-default-directory' for
yourself.  I've also added an abbrev table entry for "spec".  So, if you
<C-u>my-find-file, "spec", <C-x>ae, it should expand do what you want.

You can bind expansion to a shorter chord if you like.

-- 
Le

[-- Attachment #2: Type: text/html, Size: 3027 bytes --]

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

* Re: Looking for CDPATH functionality in emacs.
  2011-01-03 18:55 Looking for CDPATH functionality in emacs Steven W. Orr
                   ` (3 preceding siblings ...)
  2011-01-04  4:42 ` Le Wang
@ 2011-01-04  5:55 ` Kevin Rodgers
  2011-01-06  0:37 ` DevZero
  5 siblings, 0 replies; 9+ messages in thread
From: Kevin Rodgers @ 2011-01-04  5:55 UTC (permalink / raw
  To: help-gnu-emacs

On 1/3/11 11:55 AM, Steven W. Orr wrote:
> This is a bit long, so all I can do is apologise.
>
> I have a number of directories that I use frequently. From the bash side of
> things I set the CDPATH variable in bash to :d1:d2:d3 and then I can just go
> to places inside d[123] and it just works. I also have the bash variable
> cdable_vars set to allow me to say
>
> d4=/path/to/d4
>
> followed by
>
> cd d4
>
> and it all works peachy keen.
>
> What I'd like to do in emacs is to be able to visit a file in some directory
> that I favor (somehow) so that it will automagically find it without having to
> slog through the whole path to get there.
>
> I did find file-cache-find-directory which looks like it's half of what I
> want. But that has two problems:
>
> 1. I added this to my .emacs
>
> (file-cache-add-directory "/path/to/special/dir")
>
> I saw no special behavior when I ran this, either from my .emacs or interactively.

According to filecache.el:

;; FINDING FILES USING THE CACHE:
;;
;; You can use the file-cache with any function that expects a filename as
;; an argument. For example:
;;
;; 1) Invoke a function which expects a filename as an argument:
;;    M-x find-file
;;
;; 2) Begin typing a file name.
;;
;; 3) Invoke `file-cache-minibuffer-complete' (bound by default to
;; C-TAB) to complete on the filename using the cache.
;;
;; 4) When you have found a unique completion, the minibuffer contents
;; will change to the full name of that file.
;;
;; If there are a number of directories which contain the completion,
;; invoking `file-cache-minibuffer-complete' repeatedly will cycle through
;; them.
;;
;; 5) You can then edit the minibuffer contents, or press RETURN.
;;
;; It is much easier to simply try it than trying to explain it :)

> 2. I normally visit files using my own my-visit-file function:
>
> (defun my-visit-file (arg)
>    "Visit a file using completion. If there is only one window with
> nothing in it, then do not split the current window. "
>    (interactive "Fmy-visit-file :")
>    (if (and (one-window-p) (zerop (buffer-size)))
>        (find-file arg t)
>        (find-file-other-window arg t)))
>
> I use this function so that if I visit a file from an empty buffer, I won't
> end up with two windows.

Actually, that is Emacs' default behavior.  Using M-x my-visit-file
only behaves differently than M-x find-file when you have more than one
window or the current is not empty: in that case, it behaves like
M-x find-file-other-window.

> The problem is that if I had run file-cache-add-directory, the find-file
> function starts in the directory of where the current buffer is. I'd like to
> make it so that if I supplied a C-u to my-visit-file then it would *not* start
> from that current directory. Instead, it should give me a prompt as if I had
> done a C-a C-k to get rid of the directory.

Reading a file name via (interactive "F...") always starts from the current
buffer's default directory, regardless of whether file-cache-add-directory
has been run.

If you want to make my-find-file behave differently when reading its ARG,
depending on whether a prefix arg was supplied, then change the interactive
form to use a lisp expression that respects current-prefix-arg (instead of a
string specifier).

> So, if you made it this far, here's the recap:
>
> 1. Does anything already exist that smells like what I want?

Use filecache as it is documented.

> 2. Can I fix my-visit-file so that a C-u will prevent the default prompt from
> being the current directory of the file I'm starting from? (But I do still
> want filename completion.)

(interactive (list (if current-prefix-arg
		       (read-file-name "My file: " "/")
		     (read-file-name "My file: "))))

> 3. Does anyone have a better idea?

:-)

-- 
Kevin Rodgers
Denver, Colorado, USA




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

* Re: Looking for CDPATH functionality in emacs.
  2011-01-04  4:42 ` Le Wang
@ 2011-01-04  9:43   ` Le Wang
  0 siblings, 0 replies; 9+ messages in thread
From: Le Wang @ 2011-01-04  9:43 UTC (permalink / raw
  To: Steven W. Orr; +Cc: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 2211 bytes --]

Sorry, I'm trying out yasnippet, and it expanded something in the code
accidentally.  Here is the right bits:

(defun my-visit-file (arg)
 "Visit a file using completion. If there is only one window with
nothing in it, then do not split the current window. "
 (interactive "P")
 (let ((insert-default-directory t)
       my-file)
   (when (equal arg '(4))
     (setq insert-default-directory nil))
   (setq my-file (read-file-name "my-visit-file: "))
   (if (and (one-window-p) (zerop (buffer-size)))
       (find-file my-file)
     (find-file-ther-window my-file))))

(define-abbrev-table 'global-abbrev-table
  '(("spec" "/path/to/special/dir" nil 0)))



On Tue, Jan 4, 2011 at 12:42 PM, Le Wang <l26wang@gmail.com> wrote:

> On Tue, Jan 4, 2011 at 2:55 AM, Steven W. Orr <steveo@syslang.net> wrote:
>
>> So, if you made it this far, here's the recap:
>>
>> 1. Does anything already exist that smells like what I want?
>>
>
> Yes, abbrev (see below).  I don't use them heavily myself, but here is a
> tutorial: http://xahlee.org/emacs/emacs_abbrev_mode.html
>
>
>> 2. Can I fix my-visit-file so that a C-u will prevent the default prompt
>> from
>> being the current directory of the file I'm starting from? (But I do still
>> want filename completion.)
>>
>
> Read the filename yourself, so you can have control:
>
> (defun my-visit-file (arg)
>  "Visit a file using completion. If there is only one window with
> nothing in it, then do not split the current window. "
>  (interactive "P")
>  (let ((insert-default-directory t)
>        my-file)
>    (when (equal arg '(4))
>      (setq insert-default-directory nil))
>    (setq my-file (read-file-name "my-visit-file: "))
>    (if (and (one-window-p) (zerop (buffer-size)))
>        (find-file my-file)
>      (find-file-(or  )ther-window my-file))))
>
> (define-abbrev-table 'global-abbrev-table
>   '(("spec" "/path/to/special/dir" nil 0)))
>
>
> You can read the doc on `read-file-name' and `insert-default-directory' for
> yourself.  I've also added an abbrev table entry for "spec".  So, if you
> <C-u>my-find-file, "spec", <C-x>ae, it should expand do what you want.
>
> You can bind expansion to a shorter chord if you like.
>
> --
> Le
>



-- 
Le

[-- Attachment #2: Type: text/html, Size: 4691 bytes --]

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

* Re: Looking for CDPATH functionality in emacs.
  2011-01-03 18:55 Looking for CDPATH functionality in emacs Steven W. Orr
                   ` (4 preceding siblings ...)
  2011-01-04  5:55 ` Kevin Rodgers
@ 2011-01-06  0:37 ` DevZero
  5 siblings, 0 replies; 9+ messages in thread
From: DevZero @ 2011-01-06  0:37 UTC (permalink / raw
  To: help-gnu-emacs

Msg from Steven W. Orr [steveo@syslang.net/3.0K] at 03.01/19:55
> What I'd like to do in emacs is to be able to visit a file in some directory
> that I favor (somehow) so that it will automagically find it without having to
> slog through the whole path to get there.

i was searching for that too - and found it in ido-mode!
if you do C-x C-f and just type a (maybe even partial) file- or directory name
ido will expand it (if you visited that file before)...

greetz
-- 
Nature abhors a virgin -- a frozen asset.



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

* Re: Looking for CDPATH functionality in emacs.
       [not found] <mailman.12.1294080915.3992.help-gnu-emacs@gnu.org>
@ 2011-01-06  9:40 ` Stefan Kamphausen
  0 siblings, 0 replies; 9+ messages in thread
From: Stefan Kamphausen @ 2011-01-06  9:40 UTC (permalink / raw
  To: help-gnu-emacs

Hi Steven,


"Steven W. Orr" <steveo@syslang.net> writes:

> This is a bit long, so all I can do is apologise.
>
> I have a number of directories that I use frequently. From the bash side of
> things I set the CDPATH variable in bash to :d1:d2:d3 and then I can just go
> to places inside d[123] and it just works. I also have the bash variable
> cdable_vars set to allow me to say
>
> d4=/path/to/d4
>
> followed by
>
> cd d4
>
> and it all works peachy keen.

you might want to checkout a program called cdargs (yes, this is a
shameless self-ad).  It provides bookmarks for the shell (bash is well
supported, tcsh and zsh a little bit) and also integrates into emacs so
that you can do a "M-x cv" and use the same bookmarks as in bash. 

In addition to that, you might also be interested in anything
(anything.el) which I use a lot these days.


Kind regards,
Stefan
-- 
a blessed +42 regexp of confusion (weapon in hand)
You hit. The format string crumbles and turns to dust.
user=> (clojure-buch (Locale/GERMANY))
#<URL http://www.clojure-buch.de>


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

end of thread, other threads:[~2011-01-06  9:40 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-01-03 18:55 Looking for CDPATH functionality in emacs Steven W. Orr
2011-01-03 19:08 ` Thien-Thi Nguyen
2011-01-03 19:20 ` Drew Adams
2011-01-03 20:16 ` Peter Dyballa
2011-01-04  4:42 ` Le Wang
2011-01-04  9:43   ` Le Wang
2011-01-04  5:55 ` Kevin Rodgers
2011-01-06  0:37 ` DevZero
     [not found] <mailman.12.1294080915.3992.help-gnu-emacs@gnu.org>
2011-01-06  9:40 ` Stefan Kamphausen

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.