unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#18913: 24.4.51; point going back to bol after every insertion
@ 2014-10-30 12:03 Nicolas Richard
  2014-10-31 20:27 ` Stefan Monnier
  0 siblings, 1 reply; 2+ messages in thread
From: Nicolas Richard @ 2014-10-30 12:03 UTC (permalink / raw)
  To: 18913

Hello,

I found myself in the situation where cursor would go to bol after every
character I would insert. The reason was I had a compiled function in my
post-self-insert-hook -- its bytecode disassembled to :

byte code:
  doc:   ...
  args: 0
0       varref    use-hard-newlines
1       goto-if-nil 1
4       constant  set-hard-newline-properties
5       point     
6       constant  prefix-numeric-value
7       constant  nil
8       call      1
9       diff      
10      point     
11      call      2
12      discard   
13:1    save-excursion 
14      constant  102025
15      goto-char 
16      discard   
17      constant  beginning-of-line
18      call      0
19      discard   
20      constant  looking-at
21      constant  "[ 	]$"
22      call      1
23      goto-if-nil 2
26      constant  current-left-margin
27      call      0
28      constant  0
29      gtr       
30      goto-if-nil 2
33      point     
34      constant  line-end-position
35      call      0
36      delete-region 
37      discard   
38:2    unbind    1
39      constant  nil
40      goto-if-not-nil-else-pop 3
43      constant  move-to-left-margin
44      constant  nil
45      constant  t
46      call      2
47:3    return    

A bit of grepping shows that this is the following lambda
defined in the function newline (bound to `postproc'):
     (lambda ()
       ;; Mark the newline(s) `hard'.
       (if use-hard-newlines
           (set-hard-newline-properties
            (- (point) (prefix-numeric-value arg)) (point)))
       ;; If the newline leaves the previous line blank, and we
       ;; have a left margin, delete that from the blank line.
       (save-excursion
         (goto-char beforepos)
         (beginning-of-line)
         (and (looking-at "[ \t]$")
              (> (current-left-margin) 0)
              (delete-region (point)
                             (line-end-position))))
       ;; Indent the line after the newline, except in one case:
       ;; when we added the newline at the beginning of a line which
       ;; starts a page.
       (or was-page-start
           (move-to-left-margin nil t)))

OTOH in that function, post-self-insert-hook is changed in a let binding
or it is protected with unwind-protect, so i don't understand how it
could happen.

FWIW I was in ielm when it happened, and here's the rest of my
post-self-insert-hook => (electric-indent-post-self-insert-function
blink-paren-post-self-insert-function)


In GNU Emacs 24.4.51.2 (i686-pc-linux-gnu, X toolkit, Xaw3d scroll bars)
 of 2014-10-30 on localhost
Windowing system distributor `The X.Org Foundation', version 11.0.11304000
System Description:	Gentoo Base System release 2.2

Configured using:
 `configure --with-x-toolkit=lucid --enable-checking --with-wide-int
 'CFLAGS= -O0 -g3''

Important settings:
  value of $LANG: fr_FR.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Lisp Interaction

Memory information:
((conses 16 2102837 191830)
 (symbols 40 93520 37)
 (miscs 36 26347 11976)
 (strings 16 200774 27097)
 (string-bytes 1 6588284)
 (vectors 12 83543)
 (vector-slots 8 1452046 54417)
 (floats 8 1173 1233)
 (intervals 36 139920 380)
 (buffers 828 237)
 (heap 1024 87889 11076))

-- 
Nicolas Richard





^ permalink raw reply	[flat|nested] 2+ messages in thread

* bug#18913: 24.4.51; point going back to bol after every insertion
  2014-10-30 12:03 bug#18913: 24.4.51; point going back to bol after every insertion Nicolas Richard
@ 2014-10-31 20:27 ` Stefan Monnier
  0 siblings, 0 replies; 2+ messages in thread
From: Stefan Monnier @ 2014-10-31 20:27 UTC (permalink / raw)
  To: Nicolas Richard; +Cc: 18913

> I found myself in the situation where cursor would go to bol after every
> character I would insert.

Could you rebuild with the patch below (and run with debug-on-error
enabled) and see if you can get those asserts to trigger, which would
give us some information about how/when this happens.


        Stefan


=== modified file 'lisp/simple.el'
--- lisp/simple.el	2014-08-18 15:20:27 +0000
+++ lisp/simple.el	2014-10-31 20:25:11 +0000
@@ -28,6 +28,8 @@
 
 ;;; Code:
 
+(eval-when-compile (require 'cl-lib))
+
 (declare-function widget-convert "wid-edit" (type &rest args))
 (declare-function shell-mode "shell" ())
 
@@ -428,6 +430,7 @@
             ;; starts a page.
             (or was-page-start
                 (move-to-left-margin nil t)))))
+    (unwind-protect
     (if (not interactive)
         ;; FIXME: For non-interactive uses, many calls actually just want
         ;; (insert "\n"), so maybe we should do just that, so as to avoid
@@ -441,7 +444,9 @@
         ;; We first used let-binding to protect the hook, but that was naive
         ;; since add-hook affects the symbol-default value of the variable,
         ;; whereas the let-binding might only protect the buffer-local value.
-        (remove-hook 'post-self-insert-hook postproc))))
+        (remove-hook 'post-self-insert-hook postproc)))
+      (cl-assert (not (member postproc post-self-insert-hook)))
+      (cl-assert (not (member postproc (default-value 'post-self-insert-hook))))))
   nil)
 
 (defun set-hard-newline-properties (from to)






^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-10-31 20:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-30 12:03 bug#18913: 24.4.51; point going back to bol after every insertion Nicolas Richard
2014-10-31 20:27 ` Stefan Monnier

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).