Reversing lines chunks at a time
  Home FAQ Contact Sign in
gnu.emacs.help only
 
Advanced search
POPULAR GROUPS

more...

gnu.emacs.help Profile…
 Up
Reversing lines chunks at a time         


Author: Rupert Swarbrick
Date: Sep 16, 2008 02:07

Hi,

I have the following sort of transformation that I have to do fairly
often. For example, when writing LaTeX code, I might have a line in
maths mode which looks like

G_*[n] = G_* \times \Delta^n

(this defines the left hand side to be the Cartesian product of a G with
a star and a capital delta with a superscript n, for those reading who
aren't au fait with LaTeX). Anyway, suppose I wanted the product the
other way round:

G_*[n] = \Delta^n \times G_*

I'm using Auctex, which is pretty brilliant, but it's syntax table
breaks at quite a few characters other than whitespace for word
boundaries. I don't particularly want to change that: it seems
reasonable, but it means that the transpose-* commands don't really help
in this case: you end up mangling together bits of the various
sections.

Moreover, I sometimes don't bother, say, putting a space before the
\times, which is still perfectly fine LaTeX, but it means that there
would be no way for Auctex to sensibly see what to do.
Show full article (1.60Kb)
7 Comments
Re: Reversing lines chunks at a time         


Author: harven
Date: Sep 16, 2008 03:23

On Sep 16, 11:07 am, Rupert Swarbrick gmail.com> wrote:
> Hi,
>
> I have the following sort of transformation that I have to do fairly
> often. For example, when writing LaTeX code, I might have a line in
> maths mode which looks like
>
>   G_*[n] = G_* \times \Delta^n
>
> (this defines the left hand side to be the Cartesian product of a G with
> a star and a capital delta with a superscript n, for those reading who
> aren't au fait with LaTeX). Anyway, suppose I wanted the product the
> other way round:
>
>   G_*[n] = \Delta^n \times G_*
>
> I'm using Auctex, which is pretty brilliant, but it's syntax table
> breaks at quite a few characters other than whitespace for word
> boundaries. I don't particularly want to change that: it seems
> reasonable, but it means that the transpose-* commands don't really help ...
Show full article (1.86Kb)
no comments
Re: Reversing lines chunks at a time         


Author: Xah
Date: Sep 16, 2008 13:24

On Sep 16, 2:07 am, Rupert Swarbrick gmail.com> wrote:
> Hi,
>
> I have the following sort of transformation that I have to do fairly
> often. For example, when writing LaTeX code, I might have a line in
> maths mode which looks like
>
> G_*[n] = G_* \times \Delta^n
>
> (this defines the left hand side to be the Cartesian product of a G with
> a star and a capital delta with a superscript n, for those reading who
> aren't au fait with LaTeX). Anyway, suppose I wanted the product the
> other way round:
>
> G_*[n] = \Delta^n \times G_*
>
> I'm using Auctex, which is pretty brilliant, but it's syntax table
> breaks at quite a few characters other than whitespace for word
> boundaries. I don't particularly want to change that: it seems
> reasonable, but it means that the transpose-* commands don't really help ...
Show full article (1.73Kb)
no comments
Re: Reversing lines chunks at a time         


Author: rgb
Date: Sep 17, 2008 10:14

On Sep 16, 4:07 am, Rupert Swarbrick gmail.com> wrote:
> Hi,
>
> I have the following sort of transformation that I have to do fairly
> often. For example, when writing LaTeX code, I might have a line in
> maths mode which looks like
>
>   G_*[n] = G_* \times \Delta^n
>
> (this defines the left hand side to be the Cartesian product of a G with
> a star and a capital delta with a superscript n, for those reading who
> aren't au fait with LaTeX). Anyway, suppose I wanted the product the
> other way round:
>
>   G_*[n] = \Delta^n \times G_*
>
> I'm using Auctex, which is pretty brilliant, but it's syntax table
> breaks at quite a few characters other than whitespace for word
> boundaries. I don't particularly want to change that: it seems
> reasonable, but it means that the transpose-* commands don't really help ...
Show full article (2.44Kb)
no comments
Re: Reversing lines chunks at a time         


Author: Rupert Swarbrick
Date: Sep 17, 2008 11:49

rgb i1.net> writes:
(snip explanation of use)
> If I remember correctly by default it ignores white space around your
> selection. IOW you may need to C-u C-x M-t to have it swap correctly
> (stop ignoring whitespace).
> But if you find yourself needing the C-u behavior you can make this
> change.
>
> (interactive `(,(region-beginning) ,(region-end)
> ,current-prefix-arg
> to
> (interactive `(,(region-beginning) ,(region-end)
> ,(not current-prefix-arg)
>
> Hmm, maybe the routine needs a cust flag....
Show full article (1.36Kb)
no comments
Re: Reversing lines chunks at a time         


Author: Rupert Swarbrick
Date: Sep 17, 2008 11:54

harven writes:
> You could hack the syntax-table in TeX-mode for the transpose-words
> command only. e.g.
>
> (setq my-wacky-syntax-table (copy-syntax-table))
> (dolist (char '(?^ ?\ ?* ?_ ?$))
> (modify-syntax-entry char "w" my-wacky-syntax-table))
>
> (add-hook 'TeX-mode-hook (lambda ()
> (define-key TeX-mode-map "\M-t"
> '(lambda () (interactive)
> (with-syntax-table my-wacky-syntax-table (transpose-words 1)))))

Ah thanks, that's a good point - although I don't always have spaces in
helpful places. I don't think I made it very clear, but I was after
something that you could "just tell" what to move, since the syntax
was variable enough that it wouldn't be reasonable to expect anything to
guess right. For example, in the string of characters below,

A_\alpha^\beta\times_{\mathrm{t}}B^n
Show full article (1.48Kb)
no comments
Re: Reversing lines chunks at a time         


Author: Rupert Swarbrick
Date: Sep 17, 2008 11:58

Xah gmail.com> writes:
>
> harven suggested a solution that uses syntax table.
>
> i'd just write a simple elisp that process the current line or region.
> This is such as good exercise if you haven't tried elisp for text
> processing yet.
>
> The functions listed in this page is probably all you need:
> http://xahlee.org/emacs/elisp_common_functions.html

Thank you, Xah.

It's always nice to be both patronised and given no help. I actually
already have some experience writing elisp, but a "simple elisp" (do you
actually mean a new implementation of the language?!) isn't what I was
after. Indeed I wanted something a lot more like what rgb
suggested. This wasn't "simple".

Happy trolling,

Rupert
Show full article (1.04Kb)
no comments
Re: Reversing lines chunks at a time         


Author: Xah
Date: Sep 17, 2008 14:18

On Sep 17, 11:58 am, Rupert Swarbrick gmail.com> wrote:
>> harven suggested a solution that uses syntax table.
>
>> i'd just write a simple elisp that process the current line or region.
>> This is such as good exercise if you haven't tried elisp for text
>> processing yet.
>
>> The functions listed in this page is probably all you need:
>>http://xahlee.org/emacs/elisp_common_functions.html
>
> Thank you, Xah.
>
> It's always nice to be both patronised and given no help.

You mentioned whether there's already some way to do it, and asked
wheter you should just write elisp.

I'm answering to the effect that there's no existing command to do
what u want, and suggest that writing your own elisp command is
probably best solution, and gave you tips from my website tutorial on
how this could be done.
Show full article (1.27Kb)
no comments