Last active
August 29, 2015 14:13
-
-
Save kaushalmodi/b04368e07aa89a28545b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Time-stamp: <2015-01-20 13:10:26 kmodi> | |
;; Code to demonstrate that hydra is wiping out my predefined bindings to my | |
;; minor mode map | |
;; https://github.com/abo-abo/hydra/issues/3 | |
(require 'hydra) | |
(require 'bind-key) | |
(defvar xyz-mode-map (make-sparse-keymap) | |
"Keymap while xyz-mode is active.") | |
(defvar xyz/pseudo-map-prefix "C-M-o" | |
;; overrides the default binding to `split-line' | |
"Prefix key binding for a `pseudo' keymap.") | |
;;;###autoload | |
(define-minor-mode xyz-mode | |
"A minor mode so that my key settings override annoying major modes." | |
nil | |
:lighter " xyz" | |
xyz-mode-map) | |
(defadvice load (after give-my-keybindings-priority) | |
"Try to ensure that my keybindings always have priority." | |
(if (not (eq (car (car minor-mode-map-alist)) 'xyz-mode)) | |
(let ((mykeys (assq 'xyz-mode minor-mode-map-alist))) | |
(assq-delete-all 'xyz-mode minor-mode-map-alist) | |
(add-to-list 'minor-mode-map-alist mykeys)))) | |
(ad-activate 'load) | |
;;;###autoload | |
(defun turn-on-xyz-mode () | |
"Turns on xyz-mode." | |
(interactive) | |
(xyz-mode t)) | |
;;;###autoload | |
(defun turn-off-xyz-mode () | |
"Turns off xyz-mode." | |
(interactive) | |
(xyz-mode -1)) | |
;;;###autoload | |
(define-globalized-minor-mode global-xyz-mode xyz-mode turn-on-xyz-mode) | |
;; Turn off the minor mode in the minibuffer | |
(add-hook 'minibuffer-setup-hook 'turn-off-xyz-mode) | |
;; ###autoload | |
;; (add-hook 'text-mode-hook 'xyz-mode) | |
(defmacro bind-to-xyz-map (key fn) | |
"Bind a function to the `xyz-mode-map' | |
USAGE: (bind-to-xyz-map \"f\" full-screen-center) | |
" | |
`(bind-key (concat ,xyz/pseudo-map-prefix " " ,key) ',fn xyz-mode-map)) | |
(bind-to-xyz-map "p" previous-line) | |
(bind-to-xyz-map "n" next-line) | |
(turn-on-xyz-mode) | |
;; 1. First load this file without uncommenting below | |
;; 2. Do `C-h c C-M-o p`.. it will show that that is bound to `previous-line` | |
;; 3. Now uncomment and evaluate the below `hydra-create' call | |
;; 4. Do `C-h c C-M-o p`.. it will show that that is undefined! | |
;; (hydra-create "C-M-o" | |
;; '(("h" . hydra-move-splitter-left) | |
;; ("j" . hydra-move-splitter-down) | |
;; ("k" . hydra-move-splitter-up) | |
;; ("l" . hydra-move-splitter-right)) | |
;; xyz-mode-map) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment