From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Emanuel Berg Newsgroups: gmane.emacs.help Subject: Re: Newline and copy above line's indentation Date: Tue, 03 Jul 2018 16:03:34 +0200 Organization: Aioe.org NNTP Server Message-ID: <86y3esh0w9.fsf@zoho.com> References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1530626611 15136 195.159.176.226 (3 Jul 2018 14:03:31 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 3 Jul 2018 14:03:31 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Jul 03 16:03:27 2018 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1faLtu-0003oj-Sh for geh-help-gnu-emacs@m.gmane.org; Tue, 03 Jul 2018 16:03:27 +0200 Original-Received: from localhost ([::1]:40722 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1faLw2-0005TW-80 for geh-help-gnu-emacs@m.gmane.org; Tue, 03 Jul 2018 10:05:38 -0400 Original-Path: usenet.stanford.edu!goblin2!goblin.stu.neva.ru!aioe.org!.POSTED!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 64 Original-NNTP-Posting-Host: cRcuMnzjCdtBkcQq4LWXQQ.user.gioia.aioe.org Original-X-Complaints-To: abuse@aioe.org Cancel-Lock: sha1:YExl80xrS8rZVwGvS4Xb/f3Ydw8= Mail-Copies-To: never X-Notice: Filtered by postfilter v. 0.8.3 Original-Xref: usenet.stanford.edu gnu.emacs.help:223200 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:117323 Archived-At: 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