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

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

fill-paragraph with pre and postfix


From: Jacob Gerlach
Subject: fill-paragraph with pre and postfix
Date: Tue, 4 Nov 2014 22:00:14 -0500

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


reply via email to

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