Question about emacs indentation

Hi, Konstantin!

Konstantin Levinski wrote:

I think I can help with explanation of why emacs behaves as it does,
and maybe you'd agree that it makes sense.

Now I understand it.
But it's hard to change habit.
Do you think the emacs way is better?

<tab> in emacs/ruby means (ruby-indent-command), which parses vicinity
of cursor and figures out correct identation. that is, it is not "add a
tab" but "format this line".
so to get desired result, you could just use 'end<tab>'
or call (indent-region) - Ctl-Alt-\ - to indent the whole thing in one
go later.

This way you dont need to care about formatting at all, it's done
correctly automatically.

How can I keep tabs instead of spaces?

Thanks.

Sam

"Sam Kong" <sam.s.kong@gmail.com> writes:

Hi, Konstantin!

Konstantin Levinski wrote:

I think I can help with explanation of why emacs behaves as it does,
and maybe you'd agree that it makes sense.

Now I understand it.
But it's hard to change habit.
Do you think the emacs way is better?

I got used to using C-j instead of RETs and TABs. Give it a bash.

<tab> in emacs/ruby means (ruby-indent-command), which parses vicinity
of cursor and figures out correct identation. that is, it is not "add a
tab" but "format this line".
so to get desired result, you could just use 'end<tab>'
or call (indent-region) - Ctl-Alt-\ - to indent the whole thing in one
go later.

This way you dont need to care about formatting at all, it's done
correctly automatically.

How can I keep tabs instead of spaces?

For all modes by default:

  (set-default 'indent-tabs-mode t)

For just ruby-mode:

  (add-hook 'ruby-mode-hook (lambda () (setq indent-tabs-mode t)))

well, I think emacs way of autoformatting instead of 'fixed identation
levels' is better, as it is _automates_ things. (and does not get in
the way in the process /well, most of the time/ )
you can bind 'ruby-reindent-then-newline-and-indent to enter (as was
already proposed) and forget about formatting forever.

George Ogata wrote:

I got used to using C-j instead of RETs and TABs. Give it a bash.

Eugh, my pinky finger hurts enough from coding on a German keyboard from reaching to AltGr all the time, reaching for Ctrl for each newline would definately give me CTS :stuck_out_tongue_winking_eye: You can always hack ruby-mode.el and map RUBY-REINDENT-NEWLINE-AND-INDENT (word order subject to change) to RET - I managed even as an utter elisp newbie. Works like a charm.

David Vallner

David Vallner <david@vallner.net> writes:

George Ogata wrote:

I got used to using C-j instead of RETs and TABs. Give it a bash.

Eugh, my pinky finger hurts enough from coding on a German keyboard from
reaching to AltGr all the time, reaching for Ctrl for each newline would
definately give me CTS :stuck_out_tongue_winking_eye: You can always hack ruby-mode.el and map
RUBY-REINDENT-NEWLINE-AND-INDENT (word order subject to change) to RET -
I managed even as an utter elisp newbie. Works like a charm.

Heh. I'm surprised you'd put up with emacs at all if the control-key
proliferosity bothered you that much. I C-[fbpnaejod...] so often it
feels quite natural.

But you don't need to hack ruby-mode.el; just hook it in:

(add-hook 'ruby-mode-hook
  (lambda ()
    (define-key ruby-mode-map [return]
      'ruby-reindent-then-newline-and-indent)))