GNU bug report logs -
#17449
24.4.50; Empty lines confuse electric-indent-post-self-insert-function.
Previous Next
Reported by: Philipp Rumpf <prumpf <at> gmail.com>
Date: Fri, 9 May 2014 15:43:02 UTC
Severity: normal
Found in version 24.4.50
Done: Stefan Monnier <monnier <at> iro.umontreal.ca>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 17449 in the body.
You can then email your comments to 17449 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#17449
; Package
emacs
.
(Fri, 09 May 2014 15:43:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Philipp Rumpf <prumpf <at> gmail.com>
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Fri, 09 May 2014 15:43:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
In C mode and Python mode, hitting <RET> on an indented but otherwise
empty line results in an unindented new line at point, rather than an
indented line.
To reproduce in emacs -Q:
M-x python-mode<RET>
if a == 3:<RET>
<RET>
M-: (current-column)<RET>
Expected result: 4 / indented line
Actual result: 0 / line not indented
Emacs 24.3.1 produces the expected result.
Lossage:
M-x p y t h o n - m o d e <return> i f SPC a SPC =
= SPC 3 : <return> <return> M-: ( c u r r e n t - c
o l u m n ) <return>
The same bug can be seen in C mode:
M-x c-mode<RET>
int main(void) {<RET>
<RET>
M-: (current-column)<RET>
(However, since there are more electric characters in c-mode, the
problem goes away as you continue typing; that isn't true of the
python-mode bug).
Investigating this, it seems the problem is in
electric-indent-post-self-insert-function: its code reads
(when (<= pos (line-beginning-position))
...
(delete-horizontal-space t)))))
(unless (and electric-indent-inhibit
(> pos (line-beginning-position)))
(indent-according-to-mode)))))
where pos is an integer, not a marker. Assuming
electric-indent-inhibit, when delete-horizontal-space does anything
(as is the case for newline on an indented empty line),
(line-beginning-position) changes, but pos doesn't change along with
it, so the (indent-according-to-mode) is skipped even though it should
be run on new empty lines.
The easiest fix would be to change electric--after-char-pos to return
a marker, not an integer:
diff --git a/lisp/electric.el b/lisp/electric.el
index e8ceaa6..874ec09 100644
--- a/lisp/electric.el
+++ b/lisp/electric.el
@@ -176,7 +176,7 @@
(defun electric--after-char-pos ()
"Return the position after the char we just inserted.
Returns nil when we can't find this char."
- (let ((pos (point)))
+ (let ((pos (point-marker)))
(when (or (eq (char-before) last-command-event) ;; Sanity check.
(save-excursion
(or (progn (skip-chars-backward " \t")
A slightly different fix would avoid using a temporary marker for
every self-insert:
diff --git a/lisp/electric.el b/lisp/electric.el
index e8ceaa6..34567d3 100644
--- a/lisp/electric.el
+++ b/lisp/electric.el
@@ -259,7 +259,8 @@ or comment."
(unless (eq act 'do-indent) (nth 8 (syntax-ppss))))))))
;; For newline, we want to reindent both lines and basically behave
like
;; reindent-then-newline-and-indent (whose code we hence copied).
- (when (<= pos (line-beginning-position))
+ (let ((at-newline (<= pos (line-beginning-position))))
+ (when at-newline
(let ((before (copy-marker (1- pos) t)))
(save-excursion
(unless (or (memq indent-line-function
@@ -280,8 +281,8 @@ or comment."
;; indentation may (re)introduce the whitespace.
(delete-horizontal-space t)))))
(unless (and electric-indent-inhibit
- (> pos (line-beginning-position)))
- (indent-according-to-mode)))))
+ (not at-newline))
+ (indent-according-to-mode))))))
(put 'electric-indent-post-self-insert-function 'priority 60)
Both fixes appear to fix the problem in c-mode and python-mode; I've
not tested rst-mode, which appears to be the only other standard mode
that uses electric-indent-inhibit.
In GNU Emacs 24.4.50.14 (x86_64-unknown-linux-gnu, GTK+ Version 3.10.7)
of 2014-05-08 on amerigo
Windowing system distributor `The X.Org Foundation', version 11.0.11500000
System Description: Debian GNU/Linux unstable (sid)
Configured using:
`configure --without-makeinfo --without-compress-install'
Configured features:
XPM JPEG TIFF GIF PNG RSVG SOUND DBUS GSETTINGS NOTIFY LIBSELINUX GNUTLS
LIBXML2 FREETYPE XFT ZLIB
Important settings:
value of $LANG: en_US.UTF-8
locale-coding-system: utf-8-unix
Major mode: Help
Minor modes in effect:
tooltip-mode: t
electric-indent-mode: t
mouse-wheel-mode: t
tool-bar-mode: t
menu-bar-mode: t
file-name-shadow-mode: t
global-font-lock-mode: t
font-lock-mode: t
blink-cursor-mode: t
auto-composition-mode: t
auto-encryption-mode: t
auto-compression-mode: t
buffer-read-only: t
line-number-mode: t
transient-mark-mode: t
Recent input:
M-x p y t h o n - m o d e <return> i f SPC a SPC =
= SPC 3 : <return> <return> M-: ( c u r r e n t - c
o l u m n ) <return> M-x v i e w - l <tab> <return>
<help-echo> <down-mouse-1> <mouse-1> <up> <up> <up>
<up> <up> <up> <up> <up> C-a C-SPC <C-down> <down>
<up> <right> <C-up> <down> <right> <right> <right>
<right> <right> <right> <right> <right> <right> <right>
<right> <right> <right> <right> <right> <right> <right>
<right> <right> <right> <down> <right> <left> C-w M-x
r e p <tab> o r <tab> <return>
Recent messages:
For information about GNU Emacs and the GNU system, type C-h C-a.
Can't guess python-indent-offset, using defaults: 4
0 (#o0, #x0, ?\C-@)
Type C-x 1 to delete the help window.
Beginning of buffer [4 times]
Mark set
End of buffer
Buffer is read-only: #<buffer *Help*>
Making completion list...
Load-path shadows:
None found.
Features:
(shadow sort gnus-util mail-extr emacsbug message dired format-spec
rfc822 mml mml-sec mm-decode mm-bodies mm-encode mail-parse rfc2231
mailabbrev gmm-utils mailheader sendmail rfc2047 rfc2045 ietf-drums
mm-util help-fns mail-prsvr mail-utils help-mode mule-util python
easymenu comint ring ansi-color time-date tooltip electric uniquify
ediff-hook vc-hooks lisp-float-type mwheel x-win x-dnd tool-bar dnd
fontset image regexp-opt fringe tabulated-list newcomment lisp-mode
prog-mode register page menu-bar rfn-eshadow timer select scroll-bar
mouse jit-lock font-lock syntax facemenu font-core frame cham georgian
utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean
japanese hebrew greek romanian slovak czech european ethiopic indian
cyrillic chinese case-table epa-hook jka-cmpr-hook help simple abbrev
minibuffer nadvice loaddefs button faces cus-face macroexp files
text-properties overlay sha1 md5 base64 format env code-pages mule
custom widget hashtable-print-readable backquote make-network-process
dbusbind gfilenotify dynamic-setting system-font-setting
font-render-setting move-toolbar gtk x-toolkit x multi-tty emacs)
Memory information:
((conses 16 82158 4302)
(symbols 48 18600 0)
(miscs 40 51 174)
(strings 32 13034 3892)
(string-bytes 1 365906)
(vectors 16 10278)
(vector-slots 8 388612 3417)
(floats 8 68 243)
(intervals 56 260 1)
(buffers 960 13)
(heap 1024 29346 991))
[Message part 2 (text/html, inline)]
[emacs-002.diff (text/plain, attachment)]
[emacs-003.diff (text/plain, attachment)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#17449
; Package
emacs
.
(Fri, 09 May 2014 16:10:02 GMT)
Full text and
rfc822 format available.
Message #8 received at 17449 <at> debbugs.gnu.org (full text, mbox):
> Date: Fri, 9 May 2014 10:09:03 +0000
> From: Philipp Rumpf <prumpf <at> gmail.com>
>
> In C mode and Python mode, hitting <RET> on an indented but otherwise
> empty line results in an unindented new line at point, rather than an
> indented line.
>
> To reproduce in emacs -Q:
>
> M-x python-mode<RET>
> if a == 3:<RET>
> <RET>
> M-: (current-column)<RET>
>
> Expected result: 4 / indented line
> Actual result: 0 / line not indented
Per the design. "C-h k RET" displays this text:
RET (translated from <return>) runs the command newline, which is an
interactive compiled Lisp function in `simple.el'.
It is bound to RET.
(newline &optional ARG INTERACTIVE)
Insert a newline, and move to left margin of the new line if it's blank.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#17449
; Package
emacs
.
(Fri, 09 May 2014 17:38:01 GMT)
Full text and
rfc822 format available.
Message #11 received at 17449 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Thanks for the response, but I really don't think this is the intended
behaviour! If you type
M-x python-mode <RET>
if a == 3:<RET>
<RET>
<RET>
<RET>
the cursor will jump back and forth between column 0 and 4 on every
alternate line, which simply does not make sense.
As for the documentation, here is the relevant paragraph from C-h k RET:
If `electric-indent-mode' is enabled, this indents the final new line
that it adds, and reindents the preceding line. To just insert
a newline, use M-x electric-indent-just-newline.
Since we're in electric-indent-mode in the test case (it is enabled by
default for me in emacs -Q), the behaviour I've seen definitely does not
match the documentation.
On Fri, May 9, 2014 at 4:09 PM, Eli Zaretskii <eliz <at> gnu.org> wrote:
> > Date: Fri, 9 May 2014 10:09:03 +0000
> > From: Philipp Rumpf <prumpf <at> gmail.com>
> >
> > In C mode and Python mode, hitting <RET> on an indented but otherwise
> > empty line results in an unindented new line at point, rather than an
> > indented line.
> >
> > To reproduce in emacs -Q:
> >
> > M-x python-mode<RET>
> > if a == 3:<RET>
> > <RET>
> > M-: (current-column)<RET>
> >
> > Expected result: 4 / indented line
> > Actual result: 0 / line not indented
>
> Per the design. "C-h k RET" displays this text:
>
> RET (translated from <return>) runs the command newline, which is an
> interactive compiled Lisp function in `simple.el'.
>
> It is bound to RET.
>
> (newline &optional ARG INTERACTIVE)
>
> Insert a newline, and move to left margin of the new line if it's blank.
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>
[Message part 2 (text/html, inline)]
Reply sent
to
Stefan Monnier <monnier <at> iro.umontreal.ca>
:
You have taken responsibility.
(Fri, 09 May 2014 18:04:01 GMT)
Full text and
rfc822 format available.
Notification sent
to
Philipp Rumpf <prumpf <at> gmail.com>
:
bug acknowledged by developer.
(Fri, 09 May 2014 18:04:02 GMT)
Full text and
rfc822 format available.
Message #16 received at 17449-done <at> debbugs.gnu.org (full text, mbox):
> A slightly different fix would avoid using a temporary marker for
> every self-insert:
Thanks, I installed this fix,
Stefan
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Sat, 07 Jun 2014 11:24:04 GMT)
Full text and
rfc822 format available.
This bug report was last modified 11 years and 16 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.