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

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

[elpa] 46/287: Fix Issue #7


From: Matthew Fidler
Subject: [elpa] 46/287: Fix Issue #7
Date: Wed, 02 Jul 2014 14:44:29 +0000

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

commit 504e257ba55af08437dcff8dc79ea2abd5b7a371
Author: Matthew L. Fidler <address@hidden>
Date:   Wed Jun 4 18:19:03 2014 +0800

    Fix Issue #7
---
 ergoemacs-advices.el      |   79 ++++++++++----------------------
 ergoemacs-mode.el         |   13 +++++-
 ergoemacs-shortcuts.el    |    3 +-
 ergoemacs-theme-engine.el |  108 ++++++++++++++++++++++++--------------------
 ergoemacs-translate.el    |   10 +++-
 5 files changed, 104 insertions(+), 109 deletions(-)

diff --git a/ergoemacs-advices.el b/ergoemacs-advices.el
index 1766a27..10dbeb5 100644
--- a/ergoemacs-advices.el
+++ b/ergoemacs-advices.el
@@ -124,39 +124,10 @@ Also adds keymap-flag for user-defined keys run with 
`run-mode-hooks'."
 
 (eval-after-load "helm"
   '(progn
-     ;; (defadvice helm-M-x (around ergoemacs-helm-M-x-keys)
-;;        "Translates Helm M-x keys to ergoemacs style bindings."
-;;        (flet ((helm-M-x-transformer
-;;                (candidates sources)
-;;                "filtered-candidate-transformer to show bindings in emacs 
commands.
-;; Show global bindings and local bindings according to current `major-mode'."
-;;                (with-helm-current-buffer
-;;                  (loop with local-map = (helm-M-x-current-mode-map-alist)
-;;                        for cand in candidates
-;;                        for local-key  = (car (rassq cand local-map))
-     ;;                        for key        = (substitute-command-keys 
(format "\\[%s]" cand))
-;;                        collect
-;;                        (cons (cond ((and (string-match "^M-x" key) 
local-key)
-;;                                     (format "%s (%s)"
-;;                                             cand (propertize
-;;                                                   (if (and 
ergoemacs-use-ergoemacs-key-descriptions ergoemacs-mode)
-;;                                                       (ergoemacs-pretty-key 
local-key)
-;;                                                     local-key)
-;;                                                   'face 'helm-M-x-key)))
-;;                                    ((string-match "^M-x" key) cand)
-;;                                    (t (format "%s (%s)"
-;;                                               cand (propertize
-;;                                                     (if (and 
ergoemacs-use-ergoemacs-key-descriptions ergoemacs-mode)
-;;                                                         
(ergoemacs-pretty-key key)
-;;                                                       key)
-;;                                                     'face 'helm-M-x-key))))
-;;                              cand) into ls
-;;                              finally return
-;;                              (sort ls #'helm-command-M-x-sort-fn)))))
-;;          ad-do-it))
-
-     ;; (ad-activate 'helm-M-x)
-     ))
+     (defadvice helm-M-x (around ergoemacs-helm-M-x-keys activate)
+       "Make ``helm-M-x' work correctly with `ergoemacs-mode' pretty keys"
+       (let ((ergoemacs-use-M-x-p t))
+         ad-do-it))))
 
 
 (defadvice cua-mode (around ergoemacs-activate-only-selection-mode (arg) 
activate)
@@ -240,7 +211,8 @@ will add MAP to substitution."
            (test-hash (gethash test-vect 
ergoemacs-original-keys-to-shortcut-keys)))
       (if test-hash
           (progn
-            (ergoemacs-pretty-key (key-description (nth 0 test-hash))))
+            (setq test (key-description (nth 0 test-hash)))
+            (ergoemacs-pretty-key test))
         (let (ergoemacs-modal ergoemacs-repeat-keys ergoemacs-read-input-keys
                               ergoemacs-shortcut-keys)
           (ergoemacs-pretty-key
@@ -304,6 +276,9 @@ will add MAP to substitution."
                            "|"))
         (goto-char (point-min))
         (insert test "\n")
+        (goto-char (point-max))
+        (insert "\n" test "\n\n")
+        (goto-char (point-min))
         (while (re-search-forward "|-.*\\(\n|-.*\\)*" nil t)
           (replace-match test))
         (goto-char (point-min))
@@ -311,8 +286,6 @@ will add MAP to substitution."
           (replace-match (format "| \\1%s | \\2%s |"
                                  (make-string (max 0 (- max1 (length 
(match-string 1)))) ? )
                                  (make-string (max 0 (- max2 (+ 3 (length 
(match-string 2))))) ? ))))
-        (goto-char (point-max))
-        (insert "\n" test "\n\n")
         (setq ret (buffer-string)))
       ret)))
 
@@ -338,24 +311,22 @@ thus, \=\= puts \= into the output, and \=\[ puts \[ into 
the output.
 Return the original STRING if no substitutions are made.
 Otherwise, return a new string, without any text properties.
 "
-  (let (ret str mapvar)
-    (if (not ergoemacs-mode)
-        (setq ret (ergoemacs-real-substitute-command-keys string))
-      (with-temp-buffer
-        (insert string)
-        (goto-char (point-min))
-        (while (re-search-forward "\\\\\\(\\[\\|<\\).*?\\(\\]\\|>\\)" nil t)
-          (if (string-match-p "\\`<" (match-string 0))
-              (setq mapvar (match-string 0))
-            (replace-match (ergoemacs-substitute-command (match-string 0) 
mapvar))))
-        (goto-char (point-min))
-        (while (re-search-forward "\\\\{.*?}" nil t)
-          (replace-match (ergoemacs-substitute-map (match-string 0))))
-        (setq ret (buffer-string))))
-    ret))
-
-
-
+  (if (not string) nil
+    (let (ret str mapvar)
+      (if (not ergoemacs-mode)
+          (setq ret (ergoemacs-real-substitute-command-keys string))
+        (with-temp-buffer
+          (insert string)
+          (goto-char (point-min))
+          (while (re-search-forward "\\\\\\(\\[\\|<\\).*?\\(\\]\\|>\\)" nil t)
+            (if (string-match-p "\\`<" (match-string 0))
+                (setq mapvar (match-string 0))
+              (replace-match (ergoemacs-substitute-command (match-string 0) 
mapvar))))
+          (goto-char (point-min))
+          (while (re-search-forward "\\\\{.*?}" nil t)
+            (replace-match (ergoemacs-substitute-map (match-string 0))))
+          (setq ret (buffer-string))))
+      ret)))
 
 (provide 'ergoemacs-advices)
 ;;;;;;;;;;;;;;;;;;;;;;;;`';;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
diff --git a/ergoemacs-mode.el b/ergoemacs-mode.el
index 0605965..7179e82 100644
--- a/ergoemacs-mode.el
+++ b/ergoemacs-mode.el
@@ -772,8 +772,17 @@ These hooks are deferred to make sure `this-command' is 
set appropriately.")
 
 (defvar ergoemacs-smart-functions
   '(ergoemacs-shortcut
-    ergoemacs-shortcut-movement-no-shift-select ergoemacs-shortcut-movement 
ergoemacs-read-key
+    ergoemacs-shortcut-movement-no-shift-select
+    ergoemacs-shortcut-movement
+    ergoemacs-read-key
     ergoemacs-modal-default))
+
+(defun ergoemacs-smart-function-p (var)
+  "Is VAR an `ergoemacs-mode' smart function?"
+  (or (not (symbolp var))
+      (and (boundp var)
+           (memq (symbol-value var) ergoemacs-smart-functions))))
+
 (defvar ergoemacs-last-command nil)
 (defun ergoemacs-pre-command-hook ()
   "Ergoemacs pre-command-hook."
@@ -819,7 +828,7 @@ These hooks are deferred to make sure `this-command' is set 
appropriately.")
                    (not unread-command-events))
               (ergoemacs-install-shortcuts-up))))
       (error nil)))
-  (unless (memq this-command ergoemacs-smart-functions)
+  (unless (ergoemacs-smart-function-p this-command)
     (run-hooks 'ergoemacs-pre-command-hook))
   t)
 
diff --git a/ergoemacs-shortcuts.el b/ergoemacs-shortcuts.el
index fc03163..dbf49d6 100644
--- a/ergoemacs-shortcuts.el
+++ b/ergoemacs-shortcuts.el
@@ -701,8 +701,7 @@ In addition, when the function is called:
    (t
     (mapc
      (lambda(var) ;; should include `this-command' and `this-original-command'
-       (when (and (boundp var)
-                  (memq (symbol-value var) ergoemacs-smart-functions))
+       (when (ergoemacs-smart-function-p var)
          (set var function)))
      ergoemacs-this-command-fake)
     (let ((this-command-keys-shift-translated
diff --git a/ergoemacs-theme-engine.el b/ergoemacs-theme-engine.el
index e2ffeaf..8ac1f28 100644
--- a/ergoemacs-theme-engine.el
+++ b/ergoemacs-theme-engine.el
@@ -807,6 +807,46 @@ ergoemacs-get-keymaps-for-hook OBJ HOOK")
 (defvar ergoemacs-original-map-hash (make-hash-table)
   "Hash table of the original maps that `ergoemacs-mode' saves.")
 
+
+(defun ergoemacs-theme--install-shortcut-item (key args keymap lookup-keymap
+                                                   full-shortcut-map-p)
+  (let (fn-lst)
+    (cond
+     ((commandp (nth 0 args))
+      (setq fn-lst (ergoemacs-shortcut-remap-list
+                    (nth 0 args) lookup-keymap))
+      (if fn-lst
+          (ignore-errors
+            (ergoemacs-theme-component--ignore-globally-defined-key key)
+            (define-key keymap key (nth 0 (nth 0 fn-lst))))
+        (when full-shortcut-map-p
+          (ignore-errors
+            (ergoemacs-theme-component--ignore-globally-defined-key key)
+            (when (or (commandp (nth 0 args) t)
+                      (keymapp (nth 0 args)))
+              (define-key keymap key (nth 0 args)))))))
+     (full-shortcut-map-p
+      (ignore-errors
+        (ergoemacs-theme-component--ignore-globally-defined-key key)
+        (define-key keymap key
+          `(lambda(&optional arg)
+             (interactive "P")
+             (ergoemacs-read-key ,(nth 0 args) ',(nth 1 args)))))))))
+
+(defun ergoemacs-theme--install-shortcuts-list (shortcut-list keymap 
lookup-keymap full-shortcut-map-p)
+  "Install shortcuts for SHORTCUT-LIST into KEYMAP.
+LOOKUP-KEYMAP
+FULL-SHORTCUT-MAP-P "
+  (dolist (y shortcut-list)
+    (let ((key (nth 0 y))
+          (args (nth 1 y)))
+      (ergoemacs-theme--install-shortcut-item
+       key args keymap lookup-keymap
+       full-shortcut-map-p))))
+
+(defvar ergoemacs-theme-hook-installed '()
+  "Installed hooks")
+
 (defmethod ergoemacs-apply-keymaps-for-hook ((obj 
ergoemacs-theme-component-map-list) hook)
   (with-slots (shortcut-list) (ergoemacs-get-fixed-map obj)
       (dolist (map-name (ergoemacs-get-keymaps-for-hook obj hook))
@@ -818,11 +858,22 @@ ergoemacs-get-keymaps-for-hook OBJ HOOK")
            (modify-map
             (if (not (keymapp (symbol-value map-name)))
                 (warn "Keymap %s not found.  Ergoemacs-mode cannot correct." 
keymap-name)
-              (unless (gethash map-name ergoemacs-original-map-hash)
-                ;; Save original map.
-                (puthash map-name (copy-keymap (symbol-value map-name)) 
ergoemacs-original-map-hash))
-              ;; Now apply map changes.
-              ))
+              (unless (member (list hook map-name) 
ergoemacs-theme-hook-installed)
+                (let ((orig-map (gethash map-name ergoemacs-original-map-hash))
+                      (fix-map (copy-keymap fix))
+                      (shortcut-map (make-sparse-keymap)))
+                  (unless orig-map
+                    ;; Save original map.
+                    (puthash map-name (copy-keymap (symbol-value map-name)) 
ergoemacs-original-map-hash)
+                    (setq orig-map (copy-keymap (symbol-value map-name))))
+                  ;; Now apply map changes.
+                  (set map-name
+                       (make-composed-keymap 
+                        (list (ergoemacs-theme--install-shortcuts-list
+                               shortcut-list fix-map orig-map full-map)
+                              orig-map)))
+                  (unless always
+                    (push (list hook map-name) 
ergoemacs-theme-hook-installed))))))
            (t 
             ;; Shortcuts are handled by the shortcut layer.
             (let ((emulation-var (intern (concat "ergoemacs--for-" 
(symbol-name hook) "-with-" (symbol-name map-name))))
@@ -1936,48 +1987,6 @@ Will attempt to restore the mode state when turning off 
the component/theme."
   :type 'boolean
   :group 'ergoemacs-mode)
 
-(defun ergoemacs-theme--install-shortcut-item (key args keymap lookup-keymap
-                                                   full-shortcut-map-p)
-  (let (fn-lst)
-    (cond
-     ((condition-case err
-          (interactive-form (nth 0 args))
-        (error nil))
-      (setq fn-lst (ergoemacs-shortcut-remap-list
-                    (nth 0 args) lookup-keymap))
-      (if fn-lst
-          (condition-case nil
-              (progn
-                (ergoemacs-theme-component--ignore-globally-defined-key key)
-                (define-key keymap key (nth 0 (nth 0 fn-lst)))))
-        (when full-shortcut-map-p
-          (condition-case nil
-              (progn
-                (ergoemacs-theme-component--ignore-globally-defined-key key)
-                (when (or (commandp (nth 0 args) t)
-                          (keymapp (nth 0 args)))
-                  (define-key keymap key (nth 0 args))))))))
-     (full-shortcut-map-p
-      (condition-case nil
-          (progn
-            (ergoemacs-theme-component--ignore-globally-defined-key key)
-            (define-key keymap key
-              `(lambda(&optional arg)
-                 (interactive "P")
-                 (ergoemacs-read-key ,(nth 0 args) ',(nth 1 args))))))))))
-
-(defun ergoemacs-theme--install-shortcuts-list (shortcut-list keymap 
lookup-keymap full-shortcut-map-p)
-  "Install shortcuts for SHORTCUT-LIST into KEYMAP.
-LOOKUP-KEYMAP
-FULL-SHORTCUT-MAP-P "
-  (mapc
-   (lambda(y)
-     (let ((key (nth 0 y))
-           (args (nth 1 y)))
-       (ergoemacs-theme--install-shortcut-item
-        key args keymap lookup-keymap
-        full-shortcut-map-p)))
-   shortcut-list))
 
 (defun ergoemacs-theme-component-keymaps-for-hook (hook component &optional 
version)
   "Gets the keymaps for COMPONENT and component VERSION for HOOK.
@@ -3471,7 +3480,7 @@ This also:
            ergoemacs-theme-save-variables-actual))
     (setq ergoemacs-theme-save-variables-actual  nil
           ergoemacs-theme-save-variables-state   nil)))
-
+(defvar ergoemacs-M-x "M-x ")
 (defun ergoemacs-theme-install (theme &optional version)
   "Installs `ergoemacs-theme' THEME into appropriate keymaps."
   (let ((tc (ergoemacs-theme-keymaps theme version)))
@@ -3489,7 +3498,8 @@ This also:
     (ergoemacs-theme-remove-key-list
      (if (nth 5 tc)
          (append (nth 5 tc) ergoemacs-global-override-rm-keys)
-       ergoemacs-global-override-rm-keys))))
+       ergoemacs-global-override-rm-keys))
+    (setq ergoemacs-M-x (substitute-command-keys "\\[execute-extended-command] 
"))))
 
 (defvar ergoemacs-theme-hash (make-hash-table :test 'equal))
 
diff --git a/ergoemacs-translate.el b/ergoemacs-translate.el
index 1314b89..17617c1 100644
--- a/ergoemacs-translate.el
+++ b/ergoemacs-translate.el
@@ -103,10 +103,16 @@ This assumes `ergoemacs-use-unicode-char' is non-nil.  
When
   :type 'boolean
   :group 'ergoemacs-mode)
 
+(defvar ergoemacs-use-M-x-p nil)
+
 (defun ergoemacs-pretty-key (code)
   "Creates Pretty keyboard binding from kbd CODE from M- to Alt+"
   (if (not code) ""
-    (let (deactivate-mark
+    (if (string-match "^M-x " code)
+        (if ergoemacs-use-M-x-p
+            code
+          (replace-match ergoemacs-M-x t t code))
+      (let (deactivate-mark
           (ob (or (and ergoemacs-use-unicode-brackets (ergoemacs-unicode-char 
"【" "[")) "["))
           (cb (or (and ergoemacs-use-unicode-brackets (ergoemacs-unicode-char 
"】" "]")) "]"))
           (ret (replace-regexp-in-string
@@ -203,7 +209,7 @@ This assumes `ergoemacs-use-unicode-char' is non-nil.  When
               (while (re-search-forward "Ctl[+]" nil t)
                 (replace-match "^")))
             (setq ret (buffer-string)))))
-      ret)))
+      ret))))
 
 (defun ergoemacs-pretty-key-rep-internal ()
   (let (case-fold-search)



reply via email to

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