[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Newline and copy above line's indentation
From: |
Emanuel Berg |
Subject: |
Re: Newline and copy above line's indentation |
Date: |
Tue, 03 Jul 2018 16:03:34 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) |
Vas Vas wrote:
> 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:
The particular indentation system is a function
of the mode of the buffer you're in, so step
one is to have the right mode. This should
happen automatically, of course, but make sure
it is right anyway. Because sometimes because
of (mis)configuration and/or very exotic
files/languages it doesn't happen.
If you still feel something is missing please
provide me/us with an exact example of the
above line and what should happen on the line
below. That'll make it easier for us to help.
> (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)))
Some style issues:
1. Instead of storing "old-point" and then
using `goto-char', use `save-excursion' (see
the help for that function:
C-h f save-excursion RET).
2. Instead of `setq', use `let'.
3. Instead of `previous-line', use
`forward-line' with a negative argument.
Find out about points 2 and 3 by byte-compiling
the source:
$ emacs -batch -f byte-compile source.el
See
M-x man emacs RET
or emacs(1) - and ask again if you don't get it
to work, because it is very helpful.
--
underground experts united
http://user.it.uu.se/~embe8573
Re: Newline and copy above line's indentation, HASM, 2018/07/03