[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: auto indenting code blocks
From: |
Yuri Khan |
Subject: |
Re: auto indenting code blocks |
Date: |
Sat, 13 Jun 2015 19:14:38 +0600 |
On Sat, Jun 13, 2015 at 5:55 PM, Michael Heerdegen
<michael_heerdegen@web.de> wrote:
> Shouldn't `electric-indent-mode' be able to do this?
Maybe it should, but it does not for me.
$ emacs --version
GNU Emacs 24.4.1
[…]
$ emacs -Q
M-: (add-to-list 'load-path "~/.emacs.d/dash.el")
;; as of github:magnars/dash.el tag 2.10.0
M-: (add-to-list 'load-path "~/.emacs.d/smartparens")
;; as of github:Fuco1/smartparens.git commit 8d22a6b
M-x load-library
smartparens-config
M-x smartparens-global-mode
M-x load-library
cc-mode
M-: (setq c-default-style '((java-mode . "java") (awk-mode . "awk")
(other . "stroustrup")))
C-x C-f ~/test.cpp
;; where the file does not exist
Now I start typing:
===
int main(|
===
As soon as I type the opening parenthesis, smartparens adds a matching
closing parenthesis after the point:
===
int main(|)
===
I press End to get out of parentheses and then press Enter to start a new line:
===
int main()
|
===
I press “{”. smartparens adds a matching closing brace.
electric-indent-mode unindents the newly inserted pair of braces to
the level of “int”:
===
int main()
{|}
===
(1)
I press Enter. Nothing special happens:
===
int main()
{
|}
===
(2)
I press Enter again. Nothing special happens again:
===
int main()
{
|}
===
The behavior does not change if I use Ctrl+J instead of Enter.
If at point (2) I go to the end of the line with the opening brace and
press Enter, or if at point (1) I press Ctrl+O and then Enter, then I
get the desired function skeleton:
===
int main()
{
|
}
===
But those are not key sequences I’d like to repeat every time.
If I forgo smartparens, then electric-indent-mode does indeed yield
the desired sequence:
===
int main()|
===
Enter
===
int main()
|
===
Opening brace
===
int main()
{|
===
Enter
===
int main()
{
|
===
Some text
===
int main()
{
std::cout << "Hello World\n";|
===
Enter
===
int main()
{
std::cout << "Hello World\n";
|
===
Closing brace
===
int main()
{
std::cout << "Hello World\n";
}|
===
However, smartparens is too convenient to give up.