[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)
- [elpa] 07/117: Lexical scoping for ergoemacs-menus, (continued)
- [elpa] 07/117: Lexical scoping for ergoemacs-menus, Matthew Fidler, 2014/07/25
- [elpa] 08/117: Lexical binding for ergoemacs-themes, Matthew Fidler, 2014/07/25
- [elpa] 04/117: Lexical Scoping for ergoemacs-functions, Matthew Fidler, 2014/07/25
- [elpa] 09/117: Fix copyright symbol, Matthew Fidler, 2014/07/25
- [elpa] 11/117: Fix Variable binding byte compile warnings, Matthew Fidler, 2014/07/25
- [elpa] 12/117: Lexical binding for ergoemacs-macros, Matthew Fidler, 2014/07/25
- [elpa] 10/117: Lexical binding for ergoemacs-theme-engine, Matthew Fidler, 2014/07/25
- [elpa] 15/117: Don't exit if region is active., Matthew Fidler, 2014/07/25
- [elpa] 16/117: Advise describe-buffer-bindings, Matthew Fidler, 2014/07/25
- [elpa] 06/117: Lexical binding for ergoemacs-layouts., Matthew Fidler, 2014/07/25
- [elpa] 18/117: Use save-match-data with ergoemacs-pretty-key,
Matthew Fidler <=
- [elpa] 13/117: Remove pop dependence, Matthew Fidler, 2014/07/25
- [elpa] 17/117: Add rudimentary guide-key support; F1/C-h activates guide-key, Matthew Fidler, 2014/07/25
- [elpa] 14/117: Attempt Lexical Scoping for ergoemacs-translate.el, Matthew Fidler, 2014/07/25
- [elpa] 20/117: Add left/right to pretty key descriptions, Matthew Fidler, 2014/07/25
- [elpa] 19/117: Pretty key cleanup, Matthew Fidler, 2014/07/25
- [elpa] 22/117: Fix guide-key-mode requirement, Matthew Fidler, 2014/07/25
- [elpa] 24/117: Comment ergoemacs-substitute-command-keys, Matthew Fidler, 2014/07/25
- [elpa] 21/117: Better guide-key support, Matthew Fidler, 2014/07/25
- [elpa] 25/117: Add command prompt here and powershell here, Matthew Fidler, 2014/07/25
- [elpa] 23/117: Fix (substitute-command-keys "\\[recover-session]"), Matthew Fidler, 2014/07/25