Set the current buffer before handling key events

There's no guarantee that the global current buffer matches the selected
window's buffer. For example, the following  will output "*Messages*" regardless
of the actual current buffer:

  (progn
    (run-at "1 sec" nil (lambda ()
                          (with-current-buffer (get-buffer "*Messages*")
                            (sit-for 5))))
    (run-at "2 sec" nil (lambda () (message (buffer-name)))))

* exwm-input.el (exwm-input--on-KeyPress): Set the current buffer to selected
window's current buffer.
This commit is contained in:
Steven Allen 2019-10-06 08:28:03 +09:00
parent 1e9be0de38
commit f14bd2a110

View file

@ -441,6 +441,7 @@ ARGS are additional arguments to CALLBACK."
(defun exwm-input--on-KeyPress (data _synthetic)
"Handle KeyPress event."
(with-current-buffer (window-buffer (selected-window))
(let ((obj (make-instance 'xcb:KeyPress)))
(xcb:unmarshal obj data)
(exwm--log "major-mode=%s buffer=%s"
@ -452,7 +453,7 @@ ARGS are additional arguments to CALLBACK."
(char-mode
(exwm-input--on-KeyPress-char-mode obj data)))
(exwm-input--on-KeyPress-char-mode obj)))
(run-hooks 'exwm-input--event-hook))
(run-hooks 'exwm-input--event-hook)))
(defun exwm-input--on-CreateNotify (data _synthetic)
"Handle CreateNotify events."