* fill-paragraph with pre and postfix
@ 2014-11-05 3:00 Jacob Gerlach
2014-11-05 11:34 ` Alexis
0 siblings, 1 reply; 9+ messages in thread
From: Jacob Gerlach @ 2014-11-05 3:00 UTC (permalink / raw)
To: help-gnu-emacs
Hi list,
A project I'm working on uses a handling function for some command line
documentation:
blk(" I want to format my documentation like this. ");
In order to match the convention for our project, it should include the two
leading spaces and be filled with spaces out to column 70.
The only built in functionality I could find to help with this is
"fill-prefix". Besides not handling the end of the line, I had some trouble
where fill-paragrah didn't seem to actually fill at fill-column like I
expected when I defined a custom prefix.
So my first question is - have I missed a built in capability to do this?
(Alternatively, is there a library in the repos?)
Assuming the answer is no, I set out to write a function that would take a
paragraph of text, fill the text, and wrap it in the function, but I ran in
to some difficulties:
(defun my-fill-and-wrap (start end)
"Fills region and wrap in blk( \"...\");"
(interactive "r")
(let ((fill-column 70)
(fill-prefix " blk( \""))
(goto-char start)
(fill-paragraph)
(save-excursion
(while (< (point) end)
(end-of-line)
(insert-char " "
(- 70 (- (line-end-position) (line-beginning-position))))
(insert "\");")
(forward-line))))))
Executing this function seems to do nothing. No filling, or any change to
the text for that matter. Any pointers on what I'm doing wrong would be
greatly appreciated.
Jake
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: fill-paragraph with pre and postfix
2014-11-05 3:00 fill-paragraph with pre and postfix Jacob Gerlach
@ 2014-11-05 11:34 ` Alexis
[not found] ` <CAA6UvuGBeVzLqqvzY5E8DX7kuMtRiJBuP6-AORsrjPR1uuxTtg@mail.gmail.com>
0 siblings, 1 reply; 9+ messages in thread
From: Alexis @ 2014-11-05 11:34 UTC (permalink / raw)
To: help-gnu-emacs
Jacob Gerlach writes:
> A project I'm working on uses a handling function for some command line
> documentation:
>
> blk(" I want to format my documentation like this. ");
>
> In order to match the convention for our project, it should include the two
> leading spaces and be filled with spaces out to column 70.
Will the text that gets padded with spaces always be less than 70
columns in total?
Alexis.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: fill-paragraph with pre and postfix
[not found] ` <CAA6UvuGBeVzLqqvzY5E8DX7kuMtRiJBuP6-AORsrjPR1uuxTtg@mail.gmail.com>
@ 2014-11-05 12:18 ` Jacob Gerlach
2014-11-06 3:45 ` Alexis
0 siblings, 1 reply; 9+ messages in thread
From: Jacob Gerlach @ 2014-11-05 12:18 UTC (permalink / raw)
To: help-gnu-emacs
---------- Forwarded message ----------
From: "Jacob Gerlach" <jacobgerlach@gmail.com>
Date: Nov 5, 2014 7:17 AM
Subject: Re: fill-paragraph with pre and postfix
To: "Alexis" <flexibeast@gmail.com>
Cc:
On Nov 5, 2014 6:42 AM, "Alexis" <flexibeast@gmail.com> wrote:
>
>
> Jacob Gerlach writes:
>
> > A project I'm working on uses a handling function for some command line
> > documentation:
> >
> > blk(" I want to format my documentation like this.
");
> >
> > In order to match the convention for our project, it should include the
two
> > leading spaces and be filled with spaces out to column 70.
>
> Will the text that gets padded with spaces always be less than 70
> columns in total?
No, the idea is to use this function on a paragraph of text and have it
broken into appropriately sized lines and then wrapped with the format
function. Something akin to fill paragraph.
>
>
> Alexis.
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: fill-paragraph with pre and postfix
2014-11-05 12:18 ` Jacob Gerlach
@ 2014-11-06 3:45 ` Alexis
2014-11-10 15:24 ` Jacob Gerlach
0 siblings, 1 reply; 9+ messages in thread
From: Alexis @ 2014-11-06 3:45 UTC (permalink / raw)
To: help-gnu-emacs
Jacob Gerlach writes:
> On Nov 5, 2014 6:42 AM, "Alexis" <flexibeast@gmail.com> wrote:
>>
>>
>> Jacob Gerlach writes:
>>
>> > A project I'm working on uses a handling function for some command line
>> > documentation:
>> >
>> > blk(" I want to format my documentation like this.
> ");
>> >
>> > In order to match the convention for our project, it should include the
> two
>> > leading spaces and be filled with spaces out to column 70.
>>
>> Will the text that gets padded with spaces always be less than 70
>> columns in total?
>
> No, the idea is to use this function on a paragraph of text and have it
> broken into appropriately sized lines and then wrapped with the format
> function. Something akin to fill paragraph.
*nod* So you'd want output along the lines of:
blk(" I want to format my documentation like this. \nI want to format my documentation like this. I want to format my \ndocumentation like this. ")
?
(Or should /each/ 70-column line be wrapped with 'blk("")'?)
Alexis.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: fill-paragraph with pre and postfix
2014-11-06 3:45 ` Alexis
@ 2014-11-10 15:24 ` Jacob Gerlach
2014-11-11 0:19 ` Alexis
0 siblings, 1 reply; 9+ messages in thread
From: Jacob Gerlach @ 2014-11-10 15:24 UTC (permalink / raw)
To: Alexis, help-gnu-emacs
On Wed Nov 05 2014 at 10:52:13 PM Alexis <flexibeast@gmail.com> wrote:
> (Or should /each/ 70-column line be wrapped with 'blk("")'?)
>
> Almost this. Fill column should be 70, including the blk(". So the
paragraph should be filled to lines of up to 65 chars, then wrapped.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: fill-paragraph with pre and postfix
2014-11-10 15:24 ` Jacob Gerlach
@ 2014-11-11 0:19 ` Alexis
[not found] ` <CAA6UvuEQYgVUkgWD_MkU_mnjYVt6PSXA72RSe9S2YOJmxnNOUg@mail.gmail.com>
0 siblings, 1 reply; 9+ messages in thread
From: Alexis @ 2014-11-11 0:19 UTC (permalink / raw)
To: help-gnu-emacs
Jacob Gerlach writes:
> Fill column should be 70, including the blk(". So the
> paragraph should be filled to lines of up to 65 chars, then wrapped.
Hmm, but from what you said earlier, doesn't each line also need to have
a closing:
")
? Which would mean that the paragraph would be filled to lines of up to
/63/ characters, such that this:
The quick brown fox jumped over the lazy dogs. The quick brown fox
jumped over the lazy dogs. The quick brown fox jumped over the lazy
dogs.
would be transformed to this?
blk("The quick brown fox jumped over the lazy dogs. The quick brown ")
blk("fox jumped over the lazy dogs. The quick brown fox jumped over ")
blk("the lazy dogs. ")
If not, can you please show what the final output should look like?
Alexis.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: fill-paragraph with pre and postfix
[not found] ` <CAA6UvuEQYgVUkgWD_MkU_mnjYVt6PSXA72RSe9S2YOJmxnNOUg@mail.gmail.com>
@ 2014-11-11 8:26 ` Alexis
2014-11-24 19:26 ` Jacob Gerlach
0 siblings, 1 reply; 9+ messages in thread
From: Alexis @ 2014-11-11 8:26 UTC (permalink / raw)
To: help-gnu-emacs
Jacob Gerlach writes:
> On Mon, Nov 10, 2014 at 7:19 PM, Alexis <flexibeast@gmail.com> wrote:
>
>> Hmm, but from what you said earlier, doesn't each line also need to have
>> a closing:
>>
>> ")
>>
> I'm counting 70 up to, but not including the closing "), so the total line
> length should ultimately be 72.
>
>>
>> If not, can you please show what the final output should look like?
>>
> Getting the exact number of chars is not so important - this would be one
> number in the function that I can tweak as necessary. I don't have a
> function that works at all. Do you have any advice on modifying function
> from my original post, or alternatively, a library or other functionality
> that could help with this?
Well, i was going to try putting together some ELisp that does what you
want, as i think it's an interesting thing to do. :-) But, what i'm
primarily confused about is not the exact line length required, but the
overall /structure/ required. Setting aside the issue of the exact line
length required, which of the following forms is what you're after?
1.
blk("This is a sentence "
"stretching over "
"three lines. ")
2.
blk("This is a sentence
stretching over
three lines. ")
[There are fill spaces at the end of the first and second lines.]
3.
blk("This is a sentence ")
blk("stretching over ")
blk("three lines. ")
If none of the above, could you please provide a multi-line example of
the structure - regardless of exact line length - that you require?
Alexis.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: fill-paragraph with pre and postfix
2014-11-11 8:26 ` Alexis
@ 2014-11-24 19:26 ` Jacob Gerlach
2014-11-26 8:48 ` Alexis
0 siblings, 1 reply; 9+ messages in thread
From: Jacob Gerlach @ 2014-11-24 19:26 UTC (permalink / raw)
To: Alexis, help-gnu-emacs
Sorry for the delay, lost track of this thread for awhile.
On Tue Nov 11 2014 at 3:48:32 AM Alexis <flexibeast@gmail.com> wrote:
> Setting aside the issue of the exact line
> length required, which of the following forms is what you're after?
>
> [...]
> 3 .
blk("This is a sentence ")
blk("stretching over ")
> blk("three lines. ")
>
#3 Is exactly what I'm looking for
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: fill-paragraph with pre and postfix
2014-11-24 19:26 ` Jacob Gerlach
@ 2014-11-26 8:48 ` Alexis
0 siblings, 0 replies; 9+ messages in thread
From: Alexis @ 2014-11-26 8:48 UTC (permalink / raw)
To: help-gnu-emacs
Jacob Gerlach writes:
> 3 .
>
> blk("This is a sentence ")
> blk("stretching over ")
> blk("three lines. ")
>
> #3 Is exactly what I'm looking for
Okay, so i think the following is roughly what you're after; for
increased clarity, it makes use of Magnar Sveen's string-manipulation
library s.el (https://github.com/magnars/s.el, available via both MELPA
and Marmalade):
(require 's)
(defun format-paragraph ()
(interactive)
(let* ((leading "blk(\"")
(trailing "\")\n")
(width 65)
(para-start (save-excursion
(backward-paragraph)
(point)))
(para-end (save-excursion
(forward-paragraph)
(point)))
(para (s-replace
"\n" " "
(s-trim
(buffer-substring-no-properties para-start para-end))))
(line "")
(result ""))
(while (not (string= "" para))
(let ((w (if (> (length para) width)
width
(length para))))
(setq line (substring para 0 w))
(if (and (> (length para) width)
(string-match "[^[:space:]]+$" line))
(setq w (match-beginning 0))
(setq w (length para)))
(setq line (s-pad-right width " " (substring para 0 w)))
(setq result (concat result leading line trailing))
(setq para (substring para w))))
(save-excursion
(kill-region para-start para-end)
(goto-char (1+ para-start))
(insert result))))
Hope that helps!
Alexis.
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2014-11-26 8:48 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-05 3:00 fill-paragraph with pre and postfix Jacob Gerlach
2014-11-05 11:34 ` Alexis
[not found] ` <CAA6UvuGBeVzLqqvzY5E8DX7kuMtRiJBuP6-AORsrjPR1uuxTtg@mail.gmail.com>
2014-11-05 12:18 ` Jacob Gerlach
2014-11-06 3:45 ` Alexis
2014-11-10 15:24 ` Jacob Gerlach
2014-11-11 0:19 ` Alexis
[not found] ` <CAA6UvuEQYgVUkgWD_MkU_mnjYVt6PSXA72RSe9S2YOJmxnNOUg@mail.gmail.com>
2014-11-11 8:26 ` Alexis
2014-11-24 19:26 ` Jacob Gerlach
2014-11-26 8:48 ` Alexis
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).