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

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

[elpa] externals/hiddenquote e345b6a06a: Implement functionality for tra


From: ELPA Syncer
Subject: [elpa] externals/hiddenquote e345b6a06a: Implement functionality for transposing characters
Date: Wed, 9 Nov 2022 07:57:44 -0500 (EST)

branch: externals/hiddenquote
commit e345b6a06a1adaad8317ca0c874feea6460b7d7e
Author: Mauro Aranda <maurooaranda@gmail.com>
Commit: Mauro Aranda <maurooaranda@gmail.com>

    Implement functionality for transposing characters
    
    * hiddenquote.el (hiddenquote-transpose-chars): New command.
    (hiddenquote-character-map): Bind it.
---
 hiddenquote.el | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/hiddenquote.el b/hiddenquote.el
index 4382c9cf1b..a37dc5241e 100644
--- a/hiddenquote.el
+++ b/hiddenquote.el
@@ -312,6 +312,7 @@ to the syllables buffer."
     (define-key map [backspace] #'hiddenquote-delete-backward-char)
     (define-key map [delete] #'delete-char)
     (define-key map [?\d] #'hiddenquote-delete-backward-char)
+    (define-key map "\C-t" #'hiddenquote-transpose-chars)
     ;; Actions.
     (define-key map "?" #'hiddenquote-check-answer)
     (define-key map "\C-m" #'widget-field-activate)
@@ -1396,6 +1397,29 @@ Character cell bindings:
     (widget-forward 1))
   (delete-char 1))
 
+(defun hiddenquote-transpose-chars ()
+  "Interchange the characters around point, and move forward one character.
+
+Attempting to transporte the first character in a word results in an error.
+
+Note that after transposing the last character in a word, this command moves
+point to the next word."
+  (interactive)
+  (let* ((ch1 (widget-at))
+         (parent (widget-get ch1 :parent))
+         (children (widget-get parent :children))
+         (length (length children))
+         (n (seq-position children ch1))
+         (ch2 (if (= n 0)
+                  (user-error "Can't transpose the first character in a word")
+                (nth (1- n) children)))
+         (oval (widget-value ch1))
+         (nval (widget-value ch2)))
+    ;; Spaces are problematic.
+    (widget-value-set ch1 (if (char-equal nval ?\s) "" nval))
+    (widget-value-set ch2 (if (char-equal oval ?\s) "" oval))
+    (hiddenquote-forward)))
+
 (defun hiddenquote-forward ()
   "Go to the next character if at a widget, use `forward-char' otherwise."
   (interactive)



reply via email to

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