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

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

Newline and copy above line's indentation


From: Vas Vas
Subject: Newline and copy above line's indentation
Date: Tue, 3 Jul 2018 12:40:22 +0000

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.



reply via email to

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