Function: easy-mmode-define-keymap

easy-mmode-define-keymap is an autoloaded and byte-compiled function defined in easy-mmode.el.gz.

Signature

(easy-mmode-define-keymap BS &optional NAME M ARGS)

Documentation

Return a keymap built from bindings BS.

BS must be a list of (KEY . BINDING) where KEY and BINDINGS are suitable for define-key. Optional NAME is passed to make-sparse-keymap. Optional map M can be used to modify an existing map. ARGS is a list of additional keyword arguments.

Valid keywords and arguments are:

  :name Name of the keymap; overrides NAME argument.
  :dense Non-nil for a dense keymap.
  :inherit Parent keymap.
  :group Ignored.
  :suppress Non-nil to call suppress-keymap on keymap,
             nodigits to suppress digits as prefix arguments.

Probably introduced at or before Emacs version 20.1.

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/easy-mmode.el.gz
;;;###autoload
(defun easy-mmode-define-keymap (bs &optional name m args)
  "Return a keymap built from bindings BS.
BS must be a list of (KEY . BINDING) where
KEY and BINDINGS are suitable for `define-key'.
Optional NAME is passed to `make-sparse-keymap'.
Optional map M can be used to modify an existing map.
ARGS is a list of additional keyword arguments.

Valid keywords and arguments are:

  :name      Name of the keymap; overrides NAME argument.
  :dense     Non-nil for a dense keymap.
  :inherit   Parent keymap.
  :group     Ignored.
  :suppress  Non-nil to call `suppress-keymap' on keymap,
             `nodigits' to suppress digits as prefix arguments."
  (let (inherit dense suppress)
    (while args
      (let ((key (pop args))
	    (val (pop args)))
	(pcase key
	  (:name (setq name val))
	  (:dense (setq dense val))
	  (:inherit (setq inherit val))
	  (:suppress (setq suppress val))
	  (:group)
	 (_ (message "Unknown argument %s in defmap" key)))))
    (unless (keymapp m)
      (setq bs (append m bs))
      (setq m (if dense (make-keymap name) (make-sparse-keymap name))))
    (when suppress
      (suppress-keymap m (eq suppress 'nodigits)))
    (dolist (b bs)
      (let ((keys (car b))
	    (binding (cdr b)))
	(dolist (key (if (consp keys) keys (list keys)))
	  (cond
	   ((symbolp key)
	    (substitute-key-definition key binding m global-map))
	   ((null binding)
	    (unless (keymapp (lookup-key m key)) (define-key m key binding)))
	   ((let ((o (lookup-key m key)))
	      (or (null o) (numberp o) (eq o 'undefined)))
	    (define-key m key binding))))))
    (cond
     ((keymapp inherit) (set-keymap-parent m inherit))
     ((consp inherit) (easy-mmode-set-keymap-parents m inherit)))
    m))