Paste number 304865: Emacs context keys

Paste number 304865: Emacs context keys
Pasted by: tsdh
When:5 years, 3 months ago
Share:Tweet this! |
Paste contents:
Raw Source | XML | Display As
(defmacro th/define-context-key (keymap key dispatch)
  "Define KEY in KEYMAP to execute according to DISPATCH.

DISPATCH is a form that is evaluated and should return the
command to be executed.

If DISPATCH returns nil, then the command normally bound to KEY
will be executed.


  (th/define-context-key hs-minor-mode-map
     (kbd \"<C-tab>\")
      ((not (hs-already-hidden-p))

This will make <C-tab> show a hidden block.  If the block is
shown, then it'll be hidden."
  `(define-key ,keymap ,key
     `(menu-item "context-key" ignore
		 :filter ,(lambda (&optional ignored)

;; Some usages

(th/define-context-key outline-minor-mode-map
		       (kbd "TAB")
		       (when (th/outline-context-p)

;; Jump out of a TeX macro when pressing TAB twice.
(th/define-context-key TeX-mode-map (kbd "TAB")
	 (when (and (= 1 (length (this-command-keys-vector)))
		    (equal last-command-event (elt (this-command-keys-vector) 0))

This paste has no annotations.

Colorize as:
Show Line Numbers

Lisppaste pastes can be made by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively.