mirror of
https://github.com/emacs-exwm/exwm.git
synced 2025-01-22 16:08:00 +01:00
Use defvar-keymap and keymap-set instead of define-key (#108)
Emacs 29+ encourages these functions over define-key, so use them. We still use define-key in simulation keys because we need to process raw key definitions (vectors, not strings). * exwm-core.el (exwm-mode-map, exwm--kmacro-map): Use defvar-keymap. (exwm--kmacro-self-insert-command): change the kmacro self-insert command from a lambda to a function. * exwm-workspace.el (exwm-workspace--init-switch-map): Use keymap-set. (exwm-workspace--switch-map-nth-prefix): Use keymap-set.
This commit is contained in:
parent
f5fa4b885b
commit
578e37e0e8
2 changed files with 56 additions and 58 deletions
64
exwm-core.el
64
exwm-core.el
|
@ -283,40 +283,38 @@ One of `line-mode' or `char-mode'.")
|
||||||
;; _MOTIF_WM_HINTS
|
;; _MOTIF_WM_HINTS
|
||||||
(defvar-local exwm--mwm-hints-decorations t)
|
(defvar-local exwm--mwm-hints-decorations t)
|
||||||
|
|
||||||
(defvar exwm-mode-map
|
(defvar-keymap exwm-mode-map
|
||||||
(let ((map (make-sparse-keymap)))
|
:doc "Keymap for `exwm-mode'."
|
||||||
(define-key map "\C-c\C-d\C-l" #'xcb-debug:clear)
|
"C-c C-d C-l" #'xcb-debug:clear
|
||||||
(define-key map "\C-c\C-d\C-m" #'xcb-debug:mark)
|
"C-c C-d C-m" #'xcb-debug:mark
|
||||||
(define-key map "\C-c\C-d\C-t" #'exwm-debug-mode)
|
"C-c C-d C-t" #'exwm-debug-mode
|
||||||
(define-key map "\C-c\C-f" #'exwm-layout-set-fullscreen)
|
"C-c C-f" #'exwm-layout-set-fullscreen
|
||||||
(define-key map "\C-c\C-h" #'exwm-floating-hide)
|
"C-c C-h" #'exwm-floating-hide
|
||||||
(define-key map "\C-c\C-k" #'exwm-input-release-keyboard)
|
"C-c C-k" #'exwm-input-release-keyboard
|
||||||
(define-key map "\C-c\C-m" #'exwm-workspace-move-window)
|
"C-c C-m" #'exwm-workspace-move-window
|
||||||
(define-key map "\C-c\C-q" #'exwm-input-send-next-key)
|
"C-c C-q" #'exwm-input-send-next-key
|
||||||
(define-key map "\C-c\C-t\C-f" #'exwm-floating-toggle-floating)
|
"C-c C-t C-f" #'exwm-floating-toggle-floating
|
||||||
(define-key map "\C-c\C-t\C-m" #'exwm-layout-toggle-mode-line)
|
"C-c C-t C-m" #'exwm-layout-toggle-mode-line)
|
||||||
map)
|
|
||||||
"Keymap for `exwm-mode'.")
|
|
||||||
|
|
||||||
(defvar exwm--kmacro-map
|
(defun exwm--kmacro-self-insert-command ()
|
||||||
(let ((map (make-sparse-keymap)))
|
"The EXWM kmacro equivalent of `self-insert-command'."
|
||||||
(define-key map [t]
|
(interactive)
|
||||||
(lambda ()
|
(cond
|
||||||
(interactive)
|
((or exwm-input-line-mode-passthrough
|
||||||
(cond
|
(active-minibuffer-window)
|
||||||
((or exwm-input-line-mode-passthrough
|
(memq last-input-event exwm-input--global-prefix-keys)
|
||||||
(active-minibuffer-window)
|
(memq last-input-event exwm-input-prefix-keys)
|
||||||
(memq last-input-event exwm-input--global-prefix-keys)
|
(lookup-key exwm-mode-map (vector last-input-event))
|
||||||
(memq last-input-event exwm-input-prefix-keys)
|
(gethash last-input-event exwm-input--simulation-keys))
|
||||||
(lookup-key exwm-mode-map (vector last-input-event))
|
(set-transient-map (make-composed-keymap (list exwm-mode-map global-map)))
|
||||||
(gethash last-input-event exwm-input--simulation-keys))
|
(push last-input-event unread-command-events))
|
||||||
(set-transient-map (make-composed-keymap (list exwm-mode-map
|
(t
|
||||||
global-map)))
|
(exwm-input--fake-key last-input-event))))
|
||||||
(push last-input-event unread-command-events))
|
(put 'exwm--kmacro-self-insert-command 'completion-predicate #'ignore)
|
||||||
(t
|
|
||||||
(exwm-input--fake-key last-input-event)))))
|
(defvar-keymap exwm--kmacro-map
|
||||||
map)
|
:doc "Keymap used when executing keyboard macros."
|
||||||
"Keymap used when executing keyboard macros.")
|
"<t>" #'exwm--kmacro-self-insert-command)
|
||||||
|
|
||||||
;; This menu mainly acts as an reminder for users. Thus it should be as
|
;; This menu mainly acts as an reminder for users. Thus it should be as
|
||||||
;; detailed as possible, even some entries do not make much sense here.
|
;; detailed as possible, even some entries do not make much sense here.
|
||||||
|
|
|
@ -175,12 +175,12 @@ FRAME may be either a workspace frame or a workspace position."
|
||||||
(defun exwm-workspace--init-switch-map ()
|
(defun exwm-workspace--init-switch-map ()
|
||||||
"Initialize variable `exwm-workspace--switch-map'."
|
"Initialize variable `exwm-workspace--switch-map'."
|
||||||
(let ((map (make-sparse-keymap)))
|
(let ((map (make-sparse-keymap)))
|
||||||
(define-key map [t] (lambda () (interactive)))
|
(keymap-set map "<t>" #'ignore)
|
||||||
(define-key map "+" #'exwm-workspace--prompt-add)
|
(keymap-set map "+" #'exwm-workspace--prompt-add)
|
||||||
(define-key map "-" #'exwm-workspace--prompt-delete)
|
(keymap-set map "-" #'exwm-workspace--prompt-delete)
|
||||||
(dotimes (i 10)
|
(dotimes (i 10)
|
||||||
(define-key map (int-to-string i)
|
(keymap-set map (int-to-string i)
|
||||||
#'exwm-workspace--switch-map-nth-prefix))
|
#'exwm-workspace--switch-map-nth-prefix))
|
||||||
(unless (eq exwm-workspace-index-map #'number-to-string)
|
(unless (eq exwm-workspace-index-map #'number-to-string)
|
||||||
;; Add extra (and possibly override) keys for selecting workspace.
|
;; Add extra (and possibly override) keys for selecting workspace.
|
||||||
(dotimes (i 10)
|
(dotimes (i 10)
|
||||||
|
@ -188,25 +188,25 @@ FRAME may be either a workspace frame or a workspace position."
|
||||||
(when (and (stringp key)
|
(when (and (stringp key)
|
||||||
(= (length key) 1)
|
(= (length key) 1)
|
||||||
(<= 0 (elt key 0) 127))
|
(<= 0 (elt key 0) 127))
|
||||||
(define-key map key
|
(keymap-set map key
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(interactive)
|
(interactive)
|
||||||
(exwm-workspace--switch-map-select-nth i)))))))
|
(exwm-workspace--switch-map-select-nth i)))))))
|
||||||
(define-key map "\C-a" (lambda () (interactive) (goto-history-element 1)))
|
(keymap-set map "C-a" (lambda () (interactive) (goto-history-element 1)))
|
||||||
(define-key map "\C-e" (lambda ()
|
(keymap-set map "C-e" (lambda ()
|
||||||
(interactive)
|
(interactive)
|
||||||
(goto-history-element (exwm-workspace--count))))
|
(goto-history-element (exwm-workspace--count))))
|
||||||
(define-key map "\C-g" #'abort-recursive-edit)
|
(keymap-set map "C-g" #'abort-recursive-edit)
|
||||||
(define-key map "\C-]" #'abort-recursive-edit)
|
(keymap-set map "C-]" #'abort-recursive-edit)
|
||||||
(define-key map "\C-j" #'exit-minibuffer)
|
(keymap-set map "C-j" #'exit-minibuffer)
|
||||||
;; (define-key map "\C-m" #'exit-minibuffer) ;not working
|
;; (keymap-set map "\C-m" #'exit-minibuffer) ;not working
|
||||||
(define-key map [return] #'exit-minibuffer)
|
(keymap-set map "<return>" #'exit-minibuffer)
|
||||||
(define-key map " " #'exit-minibuffer)
|
(keymap-set map "<space>" #'exit-minibuffer)
|
||||||
(define-key map "\C-f" #'previous-history-element)
|
(keymap-set map "C-f" #'previous-history-element)
|
||||||
(define-key map "\C-b" #'next-history-element)
|
(keymap-set map "C-b" #'next-history-element)
|
||||||
;; Alternative keys
|
;; Alternative keys
|
||||||
(define-key map [right] #'previous-history-element)
|
(keymap-set map "<right>" #'previous-history-element)
|
||||||
(define-key map [left] #'next-history-element)
|
(keymap-set map "<left>" #'next-history-element)
|
||||||
(setq exwm-workspace--switch-map map)))
|
(setq exwm-workspace--switch-map map)))
|
||||||
|
|
||||||
(defun exwm-workspace--workspace-from-frame-or-index (frame-or-index)
|
(defun exwm-workspace--workspace-from-frame-or-index (frame-or-index)
|
||||||
|
@ -543,9 +543,9 @@ PREFIX-DIGITS is a list of the digits introduced so far."
|
||||||
(interactive)
|
(interactive)
|
||||||
(exwm-workspace--switch-map-nth-prefix digits)))))
|
(exwm-workspace--switch-map-nth-prefix digits)))))
|
||||||
(dotimes (i 10)
|
(dotimes (i 10)
|
||||||
(define-key map (int-to-string i) cmd))
|
(keymap-set map (int-to-string i) cmd))
|
||||||
;; Accept
|
;; Accept
|
||||||
(define-key map [return]
|
(keymap-set map "<return>"
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(interactive)
|
(interactive)
|
||||||
(exwm-workspace--switch-map-select-nth n)))
|
(exwm-workspace--switch-map-select-nth n)))
|
||||||
|
|
Loading…
Reference in a new issue