* Re: Reversing lines chunks at a time
2008-09-16 9:07 Reversing lines chunks at a time Rupert Swarbrick
@ 2008-09-16 10:23 ` harven
2008-09-17 18:54 ` Rupert Swarbrick
2008-09-16 20:24 ` Xah
2008-09-17 17:14 ` rgb
2 siblings, 1 reply; 8+ messages in thread
From: harven @ 2008-09-16 10:23 UTC (permalink / raw)
To: help-gnu-emacs
On Sep 16, 11:07 am, Rupert Swarbrick <rswarbr...@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
> 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.
>
> At the moment, I do a crazy jumping forward and back, killing and
> yanking, but I suspect there's a better way! Before I started hacking
> elisp, I was wondering whether there was already a neat way to solve
> this sort of problem that I didn't know about?
>
> Many thanks,
>
> Rupert
>
> application_pgp-signature_part
> < 1KViewDownload
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)))))
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Reversing lines chunks at a time
2008-09-16 10:23 ` harven
@ 2008-09-17 18:54 ` Rupert Swarbrick
0 siblings, 0 replies; 8+ messages in thread
From: Rupert Swarbrick @ 2008-09-17 18:54 UTC (permalink / raw)
To: help-gnu-emacs
[-- Attachment #1: Type: text/plain, Size: 1157 bytes --]
harven <harven@free.fr> 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
I wouldn't expect a mode to realise that the partition I was thinking of
was
A_\alpha^\beta | \times_{\mathrm{t}} | B^n
even if it is "obvious" once the latex is rendered!
Anyway, I think that the anchored-transpose.el rgb pointed me to looks
like it does what I want, although I have some ideas for adding to
it... :)
Rupert
[-- Attachment #2: Type: application/pgp-signature, Size: 314 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Reversing lines chunks at a time
2008-09-16 9:07 Reversing lines chunks at a time Rupert Swarbrick
2008-09-16 10:23 ` harven
@ 2008-09-16 20:24 ` Xah
2008-09-17 18:58 ` Rupert Swarbrick
2008-09-17 17:14 ` rgb
2 siblings, 1 reply; 8+ messages in thread
From: Xah @ 2008-09-16 20:24 UTC (permalink / raw)
To: help-gnu-emacs
On Sep 16, 2:07 am, Rupert Swarbrick <rswarbr...@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
> 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.
>
> At the moment, I do a crazy jumping forward and back, killing and
> yanking, but I suspect there's a better way! Before I started hacking
> elisp, I was wondering whether there was already a neat way to solve
> this sort of problem that I didn't know about?
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
Xah
∑ http://xahlee.org/
☄
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Reversing lines chunks at a time
2008-09-16 20:24 ` Xah
@ 2008-09-17 18:58 ` Rupert Swarbrick
2008-09-17 21:18 ` Xah
0 siblings, 1 reply; 8+ messages in thread
From: Rupert Swarbrick @ 2008-09-17 18:58 UTC (permalink / raw)
To: help-gnu-emacs
[-- Attachment #1: Type: text/plain, Size: 713 bytes --]
Xah <xahlee@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
[-- Attachment #2: Type: application/pgp-signature, Size: 314 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Reversing lines chunks at a time
2008-09-17 18:58 ` Rupert Swarbrick
@ 2008-09-17 21:18 ` Xah
0 siblings, 0 replies; 8+ messages in thread
From: Xah @ 2008-09-17 21:18 UTC (permalink / raw)
To: help-gnu-emacs
On Sep 17, 11:58 am, Rupert Swarbrick <rswarbr...@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.
> 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".
what u want can be written in 30 minutes for me. I'm sure most emacs
developers can write it in 10 min.
> Happy trolling,
yeah, sure thing.
Xah
∑ http://xahlee.org/
☄
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Reversing lines chunks at a time
2008-09-16 9:07 Reversing lines chunks at a time Rupert Swarbrick
2008-09-16 10:23 ` harven
2008-09-16 20:24 ` Xah
@ 2008-09-17 17:14 ` rgb
2008-09-17 18:49 ` Rupert Swarbrick
2 siblings, 1 reply; 8+ messages in thread
From: rgb @ 2008-09-17 17:14 UTC (permalink / raw)
To: help-gnu-emacs
On Sep 16, 4:07 am, Rupert Swarbrick <rswarbr...@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
> 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.
>
> At the moment, I do a crazy jumping forward and back, killing and
> yanking, but I suspect there's a better way! Before I started hacking
> elisp, I was wondering whether there was already a neat way to solve
> this sort of problem that I didn't know about?
>
> Many thanks,
>
> Rupert
>
> application_pgp-signature_part
> < 1KViewDownload
See
http://www.emacswiki.org/cgi-bin/wiki/AnchoredTranspose
It should probably be called swap-regions since that's what it does.
There are several ways to do what you want using it.
Personally I have it mapped to C-x t
In your example you could select the text
G_* \times \Delta^n
C-x t
select \times
C-x t
Poof it's done
If you prefer you could select
\Delta^n
C-x t
G_*
C-x t
Then it's done too.
The order you select things in isn't important.
It works with secondary selection too.
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....
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Reversing lines chunks at a time
2008-09-17 17:14 ` rgb
@ 2008-09-17 18:49 ` Rupert Swarbrick
0 siblings, 0 replies; 8+ messages in thread
From: Rupert Swarbrick @ 2008-09-17 18:49 UTC (permalink / raw)
To: help-gnu-emacs
[-- Attachment #1: Type: text/plain, Size: 1038 bytes --]
rgb <rbielaws@i1.net> writes:
>
> See
> http://www.emacswiki.org/cgi-bin/wiki/AnchoredTranspose
>
(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....
That's exactly what I was after, thanks! And if I think of a better ui
for it, I might hack around and send you the results (not that I can
immediately). About the whitespace issue, that seems sensible - I'll
play with it, but I'd say don't add a customize flag: since the user
already really needs to set up a key binding to use it, they can just
set the keybinding to pass an arg.
Thank you very much!
Rupert
[-- Attachment #2: Type: application/pgp-signature, Size: 314 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread