[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/devil 4b1eba8a1c 24/49: Add stricter validation of transla
|
From: |
ELPA Syncer |
|
Subject: |
[nongnu] elpa/devil 4b1eba8a1c 24/49: Add stricter validation of translated key sequence |
|
Date: |
Mon, 15 May 2023 12:59:32 -0400 (EDT) |
branch: elpa/devil
commit 4b1eba8a1ca2b6f79a5f2db0f675f96ec870f73a
Author: Susam Pal <susam@susam.net>
Commit: Susam Pal <susam@susam.net>
Add stricter validation of translated key sequence
Prior to this change, there was a translation issue that caused
invalid Emacs key sequences on mapping `-`. For example, mapping `-`
to `C-x` and typing `- C-f` produced `C-x CC-xf`. This has been
fixed so that `- C-f` is now translated to `C-x C-f`.
---
CHANGES.md | 5 +++++
devil.el | 32 ++++++++++++++++++++------------
2 files changed, 25 insertions(+), 12 deletions(-)
diff --git a/CHANGES.md b/CHANGES.md
index 5d9a355d44..d59500f14f 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -21,6 +21,11 @@ Changelog
### Fixed
- Remove a stray `message` call.
+- Make the function `dev--tests` non-interactive.
+- Translation issue that caused invalid Emacs key sequences on mapping
+ `-`. For example, mapping `-` to `C-x` and typing `- C-f` produced
+ `C-x CC-xf`. This has been fixed so that `- C-f` is now translated
+ to `C-x C-f`.
0.1.0 (2023-05-07)
diff --git a/devil.el b/devil.el
index 1f3812327b..c26b77b5ee 100644
--- a/devil.el
+++ b/devil.el
@@ -254,7 +254,7 @@ sequences should be read from the user."
(translated-key (devil-translate key))
(parsed-key (condition-case nil (kbd translated-key) (error nil)))
(binding (when parsed-key (key-binding parsed-key))))
- (cond ((string-match "[ACHMsS]-$" translated-key)
+ (cond ((string-match "[ACHMSs]-$" translated-key)
(devil--log "Ignoring incomplete key: %s => %s"
described-key translated-key)
nil)
@@ -293,7 +293,7 @@ read so far."
(try-key))
(when (string-prefix-p from-key in-key)
(setq try-key (devil--clean-key (concat result to-key)))
- (when (devil--valid-key-p try-key)
+ (unless (devil--invalid-key-p try-key)
(setq result try-key)
(setq index (+ index (length from-key)))
(throw 'break t)))))
@@ -359,13 +359,16 @@ the original Emacs key sequence."
(defun devil--clean-key (translated-key)
"Clean up TRANSLATED-KEY to properly formatted Emacs key sequence."
- (replace-regexp-in-string "\\([ACHMsS]\\)- " "\\1-" translated-key))
+ (replace-regexp-in-string "\\([ACHMSs]\\)- " "\\1-" translated-key))
-(defun devil--valid-key-p (translated-key)
- "Return nil iff TRANSLATED-KEY is an invalid Emacs key sequence."
- (not (string-match-p (concat "A-[^ ]*A-\\|" "C-[^ ]*C-\\|" "H-[^ ]*H-\\|"
- "M-[^ ]*M-\\|" "s-[^ ]*s-\\|" "S-[^ ]*S-")
- translated-key)))
+(defun devil--invalid-key-p (translated-key)
+ "Return t iff TRANSLATED-KEY is an invalid Emacs key sequence."
+ (catch 'break
+ (dolist (chunk (split-string translated-key " "))
+ (when (or (string= chunk "")
+ (not (string-match-p "^\\(?:[ACHMSs]-\\)*[^ ]?$" chunk))
+ (string-match-p "\\([ACHMSs]-\\)[^ ]*\\1" chunk))
+ (throw 'break t)))))
(defun devil-format (string)
"Replace %k in STRING with `devil-key'."
@@ -383,16 +386,21 @@ the original Emacs key sequence."
(defun devil--tests ()
"Test Devil functions assuming Devil has not been customized."
+ (devil--assert (devil--invalid-key-p ""))
+ (devil--assert (devil--invalid-key-p "C-x-C-f"))
+ (devil--assert (devil--invalid-key-p "C-x CC-f"))
+ (devil--assert (not (devil--invalid-key-p "C-x C-f")))
+ (devil--assert (not (devil--invalid-key-p "C-M-x")))
(devil--assert (string= (devil-translate (vconcat ",")) "C-"))
(devil--assert (string= (devil-translate (vconcat ",x")) "C-x"))
(devil--assert (string= (devil-translate (vconcat ",x,")) "C-x C-"))
(devil--assert (string= (devil-translate (vconcat ",x,f")) "C-x C-f"))
- (devil--assert (string= (devil-translate (vconcat ",,")) "C-,"))
- (devil--assert (string= (devil-translate (vconcat ",,,,")) "C-, C-,"))
+ (devil--assert (string= (devil-translate (vconcat ",,")) ","))
+ (devil--assert (string= (devil-translate (vconcat ",,,,")) ", ,"))
(devil--assert (string= (devil-translate (vconcat ",mx")) "C-M-x"))
- (devil--assert (string= (devil-translate (vconcat ",,mx")) "M-x"))
+ (devil--assert (string= (devil-translate (vconcat ",mmx")) "M-x"))
(devil--assert (string= (devil-translate (vconcat ",mmm")) "M-m"))
- (devil--log "Tests completed"))
+ (message "Done"))
(provide 'devil)
- [nongnu] elpa/devil 98064ffed4 49/49: Remove superfluous exclamation mark, (continued)
- [nongnu] elpa/devil 98064ffed4 49/49: Remove superfluous exclamation mark, ELPA Syncer, 2023/05/15
- [nongnu] elpa/devil 1cee55eaa3 41/49: Use sharp-quotes consistently for function names, ELPA Syncer, 2023/05/15
- [nongnu] elpa/devil c6db405df4 14/49: Address code review comments offered on MELPA, ELPA Syncer, 2023/05/15
- [nongnu] elpa/devil f57adb4860 03/49: Set version to 0.1.0, ELPA Syncer, 2023/05/15
- [nongnu] elpa/devil a98cb1a7bd 09/49: Automatically detect the activation key, ELPA Syncer, 2023/05/15
- [nongnu] elpa/devil 21eeb196f7 10/49: Explain how to configure multiple Devil keys, ELPA Syncer, 2023/05/15
- [nongnu] elpa/devil 1cf89ce338 11/49: Add yank-pop as a repeatable command, ELPA Syncer, 2023/05/15
- [nongnu] elpa/devil 402dcfd7fb 13/49: Fix repeatable key sequence for yank-pop, ELPA Syncer, 2023/05/15
- [nongnu] elpa/devil ef5449deda 16/49: Add kill-line and undo to repeatable keys, ELPA Syncer, 2023/05/15
- [nongnu] elpa/devil 02464b7516 18/49: Explain why a single activation key is the default, ELPA Syncer, 2023/05/15
- [nongnu] elpa/devil 4b1eba8a1c 24/49: Add stricter validation of translated key sequence,
ELPA Syncer <=
- [nongnu] elpa/devil 6943ff3e82 28/49: Remove custom version command., ELPA Syncer, 2023/05/15
- [nongnu] elpa/devil 459ce032e4 32/49: * devil.el (devil--log-command-loop-info): Use a single 'format', ELPA Syncer, 2023/05/15
- [nongnu] elpa/devil fa6eb0a319 33/49: Move tests to separate file using ERT, ELPA Syncer, 2023/05/15
- [nongnu] elpa/devil 355bcc9c14 34/49: Extract most of the README into a separate manual, ELPA Syncer, 2023/05/15
- [nongnu] elpa/devil 79fd50fe22 36/49: Set version to 0.3.0, ELPA Syncer, 2023/05/15
- [nongnu] elpa/devil c60437c11b 39/49: Support making all key sequences repeatable, ELPA Syncer, 2023/05/15
- [nongnu] elpa/devil f6ddd7cac1 38/49: Fix undefined error for RET, <f10>, etc., ELPA Syncer, 2023/05/15
- [nongnu] elpa/devil 72ce585e59 42/49: Document devil-all-keys-repeatable in the manual, ELPA Syncer, 2023/05/15
- [nongnu] elpa/devil 305a41dc55 45/49: Add MELPA badges, ELPA Syncer, 2023/05/15
- [nongnu] elpa/devil 2fe542cbc6 46/49: Mention Emacs at the beginning of documentation, ELPA Syncer, 2023/05/15