From: "Gustav Hållberg" <gustav@gmail.com>
Subject: Re: Suggested new transpose-rectangle command
Date: Sun, 13 Aug 2006 13:49:51 -0700 [thread overview]
Message-ID: <a1e915350608131349u2ea41c8bob31e27d40de82630@mail.gmail.com> (raw)
In-Reply-To: <a1e915350608122344w32dfa5ceu7c22288164fafa79@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 262 bytes --]
On 8/12/06, Gustav Hållberg <gustav@gmail.com> wrote:
> Attaching a proposed patch that adds such a command.
Erh, that patch was broken, sorry about that.
Attaching a better one!
- Gustav
PS. Maybe a better command name would be (mirror-rectangle)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: transpose-rect.patch --]
[-- Type: text/x-patch; name="transpose-rect.patch", Size: 2050 bytes --]
Index: lisp/rect.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/rect.el,v
retrieving revision 1.52
diff -u -r1.52 rect.el
--- lisp/rect.el 8 Apr 2006 10:30:19 -0000 1.52
+++ lisp/rect.el 13 Aug 2006 20:44:44 -0000
@@ -392,6 +392,46 @@
(delete-region pt (point))
(indent-to endcol)))))
+(defun transpose-array (array)
+ "Returns a new array which is a transposed copy of
+ARRAY (vector, string, or bool-vector)."
+ (let* ((length (length array))
+ (result (apply (cond ((vectorp array) 'make-vector)
+ ((stringp array) 'make-string)
+ ((bool-vector-p array) 'make-bool-vector)
+ (t (signal 'wrong-type-argument '(arrayp array))))
+ (list length 0)))
+ (index length))
+ (while (> index 0)
+ (setq index (1- index))
+ (aset result index (aref array (- length 1 index))))
+ result))
+
+;;;###autoload
+(defun transpose-rectangle (start end &optional horizontal vertical)
+ "Replace the region-rectangle with its mirror image.
+
+By default, only horizontal transposition is done. With a prefix
+argument, ask whether to transpose horizontally and/or vertically.
+
+If HORIZONTAL is non-nil, each line in the rectangle is transposed.
+If VERTICAL is non-nil, all lines in the rectangle are transposed.
+
+When called from a program, the rectangle's corners are START and END."
+ (interactive
+ (append (list (region-beginning) (region-end))
+ (if current-prefix-arg
+ (list (y-or-n-p "Transpose horizontally? ")
+ (y-or-n-p "Transpose vertically? "))
+ '(t nil))))
+ (let ((rect (delete-extract-rectangle start end)))
+ (when vertical
+ (setq rect (reverse rect)))
+ (when horizontal
+ (setq rect (mapcar (function transpose-array) rect)))
+ (goto-char start)
+ (insert-rectangle rect)))
+
(provide 'rect)
;;; arch-tag: 178847b3-1f50-4b03-83de-a6e911cc1d16
[-- Attachment #3: Type: text/plain, Size: 149 bytes --]
_______________________________________________
bug-gnu-emacs mailing list
bug-gnu-emacs@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-gnu-emacs
prev parent reply other threads:[~2006-08-13 20:49 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-08-13 6:44 Suggested new transpose-rectangle command Gustav Hållberg
2006-08-13 20:49 ` Gustav Hållberg [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a1e915350608131349u2ea41c8bob31e27d40de82630@mail.gmail.com \
--to=gustav@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).