Function: normal-erase-is-backspace-mode

normal-erase-is-backspace-mode is an interactive and byte-compiled function defined in simple.el.gz.

Signature

(normal-erase-is-backspace-mode &optional ARG)

Documentation

Toggle the Erase and Delete mode of the Backspace and Delete keys.

On window systems, when this mode is on, Delete is mapped to \C-d and Backspace is mapped to \DEL; when this mode is off, both Delete and Backspace are mapped to \DEL. (The remapping goes via local-function-key-map, so binding Delete or Backspace in the global or local keymap will override that.)

In addition, on window systems, the bindings of C-Delete, M-Delete, C-M-Delete, C-Backspace, M-Backspace, and C-M-Backspace are changed in the global keymap in accordance with the functionality of Delete and Backspace. For example, if Delete is remapped to \C-d, which deletes forward, C-Delete is bound to kill-word, but if Delete is remapped to \DEL, which deletes backward, C-Delete is bound to backward-kill-word.

If not running on a window system, a similar effect is accomplished by remapping \C-h (normally produced by the Backspace key) and \DEL via keyboard-translate: if this mode is on, \C-h is mapped to
\DEL and \DEL to \C-d; if it's off, the keys are not remapped.

When not running on a window system, and this mode is turned on, the former functionality of \C-h is available on the F1 key. You should probably not turn on this mode on a text-only terminal if you don't have both Backspace, Delete and F1 keys.

See also normal-erase-is-backspace.

This is a minor mode. If called interactively, toggle the Normal-Erase-Is-Backspace mode mode. If the prefix argument is positive, enable the mode, and if it is zero or negative, disable the mode.

If called from Lisp, toggle the mode if ARG is toggle. Enable the mode if ARG is nil, omitted, or is a positive number. Disable the mode if ARG is a negative number.

To check whether the minor mode is enabled in the current buffer, evaluate (eq (terminal-parameter nil \=normal-erase-is-backspace) 1)'.

The mode's hook is called both when the mode is enabled and when it is disabled.

View in manual

Probably introduced at or before Emacs version 21.1.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/simple.el.gz
(define-minor-mode normal-erase-is-backspace-mode
  "Toggle the Erase and Delete mode of the Backspace and Delete keys.

On window systems, when this mode is on, Delete is mapped to \\`C-d'
and Backspace is mapped to \\`DEL'; when this mode is off, both
Delete and Backspace are mapped to \\`DEL'.  (The remapping goes via
`local-function-key-map', so binding Delete or Backspace in the
global or local keymap will override that.)

In addition, on window systems, the bindings of C-Delete, M-Delete,
C-M-Delete, C-Backspace, M-Backspace, and C-M-Backspace are changed in
the global keymap in accordance with the functionality of Delete and
Backspace.  For example, if Delete is remapped to \\`C-d', which deletes
forward, C-Delete is bound to `kill-word', but if Delete is remapped
to \\`DEL', which deletes backward, C-Delete is bound to
`backward-kill-word'.

If not running on a window system, a similar effect is accomplished by
remapping \\`C-h' (normally produced by the Backspace key) and \\`DEL'
via `keyboard-translate': if this mode is on, \\`C-h' is mapped to
\\`DEL' and \\`DEL' to \\`C-d'; if it's off, the keys are not remapped.

When not running on a window system, and this mode is turned on, the
former functionality of \\`C-h' is available on the F1 key.  You should
probably not turn on this mode on a text-only terminal if you don't
have both Backspace, Delete and F1 keys.

See also `normal-erase-is-backspace'."
  :variable ((eq (terminal-parameter nil 'normal-erase-is-backspace) 1)
             . (lambda (v)
                 (setf (terminal-parameter nil 'normal-erase-is-backspace)
                       (if v 1 0))))
  (let ((enabled (eq 1 (terminal-parameter
                        nil 'normal-erase-is-backspace))))

    (cond ((display-symbol-keys-p)
	   (let ((bindings
		  '(([M-delete] [M-backspace])
		    ([C-M-delete] [C-M-backspace])
		    ([?\e C-delete] [?\e C-backspace]))))

	     (if enabled
		 (progn
		   (define-key local-function-key-map [delete] [deletechar])
		   (define-key local-function-key-map [kp-delete] [deletechar])
		   (define-key local-function-key-map [backspace] [?\C-?])
                   (dolist (b bindings)
                     ;; Not sure if input-decode-map is really right, but
                     ;; keyboard-translate-table (used below) works only
                     ;; for integer events, and key-translation-table is
                     ;; global (like the global-map, used earlier).
                     (define-key input-decode-map (car b) nil)
                     (define-key input-decode-map (cadr b) nil)))
	       (define-key local-function-key-map [delete] [?\C-?])
	       (define-key local-function-key-map [kp-delete] [?\C-?])
	       (define-key local-function-key-map [backspace] [?\C-?])
               (dolist (b bindings)
                 (define-key input-decode-map (car b) (cadr b))
                 (define-key input-decode-map (cadr b) (car b))))))
	  (t
	   (if enabled
	       (progn
                 (key-translate "C-h" "DEL")
                 (key-translate "DEL" "C-d"))
             (key-translate "C-h" "C-h")
             (key-translate "DEL" "DEL"))))

    (if (called-interactively-p 'interactive)
	(message "Delete key deletes %s"
		 (if (eq 1 (terminal-parameter nil 'normal-erase-is-backspace))
		     "forward" "backward")))))