Colin Rafferty <colin(a)xemacs.org> writes:
Hrvoje Niksic writes:
> (global-set-key 'Cyrillic_HARDSIGN 'self-insert-command)
> (put 'Cyrillic_HARDSIGN 'ascii-character ?\xff)
How would I do this for something other than an actual key. For
example, in the A+ programming language, I would like to have the
following:
(global-set-key [('alt ?a)] 'self-insert-command)
(put [(alt ?a)] 'ascii-character ?\301)
You'd have to be more tricky than that. I hoped something like this
might have a chance to work:
(defun colins-command ()
(interactive)
(self-insert-internal ?\301)
;; Attempt No. 1 to fool isearch.
(setq this-command 'self-insert-command))
;; Attempt No. 2 to fool isearch.
(put 'colins-command 'isearch-command t)
(global-set-key [(alt a)] 'colins-command)
But it doesn't work because isearch-maybe-frob-keyboard-macros, which
gets called from isearch-pre-command-hook, i.e. *before* your function
is run, explicitly checks for self-insert-command.
I was tempted to try to "fix" isearch-maybe-frob-keyboard-macros, but
after some thinking I concluded that it was the only reasonable thing
to do. Remember that isearch needs to update its search string with
the new character. Isearch cannot know in advance what character
colins-command is about to insert; since colins-command is not
self-insert-command, just using last-command-event would be wrong.
But then I remembered that "keysyms" aren't really cast in stone, and
that with a little trickery you can fake keysyms from Lisp. Here is
the result:
(global-set-key '(alt a) [fake-keysym])
(global-set-key 'fake-keysym 'self-insert-command)
(put 'fake-keysym 'ascii-character ?\301)