4

I want to unset the backspace key and I tried this:

(global-unset-key (kbd "<backspace>"))

Evaluating this in the buffer gives me nil but still the backspace key works as expected. How to unbind this?

After unbinding when I do C-h k on backspace it still shows me this:

DEL (translated from <backspace>) runs the command autopair-backspace, which is an interactive compiled Lisp function in `autopair.el'.

It is bound to DEL.

(autopair-backspace)

Possibly delete a pair of paired delimiters.

3
  • Do you still want to keep using autopair?
    – abo-abo
    Dec 29, 2014 at 21:29
  • @abo-abo Yes, but if there is a way to rebind backspace key to some other key in autopair and all the other modes that has some binding for backspace key, then that would be very nice.
    – Sibi
    Dec 29, 2014 at 21:31
  • This is how I'll do, (local-unset-key (kbd "<DEL>")) or (global-unset-key (kbd "<DEL>")). Curiously, it works only in another buffer, not in *scratch* buffer :\
    – Nsukami _
    Dec 29, 2014 at 21:48

3 Answers 3

2

Finally figured this out, this will re-map Backspace key to C-h everywhere:

(define-key key-translation-map [?\C-h] [?\C-?])

Source: Magnar Sveen's Emacs configuration

0

Try this:

(define-key (cdar autopair--emulation-alist) (kbd "DEL") nil)

This looks very non-standard, by the way.

update:

Alright, here's a weird fix:

(setcdr (car autopair--emulation-alist)
        '(keymap (93 . autopair-skip-close-maybe)
          (91 . autopair-insert-opening)
          (41 . autopair-skip-close-maybe)
          (40 . autopair-insert-opening)
          (34 . autopair-insert-or-skip-quote)
          (13 . autopair-newline))) 
3
  • Sorry, doesn't work.
    – Sibi
    Dec 29, 2014 at 21:40
  • Try to eval this in *scratch*. autopair--emulation-alist is buffer-local.
    – abo-abo
    Dec 29, 2014 at 21:41
  • Tried it in *scratch*, but doesn't seem to have any effect.
    – Sibi
    Dec 29, 2014 at 21:43
0

This is not exactly an answer to your question since it doesn't unset the DEL binding, but the following piece of code should shadow any existing binding (whether defined by autopair or any other minor/major mode or the global map):

(defun do-nothing ()
  "Don't do anything"
  (interactive))

(define-minor-mode no-backspace-mode
  "Disable the backspace key"
  :global t
  :lighter " noBackspace")

(defvar no-backspace--emulation-alist
  `((no-backspace-mode
     . ,(let ((map (make-sparse-keymap)))
          (define-key map (kbd "DEL") #'do-nothing)
          map)))) 

(add-to-list 'emulation-mode-map-alists 'no-backspace--emulation-alist)

When no-backspace-mode is active, the DEL key should not do anything. It should work as usual when no-backspace-mode is inactive.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.