help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Customising fill-paragrah


From: Xah Lee
Subject: Re: Customising fill-paragrah
Date: Tue, 10 Feb 2009 06:10:03 -0800 (PST)
User-agent: G2/1.0

On Feb 10, 12:02 am, Sebastian Tennant <address@hidden> wrote:
> Hi All,
>
> I'd like to be able to fill (M-q) a paragraph that begins with a colon
> (in column 0) followed by three SPC chars, without it reducing the three
> spaces to one, i.e., so that I can type M-q on the example para below
> without it having any affect.
>
> :   lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem
>     ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum
>
> Also, the indentation of the second line is preserved (once it is set) but
> it would be nice to have fill-paragraph automatically indent the second
> line by four spaces (in auto-fill-mode) if the first line begins with a
> colon.
>
> Any tips/advice/suggestions/pointers much appreciated.
>
> Sebastian

your question is more general than the fill-paragraph.

The essence of fill-paragraph is simple, it just insert a newline char
in every na count number of chars.

What you want to do is easy to write too. Here's the basic steps.
Suppose you are writing my-transform-region.

• check if the first few char is a colon followed by 3 spaces.
• if not, then just call fill-paragraph.
• if so, then move cursor to fill-column number of chars, insert a eol
char, then insert 3 spaces, then repeat the process.

once you have this, you can have a wrapper my-transform function, that
marks a region delimited by 2 eols, then feed it to my-transform-
region. (so that, you don't have to text selection to call it. It'll
just work on the current paragraph)

it'll take maybe 20 to 30 min to write it.

If you know perl, python, php etc but not elisp, you can easily write
it in those lang with a elisp wrapper. Here:

• Elisp Wrapper For Perl Scripts
  http://xahlee.org/emacs/elisp_perl_wrapper.html

if you want to do it in elisp... i can't think of a example code close
to what you want, but this might help:

• Emacs Lisp Idioms
  http://xahlee.org/emacs/elisp_idioms.html

• Suggestions on Emacs's Line-Cutting Commands
  http://xahlee.org/emacs/modernization_fill-paragraph.html

  Xah
∑ http://xahlee.org/

reply via email to

[Prev in Thread] Current Thread [Next in Thread]