branch: externals/ergoemacs-mode commit 3c06bbefe5c9c7b57aa4b341eda6c908ef6a3a76 Author: Walter Landry <wlan...@caltech.edu> Commit: Walter Landry <wlan...@caltech.edu>
Remove some command-loop code --- ergoemacs-command-loop.el | 214 ---------------------------------------------- ergoemacs-macros.el | 6 -- ergoemacs-test.el | 17 +--- 3 files changed, 3 insertions(+), 234 deletions(-) diff --git a/ergoemacs-command-loop.el b/ergoemacs-command-loop.el index 862a431..8842b09 100644 --- a/ergoemacs-command-loop.el +++ b/ergoemacs-command-loop.el @@ -1459,220 +1459,6 @@ run, by changing `this-command' to `last-command'" ;; FIXME: Somehow change the output of `this-single-command-raw-keys' nil) -(defun ergoemacs-command-loop--read-key-sequence (prompt &rest _ignore) - "Read key sequence in ergoemacs-mode with PROMPT. - -Ignore all the other options." - (let ((old ergoemacs-command-loop-type) - (old-prompt ergoemacs-command-loop--read-key-prompt) - ret) - (setq ergoemacs-command-loop-type :read-key-sequence - ergoemacs-command-loop--read-key-prompt prompt) - (unwind-protect - (setq ret (ergoemacs-command-loop--internal)) - (setq ergoemacs-command-loop-type old - ergoemacs-command-loop--read-key-prompt old-prompt)) - ret)) - -(defun ergoemacs-command-loop--internal (&optional key type initial-key-type universal initial-history) - "Read keyboard input and execute command. -The KEY is the keyboard input where the reading begins. If nil, -read the whole keymap. - -TYPE is the keyboard translation type, defined by `ergoemacs-translate' -Ergoemacs-mode sets up: :unchorded :normal. - -INITIAL-KEY-TYPE represents the translation type for the initial KEY. - -UNIVERSAL allows ergoemacs-read-key to start with universal -argument prompt. - -INITIAL-HISTORY is the initial history list to use. - -While in the loop, every command resets the keys typed every time -a command is completed (by `clear-this-command-keys') - -Also in the loop, `universal-argument-num-events' is set to -0. (Allows commands like `isearch' to work correctly in older -Emacs versions)." - (interactive) - (when ergoemacs-mode - ;; Call the startup command - (when (commandp ergoemacs-command-loop-start) - (ergoemacs-command-loop--call-interactively ergoemacs-command-loop-start) - (ergoemacs-command-loop--internal-end-command)) - ;; Replace functions temporarily - (cl-letf (((symbol-function 'this-command-keys) #'ergoemacs-command-loop--this-command-keys) - ((symbol-function 'this-single-command-keys) #'ergoemacs-command-loop--this-command-keys) - ((symbol-function 'this-command-keys-vector) #'ergoemacs-command-loop--this-command-keys) - ((symbol-function 'this-single-command-raw-keys) #'ergoemacs-command-loop--this-command-keys) - ;; ((symbol-function 'read-key-sequence) #'ergoemacs-command-loop--read-key-sequence) - ) - (let* ((type (or type :normal)) - (from-start-p ergoemacs-command-loop-start) - (continue-read t) - (first-type type) - raw-key current-key last-current-key - (translation (ergoemacs-translate--get type)) - (local-keymap (ergoemacs-translate--keymap translation)) - tmp command) - (unwind-protect - (progn - ;; Set these to nil when entering the command loop; - ;; - ;; For some reason `inhibit-point-motion-hooks' on emacs - ;; 25.1 is t when the command loop is entered. - ;; - ;; To allow the point motion hooks to work as - ;; advertised, set these on starting the command loop. - (setq inhibit-point-motion-hooks nil - disable-point-adjustment nil - global-disable-point-adjustment nil) - ;; Setup initial unread command events, first type and history - (setq tmp (ergoemacs-command-loop--listify-key-sequence key initial-key-type) - unread-command-events (or (and unread-command-events tmp (append tmp unread-command-events)) tmp) - ergoemacs-command-loop--first-type first-type - ergoemacs-command-loop--history initial-history - ergoemacs-command-loop-start nil) - (while continue-read - (setq ergoemacs-last-command-was-ergoemacs-ignore-p nil) - (unless (eq ergoemacs-command-loop-type :read-key-sequence) - (setq inhibit-quit t)) - (while continue-read - (setq ergoemacs-last-command-was-ergoemacs-ignore-p nil) - ;; Read key - (setq ergoemacs-command-loop--single-command-keys current-key - ergoemacs-command-loop--current-type type - ergoemacs-command-loop--universal universal - raw-key (ergoemacs-command-loop--read-key - current-key - (or (and unread-command-events :normal) type) - (and (not unread-command-events) universal)) - ergoemacs-command-loop--single-command-keys nil - universal-argument-num-events 0 - last-current-key current-key - current-key (nth 1 raw-key) - raw-key (nth 0 raw-key) - continue-read nil) - (cond - ;; Handle quit commands - ((and last-current-key - (or (lookup-key ergoemacs-map--quit-map raw-key) - (and (equal raw-key [27]) - (lookup-key ergoemacs-map--quit-map [escape])))) - (ergoemacs-command-loop--message - "Key sequence %s aborted by %s" - (ergoemacs-key-description last-current-key) - (ergoemacs-key-description raw-key)) - (setq quit-flag t)) - ;; Handle local commands. - ((and (not (equal current-key raw-key)) - (setq command (lookup-key local-keymap raw-key)) - (not (ergoemacs-keymapp command)) ;; Ignore locally - ;; Already handled by `ergoemacs-command-loop--read-key' - (not (ergoemacs-gethash command ergoemacs-command-loop--next-key-hash)) - ;; If a command has :ergoemacs-local property of :force, don't - ;; worry about looking up a key, just run the function. - (or (and (symbolp command) (eq (get command :ergoemacs-local) :force)) - (not (key-binding current-key t)))) - (pop ergoemacs-command-loop--history) ;; Don't recored local events - (setq ergoemacs-command-loop--single-command-keys last-current-key - universal-argument-num-events 0 - ergoemacs-command-loop--current-type type - ergoemacs-command-loop--universal universal - ergoemacs-command-loop--exit nil) - - (unless (eq ergoemacs-command-loop-type :test) - (setq tmp this-command - this-command command) - (ergoemacs-command-loop--call-interactively this-command) - (setq command this-command - this-command tmp)) - ;; If the command changed anything, fix it here. - (unless (equal type ergoemacs-command-loop--current-type) - (setq type ergoemacs-command-loop--current-type - translation (ergoemacs-translate--get type) - local-keymap (ergoemacs-translate--keymap translation))) - - (setq current-key ergoemacs-command-loop--single-command-keys - universal ergoemacs-command-loop--universal - ergoemacs-command-loop--single-command-keys nil - continue-read (not ergoemacs-command-loop--exit))) - ;; Handle any keys that are bound in some translatable way. - ((setq command (ergoemacs-command-loop--key-lookup current-key)) - ;; Setup external indicators of how the loop currently behaves. - (setq ergoemacs-command-loop--single-command-keys current-key - universal-argument-num-events 0 - ergoemacs-command-loop--current-type type - ergoemacs-command-loop--universal nil - ergoemacs-command-loop--exit t) - (if (setq continue-read (and (not (and (consp (aref current-key 0)) - (memq (event-basic-type (car (aref current-key 0))) - '(mouse-1 mouse-2 mouse-3 mouse-4 mouse-5 mouse-6 mouse-7 mouse-8 mouse-9)))) - (ergoemacs-keymapp command))) - (setq universal nil) - (unless (memq ergoemacs-command-loop-type '(:test :read-key-sequence)) - (with-local-quit - (ergoemacs-command-loop--execute command))) - - (when quit-flag - (ergoemacs-command-loop--message "Quit!")) - - ;; Change any information (if needed) - (unless (equal type ergoemacs-command-loop--current-type) - (setq type ergoemacs-command-loop--current-type - translation (ergoemacs-translate--get type) - local-keymap (ergoemacs-translate--keymap translation))) - - (when (eq ergoemacs-command-loop-type :read-key-sequence) - (setq ergoemacs-command-loop--exit t - continue-read nil - command current-key)) - - (setq current-key ergoemacs-command-loop--single-command-keys - universal ergoemacs-command-loop--universal - ergoemacs-command-loop--single-command-keys nil - continue-read (not ergoemacs-command-loop--exit) - current-prefix-arg (if ergoemacs-command-loop--universal current-prefix-arg prefix-arg)) - - (when (and (not continue-read) - (eq ergoemacs-command-loop--exit :ignore-post-command-hook)) - (setq continue-read t))) - - (when (or (not ergoemacs-command-loop--exit) - (and (not continue-read) (setq continue-read unread-command-events))) - (ergoemacs-command-loop--internal-end-command))) - (quit-flag - (ergoemacs-command-loop--message "Quit!") - (setq quit-flag nil - type :normal - first-type :normal - raw-key nil - current-key nil - translation (ergoemacs-translate--get type) - local-keymap (ergoemacs-translate--keymap translation) - ergoemacs-command-loop--first-type first-type - ergoemacs-command-loop--history nil)) - ((consp (aref current-key 0))) ;; don't complain about mouse keys - (t ;; Command not found exit. - (ergoemacs-command-loop--message "Key %s doesn't do anything." (ergoemacs-key-description current-key))))) - (unless quit-flag - (ergoemacs-command-loop--internal-end-command)) - (setq quit-flag nil - type :normal - continue-read (or unread-command-events (and from-start-p (ergoemacs-command-loop-full-p))) - first-type :normal - raw-key nil - current-key nil - translation (ergoemacs-translate--get type) - local-keymap (ergoemacs-translate--keymap translation) - ergoemacs-command-loop--first-type first-type - ergoemacs-command-loop--history nil) - (when (or (not ergoemacs-mode) (eq :read-key-sequence ergoemacs-command-loop-type)) - (setq continue-read nil))) - (setq inhibit-quit nil))) - command)))) - (defcustom ergoemacs-message-in-mode-line t "Display ergoemacs information in mode-line." :type 'boolean diff --git a/ergoemacs-macros.el b/ergoemacs-macros.el index 284c4c1..e25e442 100644 --- a/ergoemacs-macros.el +++ b/ergoemacs-macros.el @@ -869,12 +869,6 @@ When :type is :replace that replaces a function (like `define-key')" ((symbol-function 'describe-key) #'ergoemacs--real-describe-key)) ,@body)) -(defmacro ergoemacs-specials (&rest body) - "Use `ergoemacs-mode' special functions in BODY." - `(cl-letf (((symbol-function 'read-key-sequence) #'ergoemacs-command-loop--read-key-sequence) - ((symbol-function 'key-description) #'ergoemacs-key-description)) - ,@body)) - (defmacro ergoemacs-autoloadp (object) "Non-nil if OBJECT is an autoload." (cond diff --git a/ergoemacs-test.el b/ergoemacs-test.el index bfdf144..0bc6494 100644 --- a/ergoemacs-test.el +++ b/ergoemacs-test.el @@ -55,9 +55,7 @@ (declare-function ergoemacs-mode "ergoemacs-mode") -(declare-function ergoemacs-command-loop--internal "ergoemacs-command-loop") (declare-function ergoemacs-command-loop--mouse-command-drop-first "ergoemacs-command-loop") -(declare-function ergoemacs-command-loop--read-key-sequence "ergoemacs-command-loop") (declare-function ergoemacs-component-struct--lookup-hash "ergoemacs-compononent") @@ -567,11 +565,9 @@ Grep finished (matches found) at Fri Aug 22 08:30:37 "Test that unicode translations work. See Issue #138." (save-excursion - (unless ergoemacs-mode - (ergoemacs-mode)) (switch-to-buffer (get-buffer-create "*ergoemacs-test*")) (delete-region (point-min) (point-max)) - (ergoemacs-command-loop--internal "C-x 8 !") + (execute-kbd-macro (kbd "C-x 8 !")) (should (string= "¡" (buffer-string))) (kill-buffer (current-buffer)))) @@ -580,10 +576,8 @@ See Issue #138." See Issue #138." (save-excursion (switch-to-buffer (get-buffer-create "*ergoemacs-test*")) - (unless ergoemacs-mode - (ergoemacs-mode)) (delete-region (point-min) (point-max)) - (ergoemacs-command-loop--internal "C-x 8 \" A") + (execute-kbd-macro (kbd "C-x 8 \" A")) (should (string= "Ä" (buffer-string))) (kill-buffer (current-buffer)))) @@ -929,7 +923,7 @@ hash appropriaetly." (switch-to-buffer (get-buffer-create "*ergoemacs-test*")) (delete-region (point-min) (point-max)) (table-insert 1 2) - (ergoemacs-command-loop--internal "abc <tab> abc <tab>") + (execute-kbd-macro (kbd "abc <tab> abc <tab>")) (should (string= (buffer-string) "+-----+ |abc | +-----+ @@ -988,11 +982,6 @@ hash appropriaetly." (should (member [27 ?b] list)) list)) -(ert-deftest ergoemacs-test-issue-379 () - "Test infinite recursive event-modifiers." - :tags '(:translate) - (should (equal (ignore-errors (ergoemacs-specials (ergoemacs-translate--event-modifiers 134217755))) '(control meta)))) - (ert-deftest ergoemacs-test-temp-map-issue () "Test temporary map issue." (if (version-list-< (version-to-list "24.4") (version-to-list emacs-version))