[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] 56/287: Better key replacements.
From: |
Matthew Fidler |
Subject: |
[elpa] 56/287: Better key replacements. |
Date: |
Wed, 02 Jul 2014 14:44:35 +0000 |
mlf176f2 pushed a commit to branch externals/ergoemacs-mode
in repository elpa.
commit a300a9af4e1bd5e1bd4f4c9311c162d1968785b8
Author: Matthew L. Fidler <address@hidden>
Date: Fri Jun 6 08:28:41 2014 -0500
Better key replacements.
---
ergoemacs-advices.el | 70 ++++++++++++++++++++++++++++---------------------
ergoemacs-mode.el | 7 +++++
2 files changed, 47 insertions(+), 30 deletions(-)
diff --git a/ergoemacs-advices.el b/ergoemacs-advices.el
index 9a7596d..684cdf2 100644
--- a/ergoemacs-advices.el
+++ b/ergoemacs-advices.el
@@ -195,10 +195,6 @@ This assumes any key defined while running a hook is a
user-defined hook."
(ergoemacs-with-global
ad-do-it))
-;;; Unfortunately, the advice route doesn't seem to work :(
-
-(fset 'ergoemacs-real-substitute-command-keys (symbol-function
'substitute-command-keys))
-
(defun ergoemacs-substitute-command (string &optional map)
"Substitutes command STRING
will add MAP to substitution."
@@ -296,26 +292,9 @@ will add MAP to substitution."
-(defun substitute-command-keys (string)
- "Substitute key descriptions for command names in STRING.
-Each substring of the form \[COMMAND] is replaced by either a
-keystroke sequence that invokes COMMAND, or \"M-x COMMAND\" if COMMAND
-is not on any keys.
-
-Each substring of the form \{MAPVAR} is replaced by a summary of
-the value of MAPVAR as a keymap. This summary is similar to the one
-produced by `describe-bindings'. The summary ends in two newlines
- (used by the helper function `help-make-xrefs' to find the end of the
- summary).
-
-Each substring of the form \<MAPVAR> specifies the use of MAPVAR
-as the keymap for future \[COMMAND] substrings.
-\= quotes the following character and is discarded;
-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.
-"
+(defun ergoemacs-substitute-command-keys (string)
+ "`ergoemacs-mode' replacement for substitute-command-keys.
+Actual substitute-command-keys is always in
`ergoemacs-real-substitute-command-keys'"
(if (not string) nil
(let (ret str mapvar)
(if (not ergoemacs-mode)
@@ -323,16 +302,47 @@ Otherwise, return a new string, without any text
properties.
(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) t t)))
+ (while (re-search-forward "\\<M-x " nil t)
+ (replace-match (ergoemacs-substitute-command
"\\[execute-extended-command] " "\\<global-map>") t t))
+ (goto-char (point-min))
+ (while (re-search-forward
"\\(\\(?:\\\\=\\)?\\)\\\\\\(\\[\\|<\\|{\\)\\(.*?\\)\\(\\]\\|>\\|}\\)" nil t)
+ (cond
+ ((string-match-p "\\\\=" (match-string 1))
+ (replace-match "\\\\\\2\\3\\4" t nil))
+ ((and (string-match-p "<" (match-string 2))
+ (string-match-p ">" (match-string 4)))
+ (setq mapvar (match-string 3))
+ (replace-match ""))
+ ((and (string-match-p "{" (match-string 2))
+ (string-match-p "}" (match-string 4)))
+ (replace-match (ergoemacs-substitute-map (match-string 0)) t t))
+ ((and (string-match-p "\\[" (match-string 2))
+ (string-match-p "\\]" (match-string 4)))
+ (replace-match (ergoemacs-substitute-command (match-string 0)
mapvar) t t))))
(goto-char (point-min))
- (while (re-search-forward "\\\\{.*?}" nil t)
- (replace-match (ergoemacs-substitute-map (match-string 0)) t t))
+ (while (re-search-forward "\\\\=" nil t)
+ (replace-match "" t t)
+ (re-search-forward "\\=\\\\=" nil t))
(setq ret (buffer-string))))
ret)))
+;;; Unfortunately, the advice route doesn't seem to work :(
+
+(fset 'ergoemacs-real-substitute-command-keys (symbol-function
'substitute-command-keys))
+
+(fset 'ergoemacs-real-completing-read (symbol-function 'completing-read))
+(defun ergoemacs-completing-read (prompt collection &optional
+ predicate require-match
+ initial-input hist def
inherit-input-method)
+ "Ergoemacs replacement of `completing-read'.
+Allows `execute-extended-command' to show the proper keys.
+The real command is always `ergoemacs-real-completing-read'.
+"
+ (ergoemacs-real-completing-read
+ (substitute-command-keys
+ (replace-regexp-in-string "\\<M-x " "\\[execute-extended-command] " prompt
t t))
+ collection predicate require-match
+ initial-input hist def inherit-input-method))
(provide 'ergoemacs-advices)
;;;;;;;;;;;;;;;;;;;;;;;;`';;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; ergoemacs-advices.el ends here
diff --git a/ergoemacs-mode.el b/ergoemacs-mode.el
index fd7fe68..4636d90 100644
--- a/ergoemacs-mode.el
+++ b/ergoemacs-mode.el
@@ -510,6 +510,9 @@ bindings the keymap is:
(setq overriding-terminal-local-map
ergoemacs-read-key-overriding-terminal-local-save)
(delete-overlay ergoemacs-read-key-overriding-overlay-save)
(setq ergoemacs-read-key-overriding-overlay-save nil)))
+ ;; Fix `substitute-command-keys'
+ (fset 'substitute-command-keys (symbol-function
'ergoemacs-substitute-command-keys))
+ (fset 'completing-read (symbol-function 'ergoemacs-completing-read))
(setq ergoemacs-unbind-keys t)
(add-hook 'pre-command-hook 'ergoemacs-pre-command-hook)
(ergoemacs-populate-pre-command-hook)
@@ -550,6 +553,10 @@ bindings the keymap is:
(remove-hook 'minibuffer-setup-hook #'ergoemacs-minibuffer-setup)
(remove-hook 'pre-command-hook 'ergoemacs-pre-command-hook)
(ergoemacs-populate-pre-command-hook t)
+ ;; Revert `substitute-command-keys' and `completing-read'
+ (fset 'completing-read (symbol-function 'ergoemacs-real-completing-read))
+ (fset 'substitute-command-keys (symbol-function
'ergoemacs-real-substitute-command-keys))
+
(ergoemacs-debug-heading "Ergoemacs-mode turned OFF."))
;; Always have `ergoemacs-post-command-hook' on so that it will
;; uninstall ergoemacs keymaps that were installed to overlays and
- [elpa] 43/287: Be more conservative with substituting key commands., (continued)
- [elpa] 43/287: Be more conservative with substituting key commands., Matthew Fidler, 2014/07/02
- [elpa] 46/287: Fix Issue #7, Matthew Fidler, 2014/07/02
- [elpa] 50/287: Another bug-fix for substitute-command-keys, Matthew Fidler, 2014/07/02
- [elpa] 52/287: Debugging ergoemacs-theme obect, Matthew Fidler, 2014/07/02
- [elpa] 51/287: more substitute-command-keys fixes, Matthew Fidler, 2014/07/02
- [elpa] 58/287: Fix misplaced paren, Matthew Fidler, 2014/07/02
- [elpa] 57/287: Added basic variable/mode initialization routines., Matthew Fidler, 2014/07/02
- [elpa] 54/287: Maps seem correct now, Matthew Fidler, 2014/07/02
- [elpa] 48/287: Unstage the incompatible, Matthew Fidler, 2014/07/02
- [elpa] 55/287: Nicer theme debugging display, Matthew Fidler, 2014/07/02
- [elpa] 56/287: Better key replacements.,
Matthew Fidler <=
- [elpa] 64/287: Replace either M-x or <execute> with M-x code., Matthew Fidler, 2014/07/02
- [elpa] 63/287: Fixed mapvar issues., Matthew Fidler, 2014/07/02
- [elpa] 47/287: Stage some components, Matthew Fidler, 2014/07/02
- [elpa] 62/287: Playing with object more., Matthew Fidler, 2014/07/02
- [elpa] 53/287: Better debug and modify keymaps fix bugs, Matthew Fidler, 2014/07/02
- [elpa] 59/287: Fix typo, Matthew Fidler, 2014/07/02
- [elpa] 61/287: Ergoemacs-mode setup with object almost complete., Matthew Fidler, 2014/07/02
- [elpa] 66/287: Make ergoemacs-clean toggle debug on error, Matthew Fidler, 2014/07/02
- [elpa] 71/287: Fix isearch issues., Matthew Fidler, 2014/07/02
- [elpa] 60/287: Ensure the object-name is a string. EIEIO seems to prefer this., Matthew Fidler, 2014/07/02