all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Several questions on SLIME customizations
@ 2006-11-19  5:32 Victor Kryukov
  2006-11-20 19:42 ` Robert Thorpe
  0 siblings, 1 reply; 3+ messages in thread
From: Victor Kryukov @ 2006-11-19  5:32 UTC (permalink / raw)


Hello list,

I've a couple emacs customization/elisp questions, which are not very
closely related, except that they have one unifying theme: making life
under SLIME better (as I understand it). I would appreciate if you
could answer at least some of them - and of course, feel free to share
you strategies to customize SLIME!

= Redefining TAB. =

I tried TextMate recently (yes, luckily I live under Mac OS X; no, I
don't want to start another flame war), and I especially like how it
treats TAB key - ok, ok, I know that their behaviour is risky because
it's context-dependent, but vim users somehow manage to accomodate to
multiple contexts ;).

Anyway, TAB is too valuable key to spare, as it's very easy to type,
and in my use case, I never need to use it _alone_: most often during
editing I need to wrap a bunch of lines into let statement, say, so I
need to indent a whole region anyway. Hence my strategy was like this:

(global-set-key "\r" 'newline-and-indent)

makes Return indent next line automatically, and the following function
indents the whole defun:

(defun indent-defun ()
  (interactive)
  (let (a b)
    (beginning-of-defun)
    (setq a (point))
    (end-of-defun)
    (setq b (point))
    (indent-region a b)))

After that, we don't need TAB for any indenting purposes, and can
redefine it to something more useful (we redefined default key binding
for indent-region, as we don't need it that often):

(add-hook 'slime-mode-hook
	  (lambda ()
	    (local-set-key "\C-i" 'slime-complete-symbol)
	    (local-set-key "\C-\M-\\" 'indent-defun)))

So far so good - pressing TAB auto-completes all known symbols, and
makes typing code much easier (at least for me). Here is the questions
I have:

1. indent-defun looks terribly ugly for many reasons: a/ it is not LISPish -
more like a BASIC program directly translated into Lisp; I would like
to write something like

(defun indent-defun ()
  (interactive)
  (indent-region (beginning-of-defun) (end-of-defun)))

but I don't know which elisp function(s) to use. b/ it will not work with
defmacro, or with any other top-level form. I would like to have something
like (beginning-of-top-level-form) - again, I don't know if such beast
exists and my elisp skills are too weak yet to program it myself - any
suggestions?


= Renaming buffers =

I am playing with several lisp implementations - clisp, Allegro CL
Express and SBCL to be precise. I would like their slime buffers to
have names like *clisp*, *allegro* and *sbcl* instead of *slime-repl
sbcl* etc. I tried to rename these buffers:

(defun sbcl ()
  (interactive)
  (setq inferior-lisp-program "/usr/local/bin/sbcl")
  (slime)
  (rename-buffer "*sbcl*"))

but what happens is that buffer is renamed _before_ slime finishes
loading lisp, and after it finish, it renames the buffer back. Can I
attach a function to the moment when slime finish it's load process -
like defining hook for a major mode?

Best,
Victor.

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

* Re: Several questions on SLIME customizations
  2006-11-19  5:32 Several questions on SLIME customizations Victor Kryukov
@ 2006-11-20 19:42 ` Robert Thorpe
  2006-11-21  0:54   ` Victor Kryukov
  0 siblings, 1 reply; 3+ messages in thread
From: Robert Thorpe @ 2006-11-20 19:42 UTC (permalink / raw)


Victor Kryukov wrote:
> Hello list,
>
> I've a couple emacs customization/elisp questions, which are not very
> closely related, except that they have one unifying theme: making life
> under SLIME better (as I understand it). I would appreciate if you
> could answer at least some of them - and of course, feel free to share
> you strategies to customize SLIME!

Maybe best to ask on comp.lang.lisp, they use it a lot.

> = Redefining TAB. =
>
> I tried TextMate recently (yes, luckily I live under Mac OS X; no, I
> don't want to start another flame war), and I especially like how it
> treats TAB key - ok, ok, I know that their behaviour is risky because
> it's context-dependent, but vim users somehow manage to accomodate to
> multiple contexts ;).
>
> Anyway, TAB is too valuable key to spare, as it's very easy to type,
> and in my use case, I never need to use it _alone_: most often during
> editing I need to wrap a bunch of lines into let statement, say, so I
> need to indent a whole region anyway. Hence my strategy was like this:
>
> (global-set-key "\r" 'newline-and-indent)
>
> makes Return indent next line automatically, and the following function
> indents the whole defun:
>
> (defun indent-defun ()
>   (interactive)
>   (let (a b)
>     (beginning-of-defun)
>     (setq a (point))
>     (end-of-defun)
>     (setq b (point))
>     (indent-region a b)))
>
> After that, we don't need TAB for any indenting purposes, and can
> redefine it to something more useful (we redefined default key binding
> for indent-region, as we don't need it that often):
>
> (add-hook 'slime-mode-hook
> 	  (lambda ()
> 	    (local-set-key "\C-i" 'slime-complete-symbol)
> 	    (local-set-key "\C-\M-\\" 'indent-defun)))

That's quite a good idea.

> So far so good - pressing TAB auto-completes all known symbols, and
> makes typing code much easier (at least for me). Here is the questions
> I have:
>
> 1. indent-defun looks terribly ugly for many reasons: a/ it is not LISPish -
> more like a BASIC program directly translated into Lisp;

I wouldn't worry about that.

> I would like
> to write something like
>
> (defun indent-defun ()
>   (interactive)
>   (indent-region (beginning-of-defun) (end-of-defun)))
>
> but I don't know which elisp function(s) to use.

The ones you've used are fine.  The reason you are encountering this
problem is because emacs does not record the positions of
beginning-of-defun etc, it discovers them each time.  It may be argued
that this is bad design.

If you want a more functional version of beginning-of-defun you'll have
to write it yourself.  You can do this by wrapping (beginning-of-defun)
(setq a (point)) in a function.

Note, you could also do what you have done by using push-mark but your
way is fine, maybe better.

> b/ it will not work with
> defmacro, or with any other top-level form. I would like to have something
> like (beginning-of-top-level-form) - again, I don't know if such beast
> exists

It doesn't.  The code for this stuff is in /emacs-lisp/lisp.el BTW

> and my elisp skills are too weak yet to program it myself - any
> suggestions?

Beginning-of-defun means that in the most broadest sense, it works with
other forms like defmacro.

> = Renaming buffers =
>
> I am playing with several lisp implementations - clisp, Allegro CL
> Express and SBCL to be precise. I would like their slime buffers to
> have names like *clisp*, *allegro* and *sbcl* instead of *slime-repl
> sbcl* etc. I tried to rename these buffers:
>
> (defun sbcl ()
>   (interactive)
>   (setq inferior-lisp-program "/usr/local/bin/sbcl")
>   (slime)
>   (rename-buffer "*sbcl*"))
>
> but what happens is that buffer is renamed _before_ slime finishes
> loading lisp, and after it finish, it renames the buffer back. Can I
> attach a function to the moment when slime finish it's load process -
> like defining hook for a major mode?

Probably, don't know.  Code like the above very rarely works.  Normally
when a big internal Emacs feature is invoked it makes it's own buffers.
 People on comp.lang.lisp might know the right hook.

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

* Re: Several questions on SLIME customizations
  2006-11-20 19:42 ` Robert Thorpe
@ 2006-11-21  0:54   ` Victor Kryukov
  0 siblings, 0 replies; 3+ messages in thread
From: Victor Kryukov @ 2006-11-21  0:54 UTC (permalink / raw)


"Robert Thorpe" <rthorpe@realworldtech.com> writes:

Robert - thanks for your answers.

>> b/ it will not work with
>> defmacro, or with any other top-level form. I would like to have something
>> like (beginning-of-top-level-form) - again, I don't know if such beast
>> exists
>
> Beginning-of-defun means that in the most broadest sense, it works with
> other forms like defmacro.

Indeed, you're right - beginning-of-defun function works with _any_
top-level form, not only with defun.

>> loading lisp, and after it finish, it renames the buffer back. Can I
>> attach a function to the moment when slime finish it's load process -
>> like defining hook for a major mode?
>
> Probably, don't know.  Code like the above very rarely works.  Normally
> when a big internal Emacs feature is invoked it makes it's own buffers.
>  People on comp.lang.lisp might know the right hook.

OK, will do that.

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

end of thread, other threads:[~2006-11-21  0:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-11-19  5:32 Several questions on SLIME customizations Victor Kryukov
2006-11-20 19:42 ` Robert Thorpe
2006-11-21  0:54   ` Victor Kryukov

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.