the key to Emacs keys

Mon, 16 May 2016 21:06:39 +0200

> Since this file is read only and it's not
> inside .emacs.d, I do not want to change it
> directly if other solutions are possible.

Good call! Because then you'll loose it for
example when you upgrade Emacs, and each edit
would require a sudo detour...

> I've tried with writing the following line in
> my personal customization file:
>
>     (define-key global-map (kbd "<f8>")
> 'toggle-input-method) or (global-set-key (kbd
> "<f8>") 'toggle-input-method)

Instead of (kbd "<f8>"), you can do [f8].

(But: I don't recommend using the function keys
as they are remote (i.e., require arm movement
as opposed to just finger ditto, which in turn
implies a reset to typing position) - also they
are confusing (too alike) and thus difficult to
remember. And they don't work in a VT Emacs
instance! - not without special efforts [1]
at least.)

> Apparently my method does not override the
> original key binding. Any suggestions?

By "override", do you mean the new keystroke
won't work, or the old keystroke remains?

If the old keystroke remains, that is normal.
You can unset it like this:

    (global-unset-key "\C-hh")

If the new keystroke doesn't work, sometimes it
is the case that a *local* keymap has that key
assigned. Changing the global keymap doesn't
change the local map, of course, and the local
map has priority, as far as locally goes!

Here is some code to automatize setting
a global key, and then disabling the same key
for the desired local modes - if you want the
global key to be in effect there, as well.
Use the functions in the order they appear.

    (defvar super-global-keys '())

    (defun super-global-set-key (key function)
      "Make a super global KEY that invokes FUNCTION."
      (global-set-key key function)
      (add-to-list 'super-global-keys key) )

    (defun disable-super-global-keys (&optional map)
      "Disable MAP super global keystrokes, so they can be assigned."
      (dolist (k super-global-keys)
        (define-key (or map (current-local-map)) k nil) ))

[1] http://user.it.uu.se/~embe8573/tty-emacs-keys.txt

Back to Blogomatic.