help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Autoindentation in all modes


From: Daimrod
Subject: Re: Autoindentation in all modes
Date: Wed, 28 Mar 2012 19:29:58 -0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.92 (gnu/linux)

Alexander Stepanov <darkdrip@gmail.com> writes:

> On Dec 25, 6:38 pm, rocky...@163.com-NOSPAM ("Rocky Zhang") wrote:
>> Alexander Stepanov <darkd...@gmail.com> writes:
>> > On Dec 25, 4:24 pm, rocky...@163.com-NOSPAM ("Rocky Zhang") wrote:
>> >> Alexander Stepanov <darkd...@gmail.com> writes:
>> >> > Is it possible to rewrite this ugly code in my ~/.emacs? What is the
>> >> > good way to do the %subject%?
>>
>> >> > (add-hook 'c-mode-common-hook '(lambda ()
>> >> >   (local-set-key (kbd "RET") 'newline-and-indent)))
>> >> > (add-hook 'ruby-mode-hook '(lambda ()
>> >> >   (local-set-key (kbd "RET") 'newline-and-indent)))
>> >> > (add-hook 'python-mode-hook '(lambda ()
>> >> >   (local-set-key (kbd "RET") 'newline-and-indent)))
>> >> > (add-hook 'java-mode-hook '(lambda ()
>> >> >   (local-set-key (kbd "RET") 'newline-and-indent)))
>> >> > (add-hook 'css-mode-hook '(lambda ()
>> >> >   (local-set-key (kbd "RET") 'newline-and-indent)))
>> >> > (add-hook 'xml-mode-hook '(lambda ()
>> >> >   (local-set-key (kbd "RET") 'newline-and-
>> >> > indent)))
>> >> > (add-hook 'html-mode-hook '(lambda ()
>> >> >   (local-set-key (kbd "RET") 'newline-and-indent)))
>>
>> >> You can use the `dolist' function to do the same works:
>>
>> >> (dolist (all-the-mode '(c-mode-common-hook
>> >>                         ruby-mode-hook
>> >>                         python-mode-hook
>> >>                         java-mode-hook
>> >>                         css-mode-hook
>> >>                         xml-mode-hook))
>> >>          (add-hook all-the-mode '(lambda ()
>> >>            (local-set-key (kbd "RET") 'newline-and-indent))))
>>
>> >> --
>> >> Rocky Zhang
>>
>> >> --- Posted via news://freenews.netfront.net/ - Complaints to 
>> >> n...@netfront.net ---
>>
>> > That's cool. But I still should write all the modes in this
>> > construction. Is it possible to turn on autoindentation for all modes
>> > by writing one line in config? I am surprised to realize that
>> > autoindentation is not turn on in Emacs by default.
>>
>> Do you mean that `global-set-key'?
>>
>> (global-set-key (kbd "RET") 'newline-and-indent)
>>
>> --
>> Rocky Zhang
>>
>> --- Posted via news://freenews.netfront.net/ - Complaints to 
>> n...@netfront.net ---
>
> Yes. I want to use something like that. But it doesn't work in ruby-
> mode.

Why don't you use C-j ?
It think most modes if not any bound it to the correct function to
indent and add a newline.

i.e.
in c-mode -> newline-and-indent
in ruby-mode -> reindent-then-newline-and-indent
etc...

A workaround could be to look at the function bound to C-j and set it to RET.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]