From: nuxdoors@cegetel.net
To: bug-gnu-emacs@gnu.org
Subject: Re: reindent-then-newline-and-indent doesn't indent properly in emacs 22.1
Date: Sun, 14 Oct 2007 14:46:41 +0200 [thread overview]
Message-ID: <47120FB1.4000007@cegetel.net> (raw)
In-Reply-To: <470FFCF1.5050201@cegetel.net>
> The problem with this is that the first `indent-according-to-mode' may
> insert whitespace at the end of an otherwise empty line. Try to invoke
> your function at the beginning of a non-empty line.
I take care of this in this new function by deleting spaces after
indenting the line around the point of initial breakage. I expect it has
now the same behaviour as before except for the minor bug. Please test.
I completed the doc string with a note one the automatic trailing space
deleting. Shouldn't that be stated or is it too obvious ?
(defun reindent-then-newline-and-indent ()
"Reindent current line, insert newline deleting trailing spaces or tabs,
then indent the new line.
Indentation of both lines is done according to the current major mode,
which means calling the current value of `indent-line-function'.
In programming language modes, this is the same as TAB.
In some text modes, where TAB inserts a tab, this indents to the
column specified by the function `current-left-margin'."
(interactive "*")
(let ((pos (point)))
;; Be careful to insert the newline before indenting the line.
;; Otherwise, the indentation might be wrong.
(newline)
(save-excursion
(goto-char pos)
;; Beware of indentation functions which move point.
(save-excursion
(indent-according-to-mode))
;; Delete all trailing spaces or tabs introduced by the newline
command
;; or the new indentation. 0 is for no space.
(just-one-space 0))
(indent-according-to-mode)))
-----------------------------------------
--- lisp/simple.el.orig 2007-05-27 16:35:51.000000000 +0200
+++ lisp/simple.el 2007-10-14 14:38:20.000000000 +0200
@@ -618,7 +618,8 @@
(indent-according-to-mode))
(defun reindent-then-newline-and-indent ()
- "Reindent current line, insert newline, then indent the new line.
+ "Reindent current line, insert newline deleting trailing spaces or tabs,
+then indent the new line.
Indentation of both lines is done according to the current major mode,
which means calling the current value of `indent-line-function'.
In programming language modes, this is the same as TAB.
@@ -631,8 +632,12 @@
(newline)
(save-excursion
(goto-char pos)
- (indent-according-to-mode)
- (delete-horizontal-space t))
+ ;; Beware of indentation functions which move point.
+ (save-excursion
+ (indent-according-to-mode))
+ ;; Delete all trailing spaces or tabs introduced by the newline
command
+ ;; or the new indentation.
+ (just-one-space 0))
(indent-according-to-mode)))
(defun quoted-insert (arg)
next prev parent reply other threads:[~2007-10-14 12:46 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-10-12 23:02 reindent-then-newline-and-indent doesn't indent properly in emacs 22.1 nuxdoors
2007-10-13 8:40 ` martin rudalics
2007-10-13 22:24 ` nuxdoors
2007-10-14 13:23 ` nuxdoors
2007-10-14 18:26 ` martin rudalics
2007-10-15 1:37 ` Richard Stallman
2007-10-16 0:07 ` nuxdoors
2007-10-16 19:09 ` Richard Stallman
2007-10-16 20:39 ` nuxdoors
[not found] ` <E1Ii13p-0002HF-Q4@fencepost.gnu.org>
2007-10-19 1:07 ` nuxdoors
[not found] ` <mailman.2040.1192368226.18990.bug-gnu-emacs@gnu.org>
2007-10-14 19:48 ` Stefan Monnier
2007-10-16 15:19 ` Stefan Monnier
2007-10-14 12:46 ` nuxdoors [this message]
2007-10-15 1:37 ` Richard Stallman
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=47120FB1.4000007@cegetel.net \
--to=nuxdoors@cegetel.net \
--cc=bug-gnu-emacs@gnu.org \
/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.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
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).