From mboxrd@z Thu Jan 1 00:00:00 1970 From: brian powell Subject: Re: Sorting table columns (*not* content) Date: Mon, 1 Nov 2010 11:39:53 -0400 Message-ID: References: <20101101144342.GA2450@soloJazz.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============1263805255==" Return-path: Received: from [140.186.70.92] (port=42230 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PCwUK-0007ad-AK for emacs-orgmode@gnu.org; Mon, 01 Nov 2010 11:40:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PCwUG-0008AP-S1 for emacs-orgmode@gnu.org; Mon, 01 Nov 2010 11:39:59 -0400 Received: from mail-px0-f169.google.com ([209.85.212.169]:44207) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PCwUG-00089x-6V for emacs-orgmode@gnu.org; Mon, 01 Nov 2010 11:39:56 -0400 Received: by pxi12 with SMTP id 12so867981pxi.0 for ; Mon, 01 Nov 2010 08:39:54 -0700 (PDT) In-Reply-To: <20101101144342.GA2450@soloJazz.com> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Juan Pechiar Cc: emacs-orgmode@gnu.org --===============1263805255== Content-Type: multipart/alternative; boundary=0016e64c25f69952640493ff9ef2 --0016e64c25f69952640493ff9ef2 Content-Type: text/plain; charset=ISO-8859-1 Jeff Horn seems to be explaining specifics of how to do some nitty-gritty manipulations--he mentions (quoting the manual) methods for yanking, Ccxy The methods Jeff expressed are useful for the question posed. I recommend rectangle-kill and rectangle-yank--Cxrk and Cxry to solve this (in a very simple albeit possibly faster or slower way--depending on how many columns you want to move/sort---moving column/rectangle 3 to the 3rd position in this case--took a few seconds) I tested Juan's method/defun---works grrrrreat!! Thanks Juan P.S. I did lose the hlines like you reported; but, to put the line back was 3 key strokes: |-Tab On Mon, Nov 1, 2010 at 10:43 AM, Juan Pechiar wrote: > If you don't mind losing h-lines, you can transpose the table, sort > rows, and transpose back. > > This code (which I previously posted to the list) transposes a table: > > #+begin_src: emacs-lisp > > (defun org-transpose-table-at-point () > "Transpose orgmode table at point, eliminate hlines" > (interactive) > (let ((contents (apply #'mapcar* #'list > (remove-if-not 'listp ;; remove 'hline from list > (org-table-to-lisp)))) ;; signals > error if not table > ) > (delete-region (org-table-begin) (org-table-end)) > (insert (mapconcat (lambda(x) (concat "| " (mapconcat 'identity x " | " > ) " |\n" )) > contents > "")) > (org-table-align) > ) > ) > > #+end_src > > Regards, > .j. > > On Mon, Nov 01, 2010 at 02:42:55PM +0100, Gary wrote: > > Is there any way to sort the columns of a table, such that for example > > > > | Col 3 | Col 1 | Col 2 | > > > > can be converted to > > > > | Col 1 | Col 2 | Col 3 | > > |-------+-------+-------| > > | ... | ... | ... | > > > > ? > > _______________________________________________ > Emacs-orgmode mailing list > Please use `Reply All' to send replies to the list. > Emacs-orgmode@gnu.org > http://lists.gnu.org/mailman/listinfo/emacs-orgmode > --0016e64c25f69952640493ff9ef2 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Jeff Horn seems to be explaining specifics of how to do some nitty-gritty m= anipulations--he mentions (quoting the manual) methods for yanking, Ccxy
The methods Jeff expressed are useful for the question pos= ed.

I recommend rectangle-kill and rectangle-yank--Cxrk and= Cxry to solve this (in a very simple albeit possibly faster or slower way-= -depending on how many columns you want to move/sort---moving column/rectan= gle 3 to the 3rd position in this case--took a few seconds)

I tested Juan's method/defun---works grrrrreat!!
Thanks Juan

P.S. I did lose the hlines like you= reported; but, to put the line back was 3 key strokes: |-Tab

On Mon, Nov 1, 2010 at 10:43 AM, Juan Pechia= r <juan@pechiar.co= m> wrote:
If you don't mind losing h-lines, you can transpose the table, sort
rows, and transpose back.

This code (which I previously posted to the list) transposes a table:

#+begin_src: emacs-lisp

(defun org-transpose-table-at-point ()
=A0"Transpose orgmode table at point, eliminate hlines"
=A0(interactive)
=A0(let ((contents (apply #'mapcar* #'list
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (remove-if-not 'listp = =A0;; remove 'hline from list
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0(org-table-to-lisp)))) =A0;; signals error if not table
=A0 =A0 =A0 =A0)
=A0 =A0(delete-region (org-table-begin) (org-table-end))
=A0 =A0(insert (mapconcat (lambda(x) (concat "| " (mapconcat = 9;identity x " | " ) " =A0|\n" ))
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 contents
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ""))
=A0 =A0(org-table-align)
=A0 =A0)
)

#+end_src

Regards,
.j.

On Mon, Nov 01, 2010 at 02:42:55PM +0100, Gary wrote:
> Is there any way to sort the columns of a table, such that for example=
>
> | Col 3 | Col 1 | Col 2 |
>
> can be converted to
>
> | Col 1 | Col 2 | Col 3 |
> |-------+-------+-------|
> | ... =A0 | ... =A0 | ... =A0 |
>
> ?

_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

--0016e64c25f69952640493ff9ef2-- --===============1263805255== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Emacs-orgmode mailing list Please use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode --===============1263805255==--