* bug#17449: 24.4.50; Empty lines confuse electric-indent-post-self-insert-function.
@ 2014-05-09 10:09 Philipp Rumpf
2014-05-09 16:09 ` Eli Zaretskii
2014-05-09 18:03 ` Stefan Monnier
0 siblings, 2 replies; 4+ messages in thread
From: Philipp Rumpf @ 2014-05-09 10:09 UTC (permalink / raw)
To: 17449
[-- Attachment #1.1: Type: text/plain, Size: 6544 bytes --]
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))
[-- Attachment #1.2: Type: text/html, Size: 7956 bytes --]
[-- Attachment #2: emacs-002.diff --]
[-- Type: text/plain, Size: 494 bytes --]
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")
[-- Attachment #3: emacs-003.diff --]
[-- Type: text/plain, Size: 2688 bytes --]
diff --git a/lisp/electric.el b/lisp/electric.el
index e8ceaa6..34567d3 100644
--- a/lisp/electric.el
+++ b/lisp/electric.el
@@ -259,29 +259,30 @@ 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 ((before (copy-marker (1- pos) t)))
- (save-excursion
- (unless (or (memq indent-line-function
- electric-indent-functions-without-reindent)
- electric-indent-inhibit)
- ;; Don't reindent the previous line if the indentation function
- ;; is not a real one.
- (goto-char before)
- (indent-according-to-mode))
- ;; We are at EOL before the call to indent-according-to-mode, and
- ;; after it we usually are as well, but not always. We tried to
- ;; address it with `save-excursion' but that uses a normal marker
- ;; whereas we need `move after insertion', so we do the
- ;; save/restore by hand.
- (goto-char before)
- (when (eolp)
- ;; Remove the trailing whitespace after indentation because
- ;; indentation may (re)introduce the whitespace.
- (delete-horizontal-space t)))))
- (unless (and electric-indent-inhibit
- (> pos (line-beginning-position)))
- (indent-according-to-mode)))))
+ (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
+ electric-indent-functions-without-reindent)
+ electric-indent-inhibit)
+ ;; Don't reindent the previous line if the indentation function
+ ;; is not a real one.
+ (goto-char before)
+ (indent-according-to-mode))
+ ;; We are at EOL before the call to indent-according-to-mode, and
+ ;; after it we usually are as well, but not always. We tried to
+ ;; address it with `save-excursion' but that uses a normal marker
+ ;; whereas we need `move after insertion', so we do the
+ ;; save/restore by hand.
+ (goto-char before)
+ (when (eolp)
+ ;; Remove the trailing whitespace after indentation because
+ ;; indentation may (re)introduce the whitespace.
+ (delete-horizontal-space t)))))
+ (unless (and electric-indent-inhibit
+ (not at-newline))
+ (indent-according-to-mode))))))
(put 'electric-indent-post-self-insert-function 'priority 60)
^ permalink raw reply related [flat|nested] 4+ messages in thread
* bug#17449: 24.4.50; Empty lines confuse electric-indent-post-self-insert-function.
2014-05-09 10:09 bug#17449: 24.4.50; Empty lines confuse electric-indent-post-self-insert-function Philipp Rumpf
@ 2014-05-09 16:09 ` Eli Zaretskii
2014-05-09 17:36 ` Philipp Rumpf
2014-05-09 18:03 ` Stefan Monnier
1 sibling, 1 reply; 4+ messages in thread
From: Eli Zaretskii @ 2014-05-09 16:09 UTC (permalink / raw)
To: Philipp Rumpf; +Cc: 17449
> Date: Fri, 9 May 2014 10:09:03 +0000
> From: Philipp Rumpf <prumpf@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.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^ permalink raw reply [flat|nested] 4+ messages in thread
* bug#17449: 24.4.50; Empty lines confuse electric-indent-post-self-insert-function.
2014-05-09 16:09 ` Eli Zaretskii
@ 2014-05-09 17:36 ` Philipp Rumpf
0 siblings, 0 replies; 4+ messages in thread
From: Philipp Rumpf @ 2014-05-09 17:36 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: 17449
[-- Attachment #1: Type: text/plain, Size: 1651 bytes --]
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@gnu.org> wrote:
> > Date: Fri, 9 May 2014 10:09:03 +0000
> > From: Philipp Rumpf <prumpf@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.
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>
[-- Attachment #2: Type: text/html, Size: 2433 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* bug#17449: 24.4.50; Empty lines confuse electric-indent-post-self-insert-function.
2014-05-09 10:09 bug#17449: 24.4.50; Empty lines confuse electric-indent-post-self-insert-function Philipp Rumpf
2014-05-09 16:09 ` Eli Zaretskii
@ 2014-05-09 18:03 ` Stefan Monnier
1 sibling, 0 replies; 4+ messages in thread
From: Stefan Monnier @ 2014-05-09 18:03 UTC (permalink / raw)
To: Philipp Rumpf; +Cc: 17449-done
> A slightly different fix would avoid using a temporary marker for
> every self-insert:
Thanks, I installed this fix,
Stefan
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-05-09 18:03 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-09 10:09 bug#17449: 24.4.50; Empty lines confuse electric-indent-post-self-insert-function Philipp Rumpf
2014-05-09 16:09 ` Eli Zaretskii
2014-05-09 17:36 ` Philipp Rumpf
2014-05-09 18:03 ` Stefan Monnier
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.