Xah Fly Keys not idempotent

By Xah Lee. Date: .

Xah Fly Keys not idempotent

Another issue I just now noticed is that enabling and disabling `xah-fly-keys' is not idempotent (as most people would assume it to be), since the global map is manipulated. The user options `xah-fly-use-control-key' and `xah-fly-use-meta-key' should probably have custom :set properties added that manipulate `xah-fly-keys-map', and binding #'undefined instead of nil.

Rather than using `global-set-key` another option (since Emacs-24) is to keep the package's global bindings on a separate keymap which is then added/removed from the global map when enabling/disabling the mode.

The basic idea could look like:

(cond
    (enabling
     (unless (memq xah-fly-keys-global-map global-map) ;; Already done
       (unless (keymap-parent global-map)
         ;; Separate the default part of the global map from the user's
         ;; own changes that might occur later.
         (setq global-map (make-composed-keymap nil global-map)))
       ;; Add `xah-fly-keys-global-map' so that it takes precedence over
       ;; the main part of `global-map' but not over the user's own settings.
       (set-keymap-parent global-map
                          (make-composed-keymap xah-fly-keys-global-map
                                                (keymap-parent global-map)))))
    (disabling
     ;; FIXME: Repeated enable/disable will keep adding a `keymap` symbol
     ;; to the map :-(
     (setq global-map (delq xah-fly-keys-global-map global-map)))