Skip to main content

EDIT 3 {

I don't believe the root of the problem has really been found. This problem manifests independently of any terminals. It also occurs in graphical Emacs. I decided to try to trace what Emacs was doing using a pre-command-hook:

(defvar *event-log* nil)
(defun log-commands nil
  (let ((buf (current-buffer)))
    (cl-push `(,buf ,this-command ,(this-command-keys))
          *event-log*)))
(add-hook 'pre-command-hook 'log-commands)

This causes Emacs to log every single keypress to an in-memory list.

From there, I opened a Python source file and put the cursor where the block appears:

def foobar(baz,qux):
    try:
        quux.xyzzy()▋
    except:
        pass

From there, I added .foobar and then tried to delete it by pressing Backspace twice (enough to reproduce the behavior and also revert back to the correct behavior). The resulting event log, which is in reverse chronological order:

 (#<buffer foobar.py> python-indent-dedent-line-backspace "^?") 
 (#<buffer foobar.py> delete-char "^D") 
 (#<buffer foobar.py> self-insert-command "r")
 (#<buffer foobar.py> self-insert-command "a")
 (#<buffer foobar.py> self-insert-command "b")
 (#<buffer foobar.py> self-insert-command "o")
 (#<buffer foobar.py> self-insert-command "o")
 (#<buffer foobar.py> self-insert-command "f")
 (#<buffer foobar.py> self-insert-command ".")

It clearly shows that the same key is being received as two distinct keys, and therefore it's executing two different functions. Why this happens remains a mystery, but because it can happen in a GUI session, we can rule out the possibility of terminal settings being to blame. Also note that it's impossible for things like terminal settings or X11 keymap bindings to suddenly change as a result of Emacs keypresses, and even if it was, the behavior would not be consistent between terminals, local X11 sessions, and X11-forwarded sessions.

}

EDIT 3 {

I don't believe the root of the problem has really been found. This problem manifests independently of any terminals. It also occurs in graphical Emacs. I decided to try to trace what Emacs was doing using a pre-command-hook:

(defvar *event-log* nil)
(defun log-commands nil
  (let ((buf (current-buffer)))
    (cl-push `(,buf ,this-command ,(this-command-keys))
          *event-log*)))
(add-hook 'pre-command-hook 'log-commands)

This causes Emacs to log every single keypress to an in-memory list.

From there, I opened a Python source file and put the cursor where the block appears:

def foobar(baz,qux):
    try:
        quux.xyzzy()▋
    except:
        pass

From there, I added .foobar and then tried to delete it by pressing Backspace twice (enough to reproduce the behavior and also revert back to the correct behavior). The resulting event log, which is in reverse chronological order:

 (#<buffer foobar.py> python-indent-dedent-line-backspace "^?") 
 (#<buffer foobar.py> delete-char "^D") 
 (#<buffer foobar.py> self-insert-command "r")
 (#<buffer foobar.py> self-insert-command "a")
 (#<buffer foobar.py> self-insert-command "b")
 (#<buffer foobar.py> self-insert-command "o")
 (#<buffer foobar.py> self-insert-command "o")
 (#<buffer foobar.py> self-insert-command "f")
 (#<buffer foobar.py> self-insert-command ".")

It clearly shows that the same key is being received as two distinct keys, and therefore it's executing two different functions. Why this happens remains a mystery, but because it can happen in a GUI session, we can rule out the possibility of terminal settings being to blame. Also note that it's impossible for things like terminal settings or X11 keymap bindings to suddenly change as a result of Emacs keypresses, and even if it was, the behavior would not be consistent between terminals, local X11 sessions, and X11-forwarded sessions.

}

Commonmark migration
Source Link

##Start Edit 1

Start Edit 1

##End Edit 1

End Edit 1

##Start Edit 2

Start Edit 2

##End Edit 2

End Edit 2

##Start Edit 1

##End Edit 1

##Start Edit 2

##End Edit 2

Start Edit 1

End Edit 1

Start Edit 2

End Edit 2

More updates as requested.
Source Link
Gabe
  • 51
  • 4
<backspace> runs the command py-electric-backspace (found in
python-mode-map), which is an interactive compiled Lisp function in
‘python python-mode.el’el .

It is bound to <backspace>, <menu-bar> <Python> <Other> <Electric>
<Electric backspace>.

(py-electric-backspace &optional ARG)

Delete preceding character or level of indentation.

When ‘delete delete-active-region’region  and (use-region-p), delete region.

Unless at indentation:
  With ‘py py-electric-kill-backward-p’p  delete whitespace before point.
  With ‘py py-electric-kill-backward-p’p  at end of a list, empty that list.

Returns column reached. 

[back]

##End Edit 1

##Start Edit 2

A few more updates (so far ony trouble shooting on Linux):

  • Looking at the output of M-x describe-bindings while in python-mode clearly shows <backspace> bound to py-electric-backspace
  • Running M-x py-electric-backspace always does the right thing
  • If I bind py-electric-backspace from within the buffer to some other key (e.g. by running M-x eval-expression then (define-key python-mode-map "\C-n" 'py-electric-backspace)), it works as expected.
  • Removing all key-bindings in my ~/.emacs does not solve this
  • M-x describe-bindings also shows <backspace> mapped to DEL under the Function key map translations: section.
  • Manually setting the normal-erase-is-backspace via M-x set-variable (0 = Off, 1 = Maybe, 2 = On or even t or nil) does nothing to solve the problem but does toggle Backspace between Backspace and DEL.
  • Manually running M-x normal-erase-is-backspace turns Backspace into C-h

##End Edit 2

<backspace> runs the command py-electric-backspace (found in
python-mode-map), which is an interactive compiled Lisp function in
‘python-mode.el’.

It is bound to <backspace>, <menu-bar> <Python> <Other> <Electric>
<Electric backspace>.

(py-electric-backspace &optional ARG)

Delete preceding character or level of indentation.

When ‘delete-active-region’ and (use-region-p), delete region.

Unless at indentation:
  With ‘py-electric-kill-backward-p’ delete whitespace before point.
  With ‘py-electric-kill-backward-p’ at end of a list, empty that list.

Returns column reached. 

[back]

##End Edit 1

<backspace> runs the command py-electric-backspace (found in
python-mode-map), which is an interactive compiled Lisp function in
 python-mode.el .

It is bound to <backspace>, <menu-bar> <Python> <Other> <Electric>
<Electric backspace>.

(py-electric-backspace &optional ARG)

Delete preceding character or level of indentation.

When  delete-active-region  and (use-region-p), delete region.

Unless at indentation:
  With  py-electric-kill-backward-p  delete whitespace before point.
  With  py-electric-kill-backward-p  at end of a list, empty that list.

Returns column reached. 

[back]

##End Edit 1

##Start Edit 2

A few more updates (so far ony trouble shooting on Linux):

  • Looking at the output of M-x describe-bindings while in python-mode clearly shows <backspace> bound to py-electric-backspace
  • Running M-x py-electric-backspace always does the right thing
  • If I bind py-electric-backspace from within the buffer to some other key (e.g. by running M-x eval-expression then (define-key python-mode-map "\C-n" 'py-electric-backspace)), it works as expected.
  • Removing all key-bindings in my ~/.emacs does not solve this
  • M-x describe-bindings also shows <backspace> mapped to DEL under the Function key map translations: section.
  • Manually setting the normal-erase-is-backspace via M-x set-variable (0 = Off, 1 = Maybe, 2 = On or even t or nil) does nothing to solve the problem but does toggle Backspace between Backspace and DEL.
  • Manually running M-x normal-erase-is-backspace turns Backspace into C-h

##End Edit 2

Answering questions for all.
Source Link
Gabe
  • 51
  • 4
Loading
Answering questions for all.
Source Link
Gabe
  • 51
  • 4
Loading
edited tags
Link
Drew
  • 79.1k
  • 10
  • 123
  • 257
Loading
Source Link
Gabe
  • 51
  • 4
Loading