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

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

[elpa] 18/117: Use save-match-data with ergoemacs-pretty-key


From: Matthew Fidler
Subject: [elpa] 18/117: Use save-match-data with ergoemacs-pretty-key
Date: Fri, 25 Jul 2014 13:23:55 +0000

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

commit 73ba2880849f23fef8fcc394a5566dddb07b925b
Author: Matthew L. Fidler <address@hidden>
Date:   Tue Jul 15 09:24:25 2014 -0500

    Use save-match-data with ergoemacs-pretty-key
---
 ergoemacs-translate.el |  245 ++++++++++++++++++++++++------------------------
 1 files changed, 123 insertions(+), 122 deletions(-)

diff --git a/ergoemacs-translate.el b/ergoemacs-translate.el
index 30c5ea9..150ba73 100644
--- a/ergoemacs-translate.el
+++ b/ergoemacs-translate.el
@@ -129,128 +129,129 @@ This assumes `ergoemacs-use-unicode-char' is non-nil.  
When
 (defvar ergoemacs-M-x)
 (defun ergoemacs-pretty-key (code)
   "Creates Pretty keyboard binding from kbd CODE from M- to Alt+"
-  (if (not code) ""
-    (if (string-match "^\\(M-x\\|<execute>\\) " 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
-                " +$" "" (replace-regexp-in-string "^ +" "" code)))
-          (case-fold-search nil)) 
-      (when ergoemacs-use-ergoemacs-key-descriptions
-        (save-match-data
-          (with-temp-buffer
-            (insert ob)
-            (insert ret)
-            (insert cb)
-            (goto-char (point-min))
-            (while (re-search-forward "<f\\([0-9]+\\)>" nil t)
-              (replace-match "<F\\1>"))
-            (goto-char (point-min))
-            (while (re-search-forward "\\(-[A-Z]\\)\\([^-]\\|$\\)" nil t)
-              (unless (save-excursion
-                        (save-match-data
-                          (goto-char (match-beginning 0))
-                          (looking-at "-\\(RET\\|SPC\\|ESC\\)")))
-                (replace-match (format "-S%s%s" (downcase (match-string 1)) 
(match-string 2)))))
-            (goto-char (point-min))
-            (while (re-search-forward "\\_<[A-Z]\\_>" nil t)
-              (replace-match (format "S-%s" (match-string 0))))
-            (goto-char (point-min))
-            (while (re-search-forward "\\(S-\\)\\{2,\\}" nil t)
-              (replace-match "S-" t t))
-            (goto-char (point-min))
-            (while (re-search-forward " +" nil t)
-              (replace-match (format "%s%s" cb ob)))
-            (goto-char (point-min))
-            (while (search-forward "M-" nil t)
-              (replace-match (if (eq system-type 'darwin)
-                                 (cond
-                                  ((or (and (boundp 'mac-command-modifier)
-                                            (eq mac-command-modifier 'meta))
-                                       (and (boundp 'ns-command-modifier)
-                                            (eq ns-command-modifier 'meta)))
-                                   (format "%sCmd+"
-                                           (ergoemacs-unicode-char "⌘" "")))
-                                  ((or (and (boundp 'mac-alternate-modifier)
-                                            (eq mac-alternate-modifier 'meta))
-                                       (and (boundp 'ns-alternate-modifier)
-                                            (eq ns-alternate-modifier 'meta)))
-                                   (format "%sOpt+"
-                                           (ergoemacs-unicode-char "⌥" "")))
-                                  (t "Alt+"))
-                               "Alt+") t))
-            (goto-char (point-min))
-            (while (search-forward "C-" nil t)
-              (replace-match "Ctl+" t))
-            (goto-char (point-min))
-            (while (search-forward "S-" nil t)
-              (replace-match (format "%sShift+"
-                                     (ergoemacs-unicode-char "⇧" "")) t))
-            (goto-char (point-min))
-            (while (re-search-forward "[<>]" nil t)
-              (replace-match ""))
-            (goto-char (point-min))
-            (while (re-search-forward "\\(RET\\|[Rr]eturn\\)" nil t)
-              (replace-match (format "Enter%s"
-                                     (ergoemacs-unicode-char "⏎" "")) t))
-            (goto-char (point-min))
-            (while (re-search-forward "TAB" nil t)
-              (replace-match (format "%sTab"
-                                     (ergoemacs-unicode-char "↹" "")) t))
-            (goto-char (point-min))
-            (while (re-search-forward "\\(menu\\|apps\\)" nil t)
-              (unless (or (save-match-data (looking-at "-bar"))
-                          ;; (save-match-data (not (looking-back "-")))
-                          )
-                (replace-match (format "%s"
-                                       (ergoemacs-unicode-char "▤" "Menu")) 
t)))
-            (goto-char (point-min))
-            (while (re-search-forward "prior>" nil t)
-              (replace-match "PgUp>" t))
-            (goto-char (point-min))
-            (while (re-search-forward "next>" nil t)
-              (replace-match "PgDn>" t))
-            (goto-char (point-min))
-            (while (re-search-forward "[+]\\([[:lower:]]\\)\\(】\\|\\]\\)" nil 
t)
-              (replace-match (upcase (match-string 0)) t t))
-            (cond
-             ((and (eq system-type 'darwin)
-                   (string= "⇧" (ergoemacs-unicode-char "⇧" ""))
-                   (string= "⌘" (ergoemacs-unicode-char "⌘" ""))
-                   (string= "⌥" (ergoemacs-unicode-char "⌥" "")))
-              (goto-char (point-min))
-              (while (re-search-forward ".Opt[+]" nil t)
-                (replace-match "⌥"))
-              (goto-char (point-min))
-              (while (re-search-forward ".Cmd[+]" nil t)
-                (replace-match "⌘"))
-              (goto-char (point-min))
-              (while (re-search-forward ".Shift[+]" nil t)
-                (replace-match "⇧"))
-              (goto-char (point-min))
-              (while (re-search-forward "Ctl[+]" nil t)
-                (replace-match "^")))
-             ((and ergoemacs-use-small-symbols
-                   (string= "⇧" (ergoemacs-unicode-char "⇧" ""))
-                   (string= "♦" (ergoemacs-unicode-char "♦" "")))
-              (goto-char (point-min))
-              (while (re-search-forward ".Alt[+]" nil t)
-                (replace-match "♦"))
-              (goto-char (point-min))
-              (while (re-search-forward ".Shift[+]" nil t)
-                (replace-match "⇧"))
-              (goto-char (point-min))
-              (while (re-search-forward "Ctl[+]" nil t)
-                (replace-match "^"))))
-            (goto-char (point-min))
-            (unless (looking-at (regexp-quote ob))
-              (insert ob))
-            (setq ret (buffer-string)))))
-      ret))))
+  (save-match-data
+    (if (not code) ""
+      (if (string-match "^\\(M-x\\|<execute>\\) " 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
+                    " +$" "" (replace-regexp-in-string "^ +" "" code)))
+              (case-fold-search nil)) 
+          (when ergoemacs-use-ergoemacs-key-descriptions
+            (save-match-data
+              (with-temp-buffer
+                (insert ob)
+                (insert ret)
+                (insert cb)
+                (goto-char (point-min))
+                (while (re-search-forward "<f\\([0-9]+\\)>" nil t)
+                  (replace-match "<F\\1>"))
+                (goto-char (point-min))
+                (while (re-search-forward "\\(-[A-Z]\\)\\([^-]\\|$\\)" nil t)
+                  (unless (save-excursion
+                            (save-match-data
+                              (goto-char (match-beginning 0))
+                              (looking-at "-\\(RET\\|SPC\\|ESC\\)")))
+                    (replace-match (format "-S%s%s" (downcase (match-string 
1)) (match-string 2)))))
+                (goto-char (point-min))
+                (while (re-search-forward "\\_<[A-Z]\\_>" nil t)
+                  (replace-match (format "S-%s" (match-string 0))))
+                (goto-char (point-min))
+                (while (re-search-forward "\\(S-\\)\\{2,\\}" nil t)
+                  (replace-match "S-" t t))
+                (goto-char (point-min))
+                (while (re-search-forward " +" nil t)
+                  (replace-match (format "%s%s" cb ob)))
+                (goto-char (point-min))
+                (while (search-forward "M-" nil t)
+                  (replace-match (if (eq system-type 'darwin)
+                                     (cond
+                                      ((or (and (boundp 'mac-command-modifier)
+                                                (eq mac-command-modifier 
'meta))
+                                           (and (boundp 'ns-command-modifier)
+                                                (eq ns-command-modifier 
'meta)))
+                                       (format "%sCmd+"
+                                               (ergoemacs-unicode-char "⌘" 
"")))
+                                      ((or (and (boundp 
'mac-alternate-modifier)
+                                                (eq mac-alternate-modifier 
'meta))
+                                           (and (boundp 'ns-alternate-modifier)
+                                                (eq ns-alternate-modifier 
'meta)))
+                                       (format "%sOpt+"
+                                               (ergoemacs-unicode-char "⌥" 
"")))
+                                      (t "Alt+"))
+                                   "Alt+") t))
+                (goto-char (point-min))
+                (while (search-forward "C-" nil t)
+                  (replace-match "Ctl+" t))
+                (goto-char (point-min))
+                (while (search-forward "S-" nil t)
+                  (replace-match (format "%sShift+"
+                                         (ergoemacs-unicode-char "⇧" "")) t))
+                (goto-char (point-min))
+                (while (re-search-forward "[<>]" nil t)
+                  (replace-match ""))
+                (goto-char (point-min))
+                (while (re-search-forward "\\(RET\\|[Rr]eturn\\)" nil t)
+                  (replace-match (format "Enter%s"
+                                         (ergoemacs-unicode-char "⏎" "")) t))
+                (goto-char (point-min))
+                (while (re-search-forward "TAB" nil t)
+                  (replace-match (format "%sTab"
+                                         (ergoemacs-unicode-char "↹" "")) t))
+                (goto-char (point-min))
+                (while (re-search-forward "\\(menu\\|apps\\)" nil t)
+                  (unless (or (save-match-data (looking-at "-bar"))
+                              ;; (save-match-data (not (looking-back "-")))
+                              )
+                    (replace-match (format "%s"
+                                           (ergoemacs-unicode-char "▤" 
"Menu")) t)))
+                (goto-char (point-min))
+                (while (re-search-forward "prior>" nil t)
+                  (replace-match "PgUp>" t))
+                (goto-char (point-min))
+                (while (re-search-forward "next>" nil t)
+                  (replace-match "PgDn>" t))
+                (goto-char (point-min))
+                (while (re-search-forward "[+]\\([[:lower:]]\\)\\(】\\|\\]\\)" 
nil t)
+                  (replace-match (upcase (match-string 0)) t t))
+                (cond
+                 ((and (eq system-type 'darwin)
+                       (string= "⇧" (ergoemacs-unicode-char "⇧" ""))
+                       (string= "⌘" (ergoemacs-unicode-char "⌘" ""))
+                       (string= "⌥" (ergoemacs-unicode-char "⌥" "")))
+                  (goto-char (point-min))
+                  (while (re-search-forward ".Opt[+]" nil t)
+                    (replace-match "⌥"))
+                  (goto-char (point-min))
+                  (while (re-search-forward ".Cmd[+]" nil t)
+                    (replace-match "⌘"))
+                  (goto-char (point-min))
+                  (while (re-search-forward ".Shift[+]" nil t)
+                    (replace-match "⇧"))
+                  (goto-char (point-min))
+                  (while (re-search-forward "Ctl[+]" nil t)
+                    (replace-match "^")))
+                 ((and ergoemacs-use-small-symbols
+                       (string= "⇧" (ergoemacs-unicode-char "⇧" ""))
+                       (string= "♦" (ergoemacs-unicode-char "♦" "")))
+                  (goto-char (point-min))
+                  (while (re-search-forward ".Alt[+]" nil t)
+                    (replace-match "♦"))
+                  (goto-char (point-min))
+                  (while (re-search-forward ".Shift[+]" nil t)
+                    (replace-match "⇧"))
+                  (goto-char (point-min))
+                  (while (re-search-forward "Ctl[+]" nil t)
+                    (replace-match "^"))))
+                (goto-char (point-min))
+                (unless (looking-at (regexp-quote ob))
+                  (insert ob))
+                (setq ret (buffer-string)))))
+          ret)))))
 
 (defun ergoemacs-pretty-key-rep-internal ()
   (let (case-fold-search)



reply via email to

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