From: Yuri Khan <yuri.v.khan@gmail.com>
To: Michael Heerdegen <michael_heerdegen@web.de>
Cc: "help-gnu-emacs@gnu.org" <help-gnu-emacs@gnu.org>
Subject: Re: auto indenting code blocks
Date: Sat, 13 Jun 2015 19:14:38 +0600 [thread overview]
Message-ID: <CAP_d_8WsBbk3b6BhUtg6LgsttPzgq5AjtNBoGAXVkLH3+umNmg@mail.gmail.com> (raw)
In-Reply-To: <87616rlt63.fsf@web.de>
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.
next prev parent reply other threads:[~2015-06-13 13:14 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-13 10:40 auto indenting code blocks Sam Halliday
2015-06-13 11:25 ` Yuri Khan
2015-06-13 11:55 ` Michael Heerdegen
2015-06-13 13:14 ` Yuri Khan [this message]
2015-06-13 23:30 ` Michael Heerdegen
2015-06-14 5:24 ` Yuri Khan
[not found] ` <mailman.4973.1434259496.904.help-gnu-emacs@gnu.org>
2015-06-14 19:54 ` Sam Halliday
2015-06-14 19:59 ` Stefan Monnier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAP_d_8WsBbk3b6BhUtg6LgsttPzgq5AjtNBoGAXVkLH3+umNmg@mail.gmail.com \
--to=yuri.v.khan@gmail.com \
--cc=help-gnu-emacs@gnu.org \
--cc=michael_heerdegen@web.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.