Skip to content

Commit

Permalink
Use lexical bindings
Browse files Browse the repository at this point in the history
Because `mapatoms' does not consider lexically bound variables
`kmu-keymap-variable', `kmu-keymap-prefix-command' and
`kmu-keymap-parent' no longer have to explicitly ignore their
own locally bound variables.
  • Loading branch information
tarsius committed Apr 13, 2020
1 parent 5c897a8 commit 195e0ca
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions keymap-utils.el
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
;;; keymap-utils.el --- keymap utilities
;;; keymap-utils.el --- keymap utilities -*- lexical-binding: t; -*-

;; Copyright (C) 2008-2020 Jonas Bernoulli

Expand Down Expand Up @@ -104,7 +104,7 @@ the parent keymap of any keymap a key in KEYMAP is bound to."
(cl-labels ((strip-keymap
(keymap)
(set-keymap-parent keymap nil)
(cl-loop for key being the key-code of keymap
(cl-loop for _key being the key-code of keymap
using (key-binding binding) do
(and (keymapp binding)
(not (kmu-prefix-command-p binding))
Expand Down Expand Up @@ -143,7 +143,7 @@ Interactively also show the variable in the echo area."
mapvar))

(defun kmu-keymap-variable (keymap &rest exclude)
"Return a symbol whose value is KEYMAP.
"Return a dynamically-bound symbol whose value is KEYMAP.
Comparison is done with `eq'. If there are multiple variables
whose value is KEYMAP it is undefined which is returned.
Expand All @@ -152,45 +152,45 @@ Ignore symbols listed in optional EXCLUDE. Use this to prevent a
symbol from being returned which is dynamically bound to KEYMAP."
(and (keymapp keymap)
(catch 'found
(setq exclude (append '(keymap --symbol--) exclude))
(mapatoms (lambda (--symbol--)
(and (not (memq --symbol-- exclude))
(boundp --symbol--)
(eq (symbol-value --symbol--) keymap)
(throw 'found --symbol--)))))))
(mapatoms (lambda (sym)
(and (not (memq sym exclude))
(boundp sym)
(eq (symbol-value sym) keymap)
(throw 'found sym)))))))

(defun kmu-keymap-prefix-command (keymap)
"Return a symbol whose function definition is KEYMAP.
"Return a dynamically-bound symbol whose function definition is KEYMAP.
Comparison is done with `eq'. If there are multiple symbols
whose function definition is KEYMAP it is undefined which is
returned."
(and (keymapp keymap)
(catch 'found
(mapatoms (lambda (--symbol--)
(and (fboundp --symbol--)
(eq (symbol-function --symbol--) keymap)
(throw 'found --symbol--)))))))
(mapatoms (lambda (sym)
(and (fboundp sym)
(eq (symbol-function sym) keymap)
(throw 'found sym)))))))

(defun kmu-keymap-parent (keymap &optional need-symbol &rest exclude)
"Return the parent keymap of KEYMAP.
If a variable exists whose value is KEYMAP's parent keymap return
that. Otherwise if KEYMAP does not have a parent keymap return
nil. Otherwise if KEYMAP has a parent keymap but no variable is
bound to it return the parent keymap, unless optional NEED-SYMBOL
is non-nil in which case nil is returned.
If a dynamically-bound variable exists whose value is KEYMAP's
parent keymap return that. Otherwise if KEYMAP does not have
a parent keymap return nil. Otherwise if KEYMAP has a parent
keymap but no variable is bound to it return the parent keymap,
unless optional NEED-SYMBOL is non-nil in which case nil is
returned.
Comparison is done with `eq'. If there are multiple variables
whose value is the keymap it is undefined which is returned.
Ignore symbols listed in optional EXCLUDE. Use this to prevent
a symbol from being returned which is dynamically bound to the
parent keymap."
(let ((--parmap-- (keymap-parent keymap)))
(and --parmap--
(or (apply #'kmu-keymap-variable --parmap-- '--parmap-- exclude)
(and (not need-symbol) --parmap--)))))
(let ((parent (keymap-parent keymap)))
(and parent
(or (apply #'kmu-keymap-variable parent exclude)
(and (not need-symbol) parent)))))

(defun kmu-mapvar-list (&optional exclude-prefix-commands)
"Return a list of all keymap variables.
Expand Down

0 comments on commit 195e0ca

Please sign in to comment.