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

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

[elpa] 21/117: Better guide-key support


From: Matthew Fidler
Subject: [elpa] 21/117: Better guide-key support
Date: Fri, 25 Jul 2014 13:23:56 +0000

mlf176f2 pushed a commit to branch externals/ergoemacs-mode
in repository elpa.

commit 90ca177197412f3c40912051fd47aade5f500cb3
Author: Matthew L. Fidler <address@hidden>
Date:   Tue Jul 15 13:52:10 2014 -0500

    Better guide-key support
---
 ergoemacs-advices.el   |   41 ++++++++++++++++++++++-------------------
 ergoemacs-shortcuts.el |   42 ++++++++++++++++++++++++++++++++----------
 2 files changed, 54 insertions(+), 29 deletions(-)

diff --git a/ergoemacs-advices.el b/ergoemacs-advices.el
index bb4e07e..648003b 100644
--- a/ergoemacs-advices.el
+++ b/ergoemacs-advices.el
@@ -69,25 +69,6 @@ If `pre-command-hook' is used and `ergoemacs-mode' is remove 
from `ergoemacs-pre
         ergoemacs-read-no-shortcut-keys)
     ad-do-it))
 
-(defvar ergoemacs-read-key-last nil)
-(defadvice popwin:popup-buffer (around 
ergoemacs-popwin:close-popup-window-if-necessary activate)
-  "Saves `ergoemacs-read-key' before popping up a window."
-  (when (and ergoemacs-mode ergoemacs-read-key)
-    (setq ergoemacs-read-key-last ergoemacs-read-key))
-  ad-do-it)
-
-(defadvice popwin:close-popup-window-if-necessary (around 
ergoemacs-popwin:close-popup-window-if-necessary activate)
-  "Allows popup-window to be active while reading an `ergoemacs-mode' key via 
`ergoemacs-read-key'"
-  (cond
-   ((and ergoemacs-mode ergoemacs-read-key ergoemacs-read-key-last
-         (equal ergoemacs-read-key-last ergoemacs-read-key))
-    nil)
-   ((and ergoemacs-mode ergoemacs-read-key ergoemacs-read-key-last
-         (not (equal ergoemacs-read-key-last ergoemacs-read-key)))
-    (setq ergoemacs-read-key-last nil)
-    (popwin:close-popup-window))
-   (t ad-do-it)))
-
 (defadvice define-key (around ergoemacs-define-key-advice (keymap key def) 
activate)
   "This does the right thing when modifying `ergoemacs-keymap'.
 Also adds keymap-flag for user-defined keys run with `run-mode-hooks'."
@@ -178,6 +159,28 @@ Also adds keymap-flag for user-defined keys run with 
`run-mode-hooks'."
     (when oee ;; Add them back.  Now icy-mode should play nice.
       (ergoemacs-mode 1))))
 
+(defadvice guide-key/close-guide-buffer (around 
ergoemacs-guide-key/close-guide-buffer activate)
+  "Don't close guide buffer when reading ergoemacs-mode keys."
+  (unless (and ergoemacs-mode ergoemacs-read-key
+               ergoemacs-read-key-last-help
+               (equal ergoemacs-read-key-last-help ergoemacs-read-key))
+    ad-do-it))
+
+(defadvice guide-key/format-guide-buffer (around 
ergoemacs-guide-key/format-guide-buffer-advice (key-seq &optional regexp) 
activate)
+  "Format keys in `ergoemacs-mode' style"
+  (when ergoemacs-mode
+    (goto-char (point-min))
+    (while (re-search-forward (format"^%s \\([^ \t]+\\)" (regexp-quote 
(key-description key-seq))) nil t)
+      (replace-match (concat (key-description key-seq) " " (substring 
(ergoemacs-pretty-key (match-string 1)) 1 -1)) t t)))
+  ad-do-it
+  (when (and ergoemacs-mode ergoemacs-use-unicode-brackets)
+    (goto-char (point-min))
+    (while (re-search-forward "\\(^\\|  \\)\\[" nil t)
+      (replace-match (format "\\1%s" (ergoemacs-unicode-char "【" "[")))
+      (skip-chars-forward "^\\]")
+      (when (looking-at "\\]")
+        (replace-match (ergoemacs-unicode-char "】" "]"))))))
+
 (defcustom ergoemacs-helm-expand-user-dirs 't
   "Expand user directories under helm.
 This makes helm behave more like `ido-find-file'"
diff --git a/ergoemacs-shortcuts.el b/ergoemacs-shortcuts.el
index 4e2e76b..caea96f 100644
--- a/ergoemacs-shortcuts.el
+++ b/ergoemacs-shortcuts.el
@@ -495,7 +495,11 @@ It will replace anything defined by 
`ergoemacs-translation'"
       (ergoemacs-read-key-install-next-key next-key key pretty kbd))))
 
 (defvar guide-key-mode)
+(defvar guide-key/guide-key-sequence)
 (declare-function guide-key/popup-function "guide-key.el")
+(declare-function guide-key/close-guide-buffer "guide-key.el")
+(declare-function guide-key/popup-guide-buffer-p "guide-key.el")
+(defvar ergoemacs-read-key-last-help nil)
 (defvar ergoemacs-read-key nil
   "Current key for `ergoemacs-read-key'")
 (defun ergoemacs-read-key-help ()
@@ -505,7 +509,16 @@ It will replace anything defined by 
`ergoemacs-translation'"
   (if (not ergoemacs-read-key) nil
     (if guide-key-mode
         (let ((key ergoemacs-read-key))
-          (guide-key/popup-function key)
+          (if (equal ergoemacs-read-key-last-help ergoemacs-read-key)
+              (progn
+                (setq ergoemacs-read-key-last-help nil)
+                (setq guide-key/guide-key-sequence (delete (key-description 
ergoemacs-read-key) guide-key/guide-key-sequence))
+                (guide-key/close-guide-buffer))
+            ;; Not using pushnew because the test is equal and
+            ;; guide-key/guide-key-sequence is a global variable.
+            (add-to-list 'guide-key/guide-key-sequence (key-description 
ergoemacs-read-key))
+            (setq ergoemacs-read-key-last-help ergoemacs-read-key)
+            (guide-key/popup-function key))
           t)
       (let ((cb (current-buffer))
             (key ergoemacs-read-key))
@@ -593,7 +606,6 @@ It will replace anything defined by `ergoemacs-translation'"
 (defvar keyfreq-mode)
 (defvar ergoemacs-this-command)
 (defvar keyfreq-table)
-(defvar ergoemacs-read-key-last)
 (declare-function ergoemacs-emulations "ergoemacs-mode.el")
 (declare-function ergoemacs-smart-function-p "ergoemacs-model.el")
 (defvar ergoemacs-test-fn nil
@@ -622,7 +634,9 @@ In addition, when the function is called:
 
 "
   (setq ergoemacs-deactivate-mark nil)
-  (setq ergoemacs-read-key-last [ergoemacs-read-key-call])
+  (when (and ergoemacs-read-key-last-help guide-key-mode)
+    (setq ergoemacs-read-key-last-help nil)
+    (guide-key/close-guide-buffer))
   (cond
    (ergoemacs-test-fn
     (setq ergoemacs-test-fn function))
@@ -1011,6 +1025,8 @@ argument prompt.
 "
   (setq ergoemacs-deactivate-mark nil)
   (let ((continue-read t)
+        (guide-key/guide-key-sequence '())
+        (guide-key/recursive-key-sequence-flag t)
         (real-type (or type 'normal))
         (first-type (or type 'normal))
         deactivate-mark
@@ -1041,6 +1057,11 @@ argument prompt.
         (setq type real-type)
         (setq curr-universal first-universal)
         (setq real-type nil))
+      (when (and ergoemacs-read-key guide-key-mode
+                 (not (equal ergoemacs-read-key-last-help ergoemacs-read-key))
+                 (guide-key/popup-guide-buffer-p ergoemacs-read-key))
+        (setq ergoemacs-read-key-last-help ergoemacs-read-key)
+        (guide-key/popup-function ergoemacs-read-key))
       (setq real-read (not ergoemacs--input))
       (setq base (concat ":" (symbol-name type))
             next-key (vector
@@ -1057,9 +1078,11 @@ argument prompt.
           (cond
            ((and (not ergoemacs-read-key))
             (ergoemacs-keyboard-quit))
-           (ergoemacs-read-key-last
-            (setq ergoemacs-read-key-last [exit-by-escape]
-                  continue-read t))
+           ((and ergoemacs-read-key-last-help guide-key-mode)
+            (setq ergoemacs-read-key-last-help nil
+                  guide-key/guide-key-sequence (delete (key-description 
ergoemacs-read-key) guide-key/guide-key-sequence)
+                  continue-read t)
+            (guide-key/close-guide-buffer))
            (t (unless (minibufferp)
                 (let (message-log-max)
                   (setq tmp (gethash type ergoemacs-translation-text))
@@ -1335,13 +1358,12 @@ argument prompt.
                   (beep)
                   (unless (minibufferp)
                     (let (message-log-max)
-                      (message "%s is undefined!" pretty-key-undefined)))))))))
-      (when (fboundp 'popwin:close-popup-window-if-necessary)
-        (popwin:close-popup-window-if-necessary))))
+                      (message "%s is undefined!" 
pretty-key-undefined)))))))))))
   (when ergoemacs-deactivate-mark
     (setq deactivate-mark ergoemacs-deactivate-mark
           ergoemacs-mark-active nil))
-  (setq ergoemacs-describe-key nil))
+  (setq ergoemacs-describe-key nil
+        ergoemacs-read-key-last-help nil))
 
 (defun ergoemacs-read-key-default (&optional arg)
   "The default command for `ergoemacs-mode' read-key.



reply via email to

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