Shlomi Fish <[EMAIL PROTECTED]> writes:

> I read the tutorial, but it could only help me so far. Why when I type
> "enter" does the cursor move to the beginning of the line, and wait for me
> to press tab to indent itself properly? Maybe I'm too fixed on gvim, but
> it seems to make perfect sense to me. 

In some modes, but not necessarily the others. And in any case, it's
just a matter of different defaults. Let me give you a mini-tutorial
on how to find things out in XEmacs.

If you hit "C-h k RET" to find out what "enter" does, you'll find it
invokes a function called newline. You want to indent, so a reasonable
next step is "C-h a indent" which gives you a long list of
indentation-related functions and variables. If you have a bit of
spare time, you might want to explore some of those (by clicking the
middle button - have you noticed how the items are highlighted when
you move the cursor? - or by hitting enter). If not, you might look
for the word newline (you want indentation on newline, right?) - note
that you can search the buffer in the usual emacs way (described in
the tutorial) - "C-s newline"

Of course, you could have been more sophisticated with "C-h a
newline.*indent" from the start...

In any case, by this time you will see that there is a function called
newline-and-indent, globally bound to linefeed, C-j.

Now you may want to redefine the RET ("enter" - you have got used to
the jargon by now, haven't you?) key rather than use C-j all the
time. Actually, you might want to exchange the two. The crude way to
do it is (UNTESTED)

(global-set-key [(return)] 'newline-and-indent)
(global-set-key "\C-j" 'newline)

(put it as is in ~/.emacs) but that's what it says - global, will do
it always! A somewhat subtler approach will require a bit of elisp
(Nadav's next step), with something like

(defun my-return (mode-map)
  (define-key mode-map [(return)] 'newline-and-indent)
  (define-key mode-map "\C-j" 'newline))

Now, if you want to include this in, say, c-mode, you can do

(defun my-c-keymap ()
  (my-return c-mode-map))

(add-hook 'c-mode-common-hook 'my-c-keymap)

(you are by now quite capable of doing "C-h v c-mode-common-hook" all
by yourself to find out what it is, right?), et voila!

The level of abstraction in the code above is a bit more than really
needed for this explanation, but is deliberate: you can put more
keymap configurations and other stuff in my-c-keymap, and my-return is
a nice little abstraction for auto-indenting in different modes.

That's the way to progress. It is a bit of a learning curve, to be
sure, but once you get the knack of it it becomes easy and fun.

As a final comment - I am absolutely unfamiliar with the (very rich)
menus of XEmacs, but I would not be surprized if the option that you
are looking for is hiding somewhere there or in customization buffers.

And as a really final comment - I won't be offended if you don't
appreciate the effort Nadav and myself invested into saving your soul
and stick to gvim. ;-)

-- 
Oleg Goldshmidt | [EMAIL PROTECTED] 
If it aint't broken it hasn't got enough features yet.

=================================================================
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]

Reply via email to