3

I changed the C-h key binding to be used as backspace.

(define-key key-translation-map (kbd "C-h") (kbd "< DEL >"))

Now, this works flawlessy pretty much everywhere except in html-mode. When I'm in an HTML command minibuffer and press C-h, instead of deleting the last character this message appears:

You are inserting a skeleton. Standard text gets inserted into the buffer automatically, and you are prompted to fill in the variable parts.

How could I solve this problem if possible?

itsjeyd
  • 14,586
  • 3
  • 58
  • 87
allikotsa
  • 115
  • 4
  • Ahh I see, I missed the part about the minibuffer. I'm really not sure what mode is overshadowing your map. – nanny Nov 21 '14 at 16:50
  • 1
    Possibly related: [How can I find out in which keymap a key is bound?](http://emacs.stackexchange.com/q/653/50) – Malabarba Nov 21 '14 at 17:09

1 Answers1

4

This was an interesting one.

html-mode is derived from sgml-mode, which uses skeletons, which may read input from the minibuffer, which, underneath it all, uses read-char to get keyboard input.

read-char gets one event (one key press) before the key-translation-map is used. On top of that, if the help-form (minibuffer-help-form when reading from the minibuffer) variable is bound and is not nil, characters equal to help-char are captured and trigger the evaluation of help-form (or minibuffer-help-form), the value of which, if it is a string, is displayed in the *Char Help* buffer.

Here's the problem: C-h is the default value of help-char. This makes it impossible to input C-h (or whatever help-char is set to) if minibuffer-help-form is set, and skeleton-read does set it.

This suggests that the issue described in the question should affect other modes too.

Here's a minimal example:

(define-key key-translation-map (kbd "C-h") (kbd "<DEL>"))

(let ((minibuffer-help-form "Help!"))
  (read-from-minibuffer "Try using ^H now! "))

To get around this, you can just

(setq help-char nil)

or customize this variable. This disables evaluation of help-form and minibuffer-help-form everywhere.

Alternatively, you can add advice to skeleton-read to allow using C-h in skeleton prompts and keep the default behavior elsewhere:

(advice-add 'skeleton-read :around
            (lambda (orig &rest args)
              (let ((help-char nil))
                (apply orig args))))
Constantine
  • 9,072
  • 1
  • 34
  • 49