From: Kent M Pitman
Subject: Re: Newbie editor question
Date: 
Message-ID: <sfw4rakyrvr.fsf@shell01.TheWorld.com>
Chris Gehlker <·······@fastq.com> writes:

> My situation is that I'm having fun learning Lisp but I can't seem to find
> great tools. I'm running CLISP as an inferior lisp under emacs on Jaguar. I
> set up my .emacs file as shown in the editors.txt file that came with CLISP.
> This works when I'm typing in code but when I go back and edit previous
> lines emacs doesn't reflow the lines following the edit point. I keep thing
> there is some key binding to re-format the whole buffer but I can't seem to
> find it. It's kind of a drag to being trying to learn a new language and to
> have to spend time learning a new editor.

Well, in no case do I recomend reformatting a whole buffer, especially
one that contains not just code but program output, as in a transcript
window of a Lisp session. There isn't enough semantic marking for the
program doing the reformatting to have much of a prayer of getting the
reformatting correct.  A buffer of straight code (such as a .lisp
file) could, in principle, be reformatted safely, but then such files
are usually constructed by hand and usually have correct formatting to
start with, so again a mechanical reformatting is not needed.

I'm not sure what you mean by "reflow".  I'm guessing you mean to apply
auto-fill rules to the subsequent text. Vanilla auto-fill mode rarely
gives very good effect when editing Lisp expressions, nor in fact
expressions in any expression-oriented language.  Even in modes where it
has some effect at all, it usually gives you stuff that looks like
  (cond ((zerop x) 1) (t (* x (factorial (- x
                                            1)))))
rather than
  (cond ((zerop x) 1) 
        (t (* x (factorial (- x 1)))))
because it usually moves a minimum of text over the line break.
In some languages, of course, there is no indentation issue like there is
in Lisp.  Fortran is such a language.  If you just want code that looks boxy
like Fortran that thinks of every operation as a single line and continues
it "boxily" onto the start of the next line, auto-fill technology is your
"tool of choice". e.g.,

      X=SQRT(3.1415926535*Y+3.1416*Z+M)+ALPHA+EPSI
     1LON+2.7*GAMMA

could be handled by pretty minimal fussing with the auto-fill code.
Otherwise, if this is not what you want, and you'd like more intelligent
line-breaking, you have to inject some human smarts into the process as I
have traditionally understood emacs (i.e., I use emacs all the time myself
but I haven't looked at the internals of this particular stuff in years).

I don't think there is any emacs support for re-formatting expressions
where emacs will choose alternate line-breaks than the ones you have
chosen, so you need to, at minimum, use return or linefeed (linefeed
is like return + tab) to break the lines).  Then having done this, you
can repair the indentation of the current line with tab.  If the
expression in front of the cursor is multi-line and pressing tab
leaves the run-on lines mis-indented, use c-m-q to fix those once
you've set the start line of the expression in the position you want
using tab.

Btw, I recommend not "going back and editing previous lines" while you are
learning the language.  This will mean you no longer have a true transcript
of what happened and will allow you to confuse yourself.  I recommend you
instead use copy+paste operations to copy the expression to a new line and
edit a fresh copy, leaving the transcript intact.  This is a small detail,
but I think an important one to have in mind.  And it may even be less 
expedient than editing in-place.  But hopefully you can see the potential
confusion I'm trying to save you from and can make an intelligent decision
about the issue now that I've raised it.

Hope this helps.