all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Customising fill-paragrah
@ 2009-02-10  8:02 Sebastian Tennant
  0 siblings, 0 replies; 4+ messages in thread
From: Sebastian Tennant @ 2009-02-10  8:02 UTC (permalink / raw
  To: help-gnu-emacs

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
-- 
Emacs' AlsaPlayer - Music Without Jolts
Lightweight, full-featured and mindful of your idyllic happiness.
http://home.gna.org/eap





^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Customising fill-paragrah
       [not found] <mailman.283.1234252813.31690.help-gnu-emacs@gnu.org>
@ 2009-02-10 14:10 ` Xah Lee
  2009-02-14  2:32   ` Iain Dalton
  2009-02-11 21:44 ` Chetan
  1 sibling, 1 reply; 4+ messages in thread
From: Xah Lee @ 2009-02-10 14:10 UTC (permalink / raw
  To: help-gnu-emacs

On Feb 10, 12:02 am, Sebastian Tennant <seb...@smolny.plus.com> 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/^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Customising fill-paragrah
       [not found] <mailman.283.1234252813.31690.help-gnu-emacs@gnu.org>
  2009-02-10 14:10 ` Customising fill-paragrah Xah Lee
@ 2009-02-11 21:44 ` Chetan
  1 sibling, 0 replies; 4+ messages in thread
From: Chetan @ 2009-02-11 21:44 UTC (permalink / raw
  To: help-gnu-emacs

Sebastian Tennant <sebyte@smolny.plus.com> writes:

> 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.

However, the third line is indented as per the second line then, so I
guess it is only the second line that is a problem with auto fill. 
Short of writing elisp code, it might just be easier to define a
keyboard macro that replaces the colon with a space and back.

>
> Any tips/advice/suggestions/pointers much appreciated.
>
> Sebastian


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Customising fill-paragrah
  2009-02-10 14:10 ` Customising fill-paragrah Xah Lee
@ 2009-02-14  2:32   ` Iain Dalton
  0 siblings, 0 replies; 4+ messages in thread
From: Iain Dalton @ 2009-02-14  2:32 UTC (permalink / raw
  To: help-gnu-emacs

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

I'd expect it to be easier.  Here's my version, which took me 10
minutes, and that's because I've never written an elisp function
before and didn't know fill-paragraph and move-b-o-l need args.  It
goes something like this:

(defun colon-list-fill-paragraph ()
 (interactive)
 (backward-paragraph)
 (forward-line)
 (fill-paragraph nil)
 (next-line)
 (insert "    ")
 (fill-paragraph nil)
 (move-beginning-of-line 1)
 (previous-line)
 (forward-char)
 (insert "  "))

The only problem with this hastily hacked function is that your first
line may be two chars too long.  You could improve it with Chetan's
idea of replacing your paragraph's first char with space, doing what
you need to do, then replacing with a colon.

Remember, functions do exactly what you can do with the keyboard.  You
can write one by doing what you want your function to do by hand,
recording your keystrokes, learning the functions your keystrokes
invoke (C-h c), and writing them into the function body.

For that matter, consult the Emacs manual on Keyboard Macros, and you
can write a function without knowing Emacs Lisp.  Unfortunately you
may not understand your resulting function because it looks like a
string of numbers.




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-02-14  2:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.283.1234252813.31690.help-gnu-emacs@gnu.org>
2009-02-10 14:10 ` Customising fill-paragrah Xah Lee
2009-02-14  2:32   ` Iain Dalton
2009-02-11 21:44 ` Chetan
2009-02-10  8:02 Sebastian Tennant

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.