emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/ergoemacs-mode 1421a65 06/87: Change how key prefixes a


From: Stefan Monnier
Subject: [elpa] externals/ergoemacs-mode 1421a65 06/87: Change how key prefixes are handled.
Date: Wed, 14 Apr 2021 18:46:57 -0400 (EDT)

branch: externals/ergoemacs-mode
commit 1421a65c51ff548bb53b8fad9ce2b7ae9fb98d62
Author: Fidler <matthew.fidler@gmail.com>
Commit: Fidler <matthew.fidler@gmail.com>

    Change how key prefixes are handled.
    
    May fix issues #441 and #439
---
 ergoemacs-command-loop.el | 56 +++++++++++++++++++++++++++++++++++++++--------
 ergoemacs-mapkeymap.el    | 12 +++++-----
 ergoemacs-mode.el         |  3 ++-
 3 files changed, 55 insertions(+), 16 deletions(-)

diff --git a/ergoemacs-command-loop.el b/ergoemacs-command-loop.el
index caa886a..5aa9301 100644
--- a/ergoemacs-command-loop.el
+++ b/ergoemacs-command-loop.el
@@ -308,10 +308,11 @@ with this function."
 This is called through `ergoemacs-command-loop'"
   (interactive)
   (cond
-   ;; ((not (ergoemacs :command-loop-p))
-   ;;  ;; Command loop hasn't started.
-   ;;  (setq current-prefix-arg '(4))
-   ;;  (ergoemacs-command-loop nil type nil t))
+   ((not (ergoemacs-command-loop-p)) 
+    ;; Command loop hasn't started.
+    (setq current-prefix-arg '(4))
+    (setq ergoemacs-command-loop-start t)
+    (ergoemacs-command-loop nil (ergoemacs-command-loop--modal-p) nil t))
    ((not current-prefix-arg)
     (setq current-prefix-arg '(4)
           ergoemacs-command-loop--universal t
@@ -1040,7 +1041,7 @@ This sequence is compatible with `listify-key-sequence'."
   "Determine if `ergoemacs-mode' is running its command loop.
 This is done by looking at the current `backtrace' and making
 sure that `ergoemacs-command-loop--internal' hasn't been called."
-  (eq ergoemacs-last-command-event last-command-event))
+  (eq (symbol-function 'this-command-keys) 
#'ergoemacs-command-loop--this-command-keys))
 
 (defvar ergoemacs-command-loop-start nil)
 (defun ergoemacs-command-loop (&optional key type initial-key-type universal)
@@ -1059,7 +1060,7 @@ argument.
 The true work is done in `ergoemacs-command-loop--internal'."
   (interactive)
   (cond
-   ((and ergoemacs-command-loop-start (not (ergoemacs-command-loop-p)))
+   ((and (or ergoemacs-command-loop-start key) (not 
(ergoemacs-command-loop-p)))
     ;; (ergoemacs-command-loop--message "Start ergoemacs-mode command loop." )
     (ergoemacs-command-loop--internal key type initial-key-type universal))
    (t
@@ -1102,10 +1103,13 @@ appropriate value based on the COMMAND."
       (set (make-local-variable 
'ergoemacs-command-loop--minibuffer-unsupported-p) t))
     (ergoemacs-command-loop--minibuffer-supported-p)))
 
-(defun ergoemacs-command-loop-full-p ()
-  "Determines if the full command loop should be run."
+(defun ergoemacs-command-loop-full-p (&optional type )
+  "Determines if the full command loop should be run.
+
+TYPE is the type of command loop to check for.  By default this
+is the :full command loop."
   (and
-   (eq ergoemacs-command-loop-type :full)
+   (or (eq ergoemacs-command-loop-type (or type :full)) (ergoemacs :modal-p))
    (ergoemacs-command-loop--minibuffer-supported-p)
    (catch 'excluded-variables
      (dolist (var ergoemacs-command-loop--excluded-variables)
@@ -1114,6 +1118,40 @@ appropriate value based on the COMMAND."
      t)
    (not (memq major-mode ergoemacs-command-loop--excluded-major-modes))))
 
+(defun ergoemacs-command-loop-prefix-timer-p ()
+  "Determines if the command loop is run for a prefix timer."
+  (ergoemacs-command-loop-full-p :prefix-timer))
+
+(defvar ergoemacs-command-loop--prefix-timer-polling-time 0.1
+  "Timer for polling of prefix keys.")
+
+(defvar ergoemacs-command-loop--prefix-timer nil)
+
+(defun ergoemacs-command-loop--prefix-timer ()
+  "Start prefix timer for ergoemacs-mode command loop."
+  (when (and (null ergoemacs-command-loop--prefix-timer)
+            (eq ergoemacs-command-loop-type :prefix-timer))
+    (setq ergoemacs-command-loop--prefix-timer
+         (run-at-time t ergoemacs-command-loop--prefix-timer-polling-time 
#'ergoemacs-command-loop--start-for-prefix))))
+
+(defun ergoemacs-command-loop--stop-prefix-timer ()
+  "Stop prefix timer for ergoemacs-mode command loop."
+  (when ergoemacs-command-loop--prefix-timer
+    (cancel-timer ergoemacs-command-loop--prefix-timer)
+    (setq ergoemacs-command-loop--prefix-timer nil)))
+
+(defun ergoemacs-command-loop--start-for-prefix ()
+  "Start the ergoemacs command loop for the currently running prefix key."
+  (when (and (not (ergoemacs :modal-p))
+            (ergoemacs-command-loop-prefix-timer-p)
+            (ergoemacs-keymapp (key-binding (this-single-command-keys)))
+             (not (ergoemacs-command-loop-p)))
+    (setq ergoemacs-command-loop-start t
+         ergoemacs-command-loop--single-command-keys 
(this-single-command-keys))
+    (ergoemacs-command-loop ergoemacs-command-loop--single-command-keys)))
+
+(add-hook 'ergoemacs-mode-startup-hook 
#'ergoemacs-command-loop--start-for-prefix)
+
 (defun ergoemacs-command-loop--start-with-pre-command-hook ()
   "Start ergoemacs command loop.
 
diff --git a/ergoemacs-mapkeymap.el b/ergoemacs-mapkeymap.el
index f7c52cc..cb08017 100644
--- a/ergoemacs-mapkeymap.el
+++ b/ergoemacs-mapkeymap.el
@@ -84,8 +84,7 @@ If `ergoemacs-mode' cant determine the value, return nil."
                           (and (fboundp keymap) (setq tmp (symbol-function 
keymap))
                                (ergoemacs-keymapp tmp) tmp))))))))
 
-(defvar ergoemacs-map-keymap--submap-stack nil)
-
+(defvar ergoemacs-map-keymap--map-submap-last-map nil)
 (defun ergoemacs-map-keymap--map-submap (sub-keymap function &optional 
original prefix flat-keymap nil-keys)
   "Expose SUB-KEYMAP, then apply `ergoemacs-map-keymap'.
 
@@ -97,8 +96,8 @@ FLAT-KEYMAP and NIL-KEYS arguments.  It is missing the keymap
 argument, since it is calculated from the exposed sub-keymap."
   (let ((tmp (ergoemacs-map-keymap--expose-keymap sub-keymap)))
     (when tmp
-      (unless (memq tmp ergoemacs-map-keymap--submap-stack)
-       (push tmp ergoemacs-map-keymap--submap-stack)
+      (unless (eq ergoemacs-map-keymap--map-submap-last-map tmp)
+       (setq ergoemacs-map-keymap--map-submap-last-map tmp)
        (ergoemacs-map-keymap function
                               (cond
                                ((eq original :setcdr)
@@ -107,8 +106,7 @@ argument, since it is calculated from the exposed 
sub-keymap."
                                (original
                                 (ergoemacs :original tmp))
                                (t tmp))
-                              original prefix flat-keymap nil-keys)
-       (pop ergoemacs-map-keymap--submap-stack)))))
+                              original prefix flat-keymap nil-keys)))))
 
 (defun ergoemacs-map-keymap (function keymap &optional original prefix 
flat-keymap nil-keys)
   "Call FUNCTION for all keys in hash table KEYMAP.
@@ -141,6 +139,8 @@ them to be masked when mapping over the keymap."
         calc-parent-p
         prefix-map
         tmp)
+    (when (not prefix)
+      (setq ergoemacs-map-keymap--map-submap-last-map nil))
     (when (ergoemacs-keymapp keymap)
       (map-keymap
        (lambda(event item)
diff --git a/ergoemacs-mode.el b/ergoemacs-mode.el
index c18fd42..618c6b9 100644
--- a/ergoemacs-mode.el
+++ b/ergoemacs-mode.el
@@ -972,10 +972,11 @@ Valid values are:
 
 (define-obsolete-variable-alias 'ergoemacs-read-swaps 
'ergoemacs-command-loop-swap-translation)
 
-(defcustom ergoemacs-command-loop-type :full
+(defcustom ergoemacs-command-loop-type :prefix-timer
   "Type of `ergoemacs-mode' command loop."
   :type '(choice
           (const :tag "Replace emacs command loop (full)" :full)
+         (const :tag "Use command loop on prefix keys by timer" :prefix-timer)
           ;; (const :tag "Test mode; Don't actually run command " :test)
           (const :tag "No command loop support" nil))
   :group 'ergoemacs-comamnd-loop)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]