emacs-devel
[Top][All Lists]
Advanced

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

Re: Suggestion for C-t (transpose-chars)


From: Dieter Wilhelm
Subject: Re: Suggestion for C-t (transpose-chars)
Date: Fri, 27 Jul 2007 02:28:08 +0200
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux)

Eli Zaretskii <address@hidden> writes:

>
> I'd rather you posted it here, as diffs to the appropriate Emacs Lisp
> file.

Fine, here's my first idea.  I'll test it a while and see whether it's
really an improvement to the original defun (here called drag-chars).

Could I marry the two behaviours into one function in checking for
example whether the arguments are given with an C-u prefix or not?

        Dieter


Index: simple.el
===================================================================
--- simple.el   (revision 6)
+++ simple.el   (working copy)
@@ -3957,6 +3957,27 @@
       (select-window orig-window))))
 
 (defun transpose-chars (arg)
+  "Interchange characters around point.
+With prefix arg ARG, effect is to interchange adjacent characters
+ARG characters before point (ARG characters after point if ARG is
+negative).  If no argument and at end of line, the previous two
+characters are exchanged."
+  (interactive "*P")
+  (when (and (null arg) (eolp))
+    (setq arg 2))
+  (let* ((p (point))
+        (p1 (- p (prefix-numeric-value arg)))
+        (p2 (1+ p1)))
+    (when (< p1 (point-min))
+      (error "Beginning of buffer or narrowed region"))
+    (when (> p2 (point-max))
+      (error "End of buffer or narrowed region"))
+    (setq c (delete-and-extract-region p1 p2))
+    (goto-char p2)
+    (insert c)
+    (goto-char p)))
+
+(defun drag-chars (arg)
   "Interchange characters around point, moving forward one character.
 With prefix arg ARG, effect is to take character before point
 and drag it forward past ARG other characters (backward if ARG negative).


-- 
    Best wishes

    H. Dieter Wilhelm
    Darmstadt, Germany




reply via email to

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