TheClapp/ blog/ posts/ Name mangling the buffer list

I mirror some subtrees from the work server and edit files locally. (I write them back using this.) The base directory I mirror these subtrees into is 30 characters long, and the remote path can also be pretty long, which leaves me with some awfully long pathnames in the buffer-list panel. zsh has a facility where you can name a directory, and then it refers to those directories by name from then on. A sort-of real-life example:

~lmc > deployments=/home/lmc/work/xxx/xxxxxx/xxx/home/clappl/xxxxxx/xxxxxxxxxxxxxxxxxxxxxxxxxx/deployments
~lmc > cd ~deployments
~deployments > _

(And, of course, ~deployments has more stuff under it.)

So I wanted something like that for the Lispworks buffer list. After some poking at the Lispworks Window Browser, and the Inspecter, and various other tools, I came up with something that seems to work.

There are two basic tricks.

The buffer list is a standard multi-column-list-panel. This kind of panel will display lists of anything, as long as you give it a function to turn whatever it is, into a string. By default, the Editor buffer-list uses princ-to-string to turn the pathname of the file into a string. I installed my own print function that does the mangling I wanted. That's the first trick.

The second trick is getting a reference to the Editor object, after it's fully initialized (e.g. putting an :after method on initialize-instance of a lispworks-tools:editor object is too soon), so that you can perform the first trick. For that, I installed some :after advice on capi:display, so I can look at every top-level window that the IDE creates, and if it's an Editor window, I install the print functions as above.

Surprisingly, I do all this using only one undocumented function and one non-external slot, and they're both in a single function. Everything else was "above board", so to speak.

So anyway, here's the code.

Update 1, 6/5/08: It occurs to me (only now, of course, that I've completely implemented it, and even blogged about it) that perhaps logical pathnames would do the trick. I'll have to look at that. Oh well. :) It was fun, anyway.

Update 2, 6/6/08: And with just a few more undocumented functions, I've set the default sort in a buffer-list to be by pathname. LW is cool. :) (But see also update 4, below.)

Update 3, 6/8/08: Usage examples & screenshot (after all the other updates):

(add-translation "/home/lmc" "~lmc")
(add-translation "/home/lmc/lisp" "~lisp")
(add-translation "/home/lmc/lisp/lw-vim-mode" "~lw-vim-mode")
(add-translation "/home/lmc/theclapp.org/src/blog/posts" "~blog")

Update 4, 6/10/08: Change setting the default sort to use only documented, exported functions, to wit:

(capi:sorted-object-sort-by buffers-list :pathname)

Screenshot: