Tilde for SBCL convenience

« previous entry | next entry »
Jul. 9th, 2008 | 01:17 pm

Every now and then I want to use leading tildes in SBCL pathnames. That is, something like this:

(probe-file "~/.emacs") =>
   #P"/home/xach/.emacs" 
OR #P"/Users/xach/.emacs"
OR #P"/usr/u/xach/.emacs"

I know about user-homedir-pathname, but it's not quite convenient for interactive REPL use.

So I put together a short file that patches SBCL internals slightly so leading tildes in pathnames go through the POSIX getpw interface to look up home directories. It's not something I'll ever use in source files, but it's pretty convenient interactively.

To use it yourself, just download tilde.lisp and add this to your ~/.sbclrc:

(load "/path/to/tilde.lisp")
(tilde:install-tilde-expander)

After that, you can use "~/foo" and "~bob/foo" in SBCL pathnames.

update Here's a git repo for tilde.lisp, with an ASDF system file too.

Tags:

Link | Leave a comment | Add to Memories | Tell a Friend

Comments {9}

Patrick

(no subject)

from: [info]patrickwonders
date: Jul. 9th, 2008 06:36 pm (UTC)
Link

Awesome... thanks...

Reply | Thread

Patrick

(no subject)

from: [info]patrickwonders
date: Jul. 9th, 2008 06:52 pm (UTC)
Link

Of course, this ran me smack into a thing that I've never gotten sorted out in my head....
I wanted to do this:

#+sbcl
(and (load #P"/Users/pat/.sbcl/tilde.lisp")
(tilde:install-tilde-expander))

Unfortunately, that yells and screams about there being no namespace 'tilde'. I would have thought that the conditional evaluation in the 'and' would have kept the reader from thinking that tilde:install-tilde-expander was necessarily a symbol. But, no dice.

I had hoped to get around it with a bunch of jumping through (eval-when ...) stuff, but again, no dice...

Any clues would be appreciated....

Reply | Parent | Thread

Zach Beane

(no subject)

from: [info]xach
date: Jul. 9th, 2008 07:01 pm (UTC)
Link

The reader must read the whole list starting with AND before evaluating it. There's a reason I put the commands in two different forms...

Anyway, if I were you, I'd use #+sbcl twice. Another option (that doesn't much appeal to me) is something like this:

#+sbcl
(when (load "tilde.lisp") (funcall (read-from-string "tilde:install-tilde-expander")))

Reply | Parent | Thread

Patrick

(no subject)

from: [info]patrickwonders
date: Jul. 9th, 2008 07:13 pm (UTC)
Link

Ah, right... I suppose it's the reader's job to intern symbols even if the form isn't going to get evaluated....

I do have it in separate forms, but I've stumbled before trying to get similar things to work and was afraid that calling load from somewhere other than the top-level meant that all the stuff it created got thrown out when load returned. But, I would guess that instead it's the same sort of thing with the reader trying to intern symbols even though they might not get evaluated.

And, yep... the "read-from-string" offends my sensibility, too. :). I'll just assume the load's going to succeed.

Thanks.

Reply | Parent | Thread

Simpler approach

from: anonymous
date: Jul. 9th, 2008 10:20 pm (UTC)
Link

I've been using something like this from hefner (http://ahefner.livejournal.com/5984.html) for a while:
   (defun ~ (name) (merge-pathnames name (user-homedir-pathname)))
It has the advantage of being plain CL.

Reply | Thread

clbuild

from: anonymous
date: Jul. 10th, 2008 08:07 am (UTC)
Link

Would you consider turning tilde.lisp into a git archive with an asd file, so that I can add it to clbuild?

David

Reply | Thread

Zach Beane

Re: clbuild

from: [info]xach
date: Jul. 10th, 2008 11:20 am (UTC)
Link

Ok, here it is:

http://github.com/xach/tilde/tree/master

Reply | Parent | Thread

Re: clbuild

from: anonymous
date: Jul. 10th, 2008 12:51 pm (UTC)
Link

Great, thanks. clbuild users can now run:

$ clbuild update tilde
$ clbuild dumpcore tilde

and then test it with:

$ clbuild preloaded

Slime users wouldn't run preloaded, but can enable START_SLIME_USING_CORE in clbuild.conf for the same effect.


David

Reply | Parent | Thread

But what if there's a tilde in my path to tilde.lisp?

from: anonymous
date: Jul. 11th, 2008 09:38 am (UTC)
Link

The recursion ... the bootstrapping goggles do nothing! ...

Reply | Thread