I would like to edit text in boustrophedon in emacs. For those of you who don't know boustrophedon text direction goes "like an ox turns" in a field or like a printer inkjet. For the same reasons this is efficient on a farm or in a printer this text is very efficient to read once you get used to it (which doesn't take too long).
more on boustrophedon typesetting/layout:
http://www.ntg.nl/pipermail/aleph/2004-March/000094.html
To my knowledge there are no implementations of this typesetting style and I am stumped on how to implement it.
Any ideas as to how this could be done?
Thanks,
Andreas
I assume that advising self-insert-command, intercepting the events, and modifying the buffer accordingly is what you want to do. You will then need to rebind the directional commands (forward-char and friends are reversed on opposite lines), and so on.
A lot of work, but definitely possible.
Before you write anything too complicated, ask on emacs-devel. As the comments suggest, it might be useful to have generic support for something like this... although arbitrary snippets of text with different directions won't word-wrap (when inserting) the same way your text will.
Edit: Apparently advising self-insert-command doesn't quite work for this, so you will need to setup a keymap (and bind ?a to (my-new-insert-command ?a) and so on...).
You could write it in sed I hacked the rev script from the sed1liners text to skip a line and then rev every other line:
alias boustrophedon='sed -n "1{p;b a};{/\n/!G;s/\(.\)\(.*\n\)/&\2\1/;//D;s/.//;p};n;p;:a"'
$> echo -en "This\nis\nBoustrou...\ntext\non\ndisplay\nhere.\n" | boustrophedon
This
si
Boustrou...
txet
on
yalpsid
here.
Or, if you want to process a whole file:
$> boustrophedon <filename>
Related
I have a new version of a moinmoin wiki macro called Color2 that I have installed and now the color declarations come after the content. For example, before, it looked like this to declare, "I am hungry", with a white text color:
<<Color2(white,I am hungry)>>
Now, it's been changed. They switched it so the color is declared after the content:
<<Color2(I am hungry,white)>>
The syntax can get a little more complicated than this but, in our case, it is most often used in this manner.
I have about 400 pages of content in my wiki where I'd really like to do a color-declaration switch-er-oo. Preferably, I'd like to find all the instances of <<Color2(white,*)>> and replace them with <<Color2(*,white)>> and then again with red, yellow, blue, etc.
But this is a bit beyond my grep, sed and awk skills. Are there any masters kind and skilled enough to show me how this can quickly be done?
UPDATE:
I was able to make a sweet script based on Philipp's suggestion:
#!/bin/sh
cat $1 | sed 's/Color2(\([^)]*\),\([^)]*\))/Color2(\2,\1)/g'
exit 0
This elegantly captures most situations quite reliably (those where the color is delimited from the text by a comma, which isn't all of them, BTW). Thanks again, Philipp. Here's the syntax, if we name the script "script.sh": script.sh /path/to/text_file.txt > /path/to/new_file.txt
Maybe not super sophisticated, but works (for white). If you want to do what you planned, then replace white with a different color. Not sure, how different your formatting can be, but it may require adjustment of the command. So let us know if this solution doesn't work for you, so that people can give a better reply.
cat /tmp/t
<<Color2(white,I am hungry)>>
sed 's/Color2(white,\([^)]*\))/Color2(\1,white)/' /tmp/t
<<Color2(I am hungry,white)>>
I'd like to use emacs in some kind of batch mode to just render a file with syntax highlighting and exit. Specifically, I want to dump the fontified buffer with ANSI escape codes so that it shows up reasonably syntax-highlighted on my terminal. Is there any way to do this?
The ansi-lpr.el library seems to be kind of along the lines of what I want, but the output isn't colorified. I can't figure out how to get over that final hurdle — there are a lot of modules to digest ANSI escape codes into Emacs text properties (e.g. ansi-color.el) but I haven't found anything that does the reverse. If anyone can point me to something that does, I think I can piece together the rest.
Alternatively, I've seen some hacky approaches like this answer (using script and capturing the output) but in my experiments that approach has seemed unlikely to be fruitful — you get tons of undesirable control sequences mixed in with the highlighted text.
The overarching motivation here is to use emacs in a $LESSOPEN pipe to get syntax highlighting when I page files. In case you're going to say it, I've tried and "just page files in Emacs" is not acceptable for me.
I'm glad to announce a new package, e2ansi, that (hopefully) does what you asked for.
The package provides a command-line tool e2ansi-cat that starts Emacs in batch mode, opens files, syntax highlight them (using font-lock), and creates ANSI-colored versions of the syntax highlighted files.
You can integrate this into less by setting the following variables to, for example:
export "LESSOPEN=|emacs --batch -Q -l ~/.emacs -l bin/e2ansi-cat %s"
export "LESS=-R"
export MORE=$LESS
The end result looks like the following:
You can vary the colors and attributes like bold, underline, and
italics by using a suitable Emacs theme.
The e2ansi package is located at https://github.com/Lindydancer/e2ansi
Personal note
I would like to thank you for posting this question, it directly inspired me to write e2ansi.
I'm trying to edit documents (MultiMarkdown), that will do an auto-fill on paragraphs that are not indented 4 spaces, and will NOT do an auto-fill on paragraphs that ARE indented 4 spaces.
Where should I start to look to figure out how to code this?
You are going to need fill-paragraph, if, probably progn, probably string=, save-excursion, forward-paragraph, backward-paragraph and perhaps a few more. All of these can be read up if you do M-x describe-function and supply it the name.
As for the how, it is in your question. If the paragraph begins with 4 blank space letters, fill-paragraph.
Does that answer? Have I missed anything?
Where should I start to look to figure
out how to code this?
I think this is too general a question to answer. We don't know anything about your background in programming. Do you know Lisp? Do you know elisp? How well do you know Emacs? Do you know about advice? etc.
Programming in Emacs is well documented (introduction and reference). I suggest you start playing around with the fill- functions - when you run into more concrete problems with that, I'm sure it will be easier for people to help you out.
I want to fully-justify latex code on EMACS so that my latex code will look better. For example, I remember my advisor sending me latex in fully justified way like this:
In ~\cite{Hummel2004}, authors described an approach for harvesting
software components from the Web. The basic idea is to use the Web as
the underlying repository, and to utilize standard search engines,
such as Google, as the means of discovering appropriate software
assets. Other researchers have crawled through Internet publicly
available CVS repositories to build their own source code search
engines (e.g., SPARS-J)~\cite{Matsushita2005}.
I suppose that his column-width is set to 70 columns.
Could someone give me a hint?
The standard fill.el package includes the command justify-current-line which is part of what you need. From the function help:
Do some kind of justification on this line.
Normally does full justification: adds spaces to the line to make it end at
the column given by `current-fill-column'.
Optional first argument how specifies alternate type of justification:
it can be `left', `right', `full', `center', or `none'.
If how is t, will justify however the `current-justification' function says to
And other posters have already given you the magicall invokation:
M-x set-justification
As a philosophical side note, the point of fixed-wdith text justification is to fake real typography on a inflexible output device. So applying it to LaTeX source seems a little odd to me. Moreover, I have been using the "one sentence to a line" approach to LaTeX documents for some months now, and find that it really does improves both the editability and the source-control behavior of LaTeX, so I would recommend against doing this.
If you select the region, and then press Ctrl-u M-x fill-region you get "full justification".
M-x set-justification-full
Use Refill mode afterwards to not have to run the command again after typing.
To get line wrap in the file itself (as opposed to something like longlines-mode that does not alter the structure of the file), I use auto-fill-mode, which automatically applies M-q (fill-paragraph) to each paragraph. For example, I use auto-fill-mode in mail-mode. You could do something similar with your LaTeX mode with a hook like this:
(add-hook 'TeX-mode-hook 'turn-on-auto-fill)
Assuming your TeX mode's hook is TeX-mode-hook.
I'm writing a text with Latex in English but written my comments in Finnish. When I'm running the spell checking with ispell, I got to run through all the comments. Is there a handy way to skip the comments with the ispell? If that could be done with emacs, that would be double handy =)
One way would be to run the ispell within console and process the input with sed, for example, but I'd like to have my changes straight on the file...
(setq ispell-check-comments nil)
You'd have to dig in the code a bit, but when you spell-check a file, it's running the detex tool to strip out the TeX code. You should be able to modify the pipeline to have a sed or perl script strip the comment lines.
I kind of vaguely think AuC-TeX makes this configurable, but 30 seconds looking didn't reveal it.
Adding a modern answer to this old question, because I also had the problem:
Just use aspell, which does this out of the box.