[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Newline and copy above line's indentation
From: |
Robert Pluim |
Subject: |
Re: Newline and copy above line's indentation |
Date: |
Tue, 03 Jul 2018 16:21:07 +0200 |
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
Re: Newline and copy above line's indentation, HASM, 2018/07/03