From: Robert Pluim <rpluim@gmail.com>
To: Vas Vas <whiterocket@outlook.com>
Cc: "help-gnu-emacs@gnu.org" <help-gnu-emacs@gnu.org>
Subject: Re: Newline and copy above line's indentation
Date: Tue, 03 Jul 2018 16:21:07 +0200 [thread overview]
Message-ID: <87muv8qu24.fsf@gmail.com> (raw)
In-Reply-To: <DB7P194MB0316D9BA372E9E0FCFFDDE3BBF420@DB7P194MB0316.EURP194.PROD.OUTLOOK.COM> (Vas Vas's message of "Tue, 3 Jul 2018 12:40:22 +0000")
Vas Vas <whiterocket@outlook.com> writes:
> Hello, I've been using emacs since last November, migrating from
> vim. Something I've missed is the indentation behaviour, specifically
> newline copying the above line's indentation without any
> syntax-awareness. I understand emacs' indentation is much more
> powerful, but it's easier customising emacs than changing habits. The
> hack I've ended up with is:
>
> (defun copy-whitespace-above-and-indent()
> (interactive)
> (setq old-point (point))
> (previous-line)
> (beginning-of-line)
> (setq start (point))
> (beginning-of-line-text)
> (setq end (point))
> (goto-char old-point)
> (newline)
> (insert (buffer-substring start end)))
>
> I was wondering if there's a more elegant solution to this, such as by
> using emacs' existing indentation mechanisms, or by a cleaner
> implementation of that function.
Both are true, I think. Which mode(s) did you want this to work in?
Most modes already do this kind of thing automatically when you hit
RET, perhaps you have customizations that are preventing that from
working.
Robert
next prev parent reply other threads:[~2018-07-03 14:21 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-03 12:40 Newline and copy above line's indentation Vas Vas
2018-07-03 14:21 ` Robert Pluim [this message]
2018-07-03 18:59 ` Eli Zaretskii
[not found] <mailman.3005.1530624947.1292.help-gnu-emacs@gnu.org>
2018-07-03 14:03 ` Emanuel Berg
2018-07-03 14:37 ` Emanuel Berg
2018-07-03 14:49 ` Robert Pluim
[not found] ` <mailman.3009.1530629379.1292.help-gnu-emacs@gnu.org>
2018-07-03 14:56 ` Emanuel Berg
2018-07-03 15:23 ` Robert Pluim
[not found] ` <mailman.3013.1530631400.1292.help-gnu-emacs@gnu.org>
2018-07-03 17:44 ` Emanuel Berg
2018-07-03 16:03 ` HASM
2018-07-03 17:45 ` Emanuel Berg
2018-07-03 21:07 ` HASM
2018-07-03 21:39 ` Emanuel Berg
2018-07-03 22:16 ` HASM
2018-07-04 0:25 ` Dan Espen
2018-07-04 0:58 ` HASM
2018-07-04 13:45 ` Dan Espen
2018-07-04 15:26 ` HASM
2018-07-23 23:32 ` 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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87muv8qu24.fsf@gmail.com \
--to=rpluim@gmail.com \
--cc=help-gnu-emacs@gnu.org \
--cc=whiterocket@outlook.com \
/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.
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).