[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] 19/117: Pretty key cleanup
From: |
Matthew Fidler |
Subject: |
[elpa] 19/117: Pretty key cleanup |
Date: |
Fri, 25 Jul 2014 13:23:55 +0000 |
mlf176f2 pushed a commit to branch externals/ergoemacs-mode
in repository elpa.
commit 0521b448c9dc9750b2107923c3cfe2b08051d5bc
Author: Matthew L. Fidler <address@hidden>
Date: Tue Jul 15 11:25:52 2014 -0500
Pretty key cleanup
---
ergoemacs-functions.el | 11 --
ergoemacs-shortcuts.el | 2 +
ergoemacs-test.el | 23 ++---
ergoemacs-translate.el | 245 ++++++++++++++++++------------------------------
4 files changed, 100 insertions(+), 181 deletions(-)
diff --git a/ergoemacs-functions.el b/ergoemacs-functions.el
index 4b42c3e..0fe26b7 100644
--- a/ergoemacs-functions.el
+++ b/ergoemacs-functions.el
@@ -1973,17 +1973,6 @@ If arg is a negative prefix, copy file path only"
"unix")) current-coding)))
(set-buffer-file-coding-system new-coding t)))
-;;; ergoemacs help functions.
-(declare-function ergoemacs-pretty-key-rep "ergoemacs-translate.el")
-(defun ergoemacs-translate-keybindings ()
- "Fix keybindings"
- (let ((help (get-buffer "*Help*")))
- (when help
- (with-current-buffer help
- (let ((inhibit-read-only t))
- (ergoemacs-pretty-key-rep))))))
-
-
(defun ergoemacs-describe-major-mode ()
"Show inline doc for current major-mode."
;; code by Kevin Rodgers. 2009-02-25.
diff --git a/ergoemacs-shortcuts.el b/ergoemacs-shortcuts.el
index 3f63e04..4e2e76b 100644
--- a/ergoemacs-shortcuts.el
+++ b/ergoemacs-shortcuts.el
@@ -495,6 +495,7 @@ It will replace anything defined by `ergoemacs-translation'"
(ergoemacs-read-key-install-next-key next-key key pretty kbd))))
(defvar guide-key-mode)
+(declare-function guide-key/popup-function "guide-key.el")
(defvar ergoemacs-read-key nil
"Current key for `ergoemacs-read-key'")
(defun ergoemacs-read-key-help ()
@@ -592,6 +593,7 @@ 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
diff --git a/ergoemacs-test.el b/ergoemacs-test.el
index b6d62a4..a73d723 100644
--- a/ergoemacs-test.el
+++ b/ergoemacs-test.el
@@ -326,16 +326,11 @@ sunt in culpa qui officia deserunt mollit anim id est
laborum.")
(ergoemacs-test-global-key-set-before
'after "C-e" 'ergoemacs-key)))
-(declare-function ergoemacs-pretty-key-rep "ergoemacs-tranlate.el")
+(declare-function ergoemacs-pretty-key "ergoemacs-translate.el")
(ert-deftest ergoemacs-test-ctl-c-ctl-c ()
"Issue #64. Should translate C-c C-c correctly."
(let (ergoemacs-use-unicode-char)
- (should (string= (ergoemacs-pretty-key-rep "C-c C-c") "[Ctl+C] [Ctl+C]"))))
-
-(ert-deftest ergoemacs-test-helm-M-x ()
- "Issue #65. helm-M-x should not be helm-[Alt+X]."
- (let (ergoemacs-use-unicode-char)
- (should (string= (ergoemacs-pretty-key-rep "helm-M-x test") "helm-M-x
test"))))
+ (should (string= (ergoemacs-pretty-key "C-c C-c") "[Ctrl+C][Ctrl+C]"))))
(declare-function ergoemacs-cut-line-or-region "ergoemacs-functions.el")
(ert-deftest ergoemacs-test-cut-line-or-region ()
@@ -354,18 +349,12 @@ not using cua or cutting line. I think kill-region is
what is meant."
(cua-mode 1))
(should ret)))
-(ert-deftest ergoemacs-test-next-and-prior-translation ()
- "Issue #70.
-Test next and prior translation."
- (should (string= (ergoemacs-pretty-key-rep "Test next and prior translation")
- "Test next and prior translation")))
-
(declare-function ergoemacs-pretty-key "ergoemacs-translate.el")
(ert-deftest ergoemacs-test-issue-77 ()
"Issue #77.
-Test \"C-x \" translating to \"[Ctl+X][]\", should be \"[Ctl+X]\""
+Test \"C-x \" translating to \"[Ctrl+X][]\", should be \"[Ctrl+X]\""
(let ((ergoemacs-use-unicode-char nil))
- (should (string= (ergoemacs-pretty-key "C-x ") "[Ctl+X]"))))
+ (should (string= (ergoemacs-pretty-key "C-x ") "[Ctrl+X]"))))
(ert-deftest ergoemacs-test-issue-86 ()
"Test Issue #86.
@@ -934,6 +923,10 @@ Selected mark would not be cleared after paste."
"Test global C-c b"
(should (equal (ergoemacs-test-global-key-set-before nil "C-c b") t)))
+(ert-deftest ergoemacs-test-global-key-set-M-t-after ()
+ "Test global M-t"
+ (should (equal (ergoemacs-test-global-key-set-before nil "M-t") t)))
+
(ert-deftest ergoemacs-test-issue-243 ()
"Allow globally set keys like C-c C-c M-x to work globally while local
commands like C-c C-c will work correctly. "
:expected-result :failed
diff --git a/ergoemacs-translate.el b/ergoemacs-translate.el
index 150ba73..b7dc65c 100644
--- a/ergoemacs-translate.el
+++ b/ergoemacs-translate.el
@@ -129,161 +129,96 @@ 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+"
- (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)
- (goto-char (point-min))
- (while (re-search-forward
"\\(\\(?:[CAMHS]-\\)+\\(?:RET\\|Return\\|TAB\\|prior>\\|next>\\|SPC\\|ESC\\|.\\)\\|<[^>]*?>\\|\\<RET\\>\\|\\<TAB\\>\\|\\<prior>\\>\\|\\<next>\\>\\|\\<SPC\\>\\|\\<ESC\\>\\)\\(
+\\|[':,.]\\|$\\)" nil t)
- (unless (or (save-match-data (string-match "remap" (match-string 1)))
- (save-match-data (string-match "\\(\\[\\]\\|【】\\)"
(ergoemacs-pretty-key (match-string 1))))
- (save-match-data (save-excursion (goto-char (match-beginning
0)) (looking-back "-\\="))))
- (replace-match (concat (ergoemacs-pretty-key (match-string 1))
- (match-string 2)) t t)
- (while (re-search-forward
"\\=\\(\\<RET\\>\\|\\<Return\\>\\|\\<TAB\\>\\|\\<prior>\\>\\|\\<next>\\>\\|\\<SPC\\>\\|\\<ESC\\>\\|[^\n
]\\)\\( +\\|[':,.]\\|$\\)" nil t)
- (unless (save-match-data (save-excursion (goto-char (match-beginning
0)) (looking-back "-\\=")))
- (replace-match (concat (ergoemacs-pretty-key (match-string 1))
- (match-string 2)) t t)))))
- (goto-char (point-min))
- (while (re-search-forward "】 【" nil t)
- (replace-match"】【"))))
-
-(defun ergoemacs-pretty-key-rep (&optional code)
- "Finds keyboard binding codes such as C-x and replaces them with
`ergoemacs-pretty-key' encoding."
- (if code
- (let ((ret code)
- (case-fold-search nil))
+ (if (not code) ""
+ (if (string-match-p "^\\(M-x\\|<execute>\\) " code)
+ (if ergoemacs-use-M-x-p
+ code
+ (replace-match ergoemacs-M-x t t code))
+ (let* ((ob (or (and ergoemacs-use-unicode-brackets
(ergoemacs-unicode-char "【" "[")) "["))
+ (cb (or (and ergoemacs-use-unicode-brackets
(ergoemacs-unicode-char "】" "]")) "]"))
+ (ret (concat ob (replace-regexp-in-string
+ " +$" "" (replace-regexp-in-string "^ +" ""
code)) cb))
+ (case-fold-search nil)
+ (pt 0))
(when ergoemacs-use-ergoemacs-key-descriptions
- (save-match-data
- (with-temp-buffer
- (insert code)
- (ergoemacs-pretty-key-rep-internal)
- (setq ret (buffer-string)))))
- ret)
- (when ergoemacs-use-ergoemacs-key-descriptions
- (ergoemacs-pretty-key-rep-internal))))
+ (while (string-match "<f\\([0-9]+\\)>" ret pt)
+ (setq ret (replace-match "<F\\1>" t nil ret)
+ pt (match-end 0)))
+ (setq pt 0)
+ (while (string-match "\\(-[A-Z]\\)\\>\\([^-]\\|$\\)" ret pt)
+ (setq pt (+ (match-end 0) 2)
+ ret (replace-match (format "-S%s%s" (downcase (match-string
1 ret)) (match-string 2 ret)) t t ret)))
+ (setq pt 0)
+ (while (string-match "\\_<[A-Z]\\_>" ret pt)
+ (setq pt (+ (match-end 0) 2)
+ ret (replace-match (format "S-%s" (match-string 0 ret)) t t
ret)))
+ (setq pt 0)
+ (while (string-match "\\(S-\\)\\{2,\\}" ret pt)
+ (setq pt (+ (match-beginning 0) 2)
+ ret (replace-match "S-" t t ret)))
+ (dolist (args `(("\\<M-" ,(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+"))
+ ("\\<C-" "Ctrl+")
+ ("\\<S-" ,(format "%sShift+"
+ (ergoemacs-unicode-char "⇧" "")))
+ ("[<>]" "")
+ ("\\<\\(RET\\|[Rr]eturn\\)\\>" ,(format "Enter%s"
+
(ergoemacs-unicode-char "⏎" "")))
+ ("\\<TAB\\>" ,(format "%sTab"
+ (ergoemacs-unicode-char "↹"
"")))
+ ("\\_<\\(menu\\|apps\\)\\_>" ,(format "%s"
+
(ergoemacs-unicode-char "▤" "Menu")))
+ ("\\_<prior\\_>" "PgUp")
+ ("\\_<next\\_>" "PgDn")
+ (" +" ,(concat cb ob))
+ (,(regexp-quote (concat cb " +" ob)) ,(concat cb
ob))))
+ (setq pt 0)
+ (while (string-match (nth 0 args) ret pt)
+ (setq pt (+ (length (nth 1 args)) (match-beginning 0))
+ ret (replace-match (nth 1 args) t t ret))))
+ (setq pt 0)
+ (while (string-match "[+]\\([[:lower:]]\\)\\(】\\|\\]\\)" ret pt)
+ (setq ret (replace-match (upcase (match-string 0 ret)) t t ret)
+ pt (match-end 0)))
+ (setq pt 0)
+ (cond
+ ((and (eq system-type 'darwin)
+ (string= "⇧" (ergoemacs-unicode-char "⇧" ""))
+ (string= "⌘" (ergoemacs-unicode-char "⌘" ""))
+ (string= "⌥" (ergoemacs-unicode-char "⌥" "")))
+ (dolist (args `((".Opt[+]" "⌥")
+ (".Cmd[+]" "⌘")
+ (".Shift[+]" "⇧")
+ (".Ctr?l[+]" "^")))
+ (setq pt 0)
+ (while (string-match (nth 0 args) ret pt)
+ (setq pt (+ (length (nth 1 args)) (match-beginning 0))
+ ret (replace-match (nth 1 args) t t ret)))))
+ ((and ergoemacs-use-small-symbols
+ (string= "⇧" (ergoemacs-unicode-char "⇧" ""))
+ (string= "♦" (ergoemacs-unicode-char "♦" "")))
+ (dolist (args `((".Alt[+]" "♦")
+ (".Shift[+]" "⇧")
+ (".Ctr?l[+]" "^")))
+ (setq pt 0)
+ (while (string-match (nth 0 args) ret pt)
+ (setq pt (+ (length (nth 1 args)) (match-beginning 0))
+ ret (replace-match (nth 1 args) t t ret)))))))
+ ret))))
@@ -815,7 +750,7 @@ and `ergoemacs-pretty-key' descriptions.
(setq ret (plist-put ret ':alt-ctl-shift-key (read-kbd-macro
(plist-get ret ':alt-ctl-shift) t)))
(setq ret (plist-put ret ':alt-ctl-shift-pretty (ergoemacs-pretty-key
(plist-get ret ':alt-ctl-shift)))))
(maphash
- (lambda(key plist)
+ (lambda(_ignore plist)
(setq ret (ergoemacs-translation-install plist orig-key ret)))
ergoemacs-translations)
(puthash orig-key ret ergoemacs-translate-hash)
- [elpa] 12/117: Lexical binding for ergoemacs-macros, (continued)
- [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, 2014/07/25
- [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 <=
- [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
- [elpa] 27/117: Fix recursive loading in ergoemacs-mode source, Matthew Fidler, 2014/07/25
- [elpa] 30/117: Declare w32-long-file-name, Matthew Fidler, 2014/07/25
- [elpa] 29/117: Cleanup byte compile, Matthew Fidler, 2014/07/25
- [elpa] 31/117: More emcompassing shell prompt regexp, Matthew Fidler, 2014/07/25
- [elpa] 26/117: Fix load dependence, See Issue #232, Matthew Fidler, 2014/07/25