aboutsummaryrefslogtreecommitdiff
path: root/sx.el
diff options
context:
space:
mode:
authorArtur Malabarba <bruce.connor.am@gmail.com>2015-01-05 16:31:10 -0200
committerArtur Malabarba <bruce.connor.am@gmail.com>2015-01-05 16:31:10 -0200
commite061fb947a02290314be7247d81963e7bfd0987b (patch)
tree63fd0fe99a0e5970a9bcf6319e5c22fb6b97859b /sx.el
parent51b5f280119745074e9d16042b5608f25cbb6e06 (diff)
Move define-conditional-key to sx.el
Diffstat (limited to 'sx.el')
-rw-r--r--sx.el12
1 files changed, 12 insertions, 0 deletions
diff --git a/sx.el b/sx.el
index 9924308..bfc647d 100644
--- a/sx.el
+++ b/sx.el
@@ -247,6 +247,18 @@ Anything before the (sub)domain is removed."
(rx string-start (or (and (0+ word) (optional ":") "//")))
"" url)))
+(defmacro sx--define-conditional-key (keymap key def &rest body)
+ "In KEYMAP, define key sequence KEY as DEF conditionally.
+This is like `define-key', except the definition \"disapears\"
+whenever BODY evaluates to nil."
+ (declare (indent 3)
+ (debug (form form form &rest sexp)))
+ `(define-key ,keymap ,key
+ '(menu-item
+ ,(format "maybe-%s" (or (car (cdr-safe def)) def)) ignore
+ :filter (lambda (&optional _)
+ (when (progn ,@body) ,def)))))
+
;;; Printing request data
(defvar sx--overlays nil