unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Textmate like code block alignment (ruby-mode)
@ 2010-07-06 16:51 Marcelo de Moraes Serpa
  2010-07-06 17:01 ` Deniz Dogan
  0 siblings, 1 reply; 4+ messages in thread
From: Marcelo de Moraes Serpa @ 2010-07-06 16:51 UTC (permalink / raw)
  To: help-gnu-emacs

Hey list,

I have ruby-mode setup and it works pretty well. One thing though is
that it doesn't automatically align blocks, and I have to type C-a TAB
to make it align the end with a def for example:

def func <when I press ENTER here>
      |<the pointer goes here>

I'd like it to behave like Textmate, where when you press enter after
the beginning of a code block, it automatically aligns the end to like
so:

def func <when I press ENTER here>
|<the cursor goes here, where it should be>

It's really annoying having to align manually.

Any ideas?

Thanks in advance,

Marcelo.



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

* Re: Textmate like code block alignment (ruby-mode)
  2010-07-06 16:51 Textmate like code block alignment (ruby-mode) Marcelo de Moraes Serpa
@ 2010-07-06 17:01 ` Deniz Dogan
  2010-07-06 17:05   ` Marcelo de Moraes Serpa
  0 siblings, 1 reply; 4+ messages in thread
From: Deniz Dogan @ 2010-07-06 17:01 UTC (permalink / raw)
  To: Marcelo de Moraes Serpa; +Cc: help-gnu-emacs

2010/7/6 Marcelo de Moraes Serpa <celoserpa@gmail.com>:
> Hey list,
>
> I have ruby-mode setup and it works pretty well. One thing though is
> that it doesn't automatically align blocks, and I have to type C-a TAB
> to make it align the end with a def for example:
>
> def func <when I press ENTER here>
>      |<the pointer goes here>
>
> I'd like it to behave like Textmate, where when you press enter after
> the beginning of a code block, it automatically aligns the end to like
> so:
>
> def func <when I press ENTER here>
> |<the cursor goes here, where it should be>
>
> It's really annoying having to align manually.
>
> Any ideas?
>
> Thanks in advance,
>
> Marcelo.
>
>

You could try binding RET to newline-and-indent (bound to C-j by default).

Try something like this (untested):

(add-hook 'ruby-mode-hook
  (lambda ()
    (define-key ruby-mode-map (kbd "RET") 'newline-and-indent)))

By the way, you normally don't have to move the cursor anywhere to
indent the current line. Just hit TAB with the cursor anywhere on the
line you wish to indent "correctly" and it will work just as well.

-- 
Deniz Dogan



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

* Re: Textmate like code block alignment (ruby-mode)
  2010-07-06 17:01 ` Deniz Dogan
@ 2010-07-06 17:05   ` Marcelo de Moraes Serpa
  2010-07-06 23:27     ` Lennart Borgman
  0 siblings, 1 reply; 4+ messages in thread
From: Marcelo de Moraes Serpa @ 2010-07-06 17:05 UTC (permalink / raw)
  To: Deniz Dogan; +Cc: help-gnu-emacs

Hi Deniz,

Thanks for being so helpful ;)

Well, my config has snippets attached to TAB too, so if I hit TAB, it
will try to complete "end". I'm using a fork of emacs-starter-kit,
and, although I have modified it a lot already, I didn't have the time
to peek into it the way I wanted so as to understand how things are
wired up, I'll need to to that eventually.

Anyway, thanks for the suggestion. Using C-j already had this
behaviour built-in btw,

Marcelo.

On Tue, Jul 6, 2010 at 12:01 PM, Deniz Dogan <deniz.a.m.dogan@gmail.com> wrote:
> 2010/7/6 Marcelo de Moraes Serpa <celoserpa@gmail.com>:
>> Hey list,
>>
>> I have ruby-mode setup and it works pretty well. One thing though is
>> that it doesn't automatically align blocks, and I have to type C-a TAB
>> to make it align the end with a def for example:
>>
>> def func <when I press ENTER here>
>>      |<the pointer goes here>
>>
>> I'd like it to behave like Textmate, where when you press enter after
>> the beginning of a code block, it automatically aligns the end to like
>> so:
>>
>> def func <when I press ENTER here>
>> |<the cursor goes here, where it should be>
>>
>> It's really annoying having to align manually.
>>
>> Any ideas?
>>
>> Thanks in advance,
>>
>> Marcelo.
>>
>>
>
> You could try binding RET to newline-and-indent (bound to C-j by default).
>
> Try something like this (untested):
>
> (add-hook 'ruby-mode-hook
>  (lambda ()
>    (define-key ruby-mode-map (kbd "RET") 'newline-and-indent)))
>
> By the way, you normally don't have to move the cursor anywhere to
> indent the current line. Just hit TAB with the cursor anywhere on the
> line you wish to indent "correctly" and it will work just as well.
>
> --
> Deniz Dogan
>



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

* Re: Textmate like code block alignment (ruby-mode)
  2010-07-06 17:05   ` Marcelo de Moraes Serpa
@ 2010-07-06 23:27     ` Lennart Borgman
  0 siblings, 0 replies; 4+ messages in thread
From: Lennart Borgman @ 2010-07-06 23:27 UTC (permalink / raw)
  To: Marcelo de Moraes Serpa; +Cc: help-gnu-emacs

You could try tabkey2 or smart-tab to get both indentation and
snippets, see http://www.emacswiki.org/emacs/TabCompletion


On Tue, Jul 6, 2010 at 7:05 PM, Marcelo de Moraes Serpa
<celoserpa@gmail.com> wrote:
> Hi Deniz,
>
> Thanks for being so helpful ;)
>
> Well, my config has snippets attached to TAB too, so if I hit TAB, it
> will try to complete "end". I'm using a fork of emacs-starter-kit,
> and, although I have modified it a lot already, I didn't have the time
> to peek into it the way I wanted so as to understand how things are
> wired up, I'll need to to that eventually.
>
> Anyway, thanks for the suggestion. Using C-j already had this
> behaviour built-in btw,
>
> Marcelo.
>
> On Tue, Jul 6, 2010 at 12:01 PM, Deniz Dogan <deniz.a.m.dogan@gmail.com> wrote:
>> 2010/7/6 Marcelo de Moraes Serpa <celoserpa@gmail.com>:
>>> Hey list,
>>>
>>> I have ruby-mode setup and it works pretty well. One thing though is
>>> that it doesn't automatically align blocks, and I have to type C-a TAB
>>> to make it align the end with a def for example:
>>>
>>> def func <when I press ENTER here>
>>>      |<the pointer goes here>
>>>
>>> I'd like it to behave like Textmate, where when you press enter after
>>> the beginning of a code block, it automatically aligns the end to like
>>> so:
>>>
>>> def func <when I press ENTER here>
>>> |<the cursor goes here, where it should be>
>>>
>>> It's really annoying having to align manually.
>>>
>>> Any ideas?
>>>
>>> Thanks in advance,
>>>
>>> Marcelo.
>>>
>>>
>>
>> You could try binding RET to newline-and-indent (bound to C-j by default).
>>
>> Try something like this (untested):
>>
>> (add-hook 'ruby-mode-hook
>>  (lambda ()
>>    (define-key ruby-mode-map (kbd "RET") 'newline-and-indent)))
>>
>> By the way, you normally don't have to move the cursor anywhere to
>> indent the current line. Just hit TAB with the cursor anywhere on the
>> line you wish to indent "correctly" and it will work just as well.
>>
>> --
>> Deniz Dogan
>>
>
>



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

end of thread, other threads:[~2010-07-06 23:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-07-06 16:51 Textmate like code block alignment (ruby-mode) Marcelo de Moraes Serpa
2010-07-06 17:01 ` Deniz Dogan
2010-07-06 17:05   ` Marcelo de Moraes Serpa
2010-07-06 23:27     ` Lennart Borgman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).