GNU bug report logs -
#78561
[PATCH] Add semantic linefeed support for paragraph filling
Previous Next
Full log
Message #23 received at 78561 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Stefan Monnier <monnier <at> iro.umontreal.ca> writes:
>> Given that this is a first version, I have not added any reference to
>> the manuals. If you think it makes sense, please let me know and I'll
>> modify the patch accordingly.
>
> Maybe a short version of the explanation you give below would be good to
> have in the manual (tho Eli suggests a URL instead, so maybe that's
> good enough?).
>
>> +(defun fill-paragraph-semlf (&optional justify)
>> + "Fill paragraph at or after point using semantic linefeeds.
>> +
>> +This function ensures that a newline character follows every
>> +sentence, as punctuated by a period (.), exclamation mark (!), or
>> +question mark (?).
>
> This seems inaccurate: it just uses whichever definition of sentence is
> used by `forward-sentence`, so it may ignore some of those chars or pay
> attention to others.
I have updated the patch with a more precise definition. Also, I added
links to the sources I referenced for semantic linefeeds.
>> +If JUSTIFY is non-nil (interactively, with prefix argument), justify as
>> +well. If `sentence-end-double-space' is non-nil, then period followed
>> +by one space does not end a sentence, so don't break a line there. The
>> +variable `fill-column' controls the width for filling."
>
> I'd move the "The" to the last line. 🙂
Fixed :)
>> + (interactive "P")
>> + (save-excursion
>> + (let ((end (progn
>> + (fill-forward-paragraph 1)
>> + (backward-word)
>> + (end-of-line)
>> + (point)))
>> + (start (progn
>> + (fill-forward-paragraph -1)
>> + (forward-word)
>> + (beginning-of-line)
>> + (point)))
>> + pfx)
>> + (with-restriction start end
>> + (let ((fill-column (point-max)))
>> + (setq pfx (or (fill-region-as-paragraph (point-min) (point-max)) "")))
>> + (goto-char (point-min))
>> + (while (not (eobp))
>> + (let ((fill-prefix pfx))
>> + (fill-region-as-paragraph (point)
>> + (progn (forward-sentence) (point))
>> + justify))
>> + (when (and (> (point) (line-beginning-position))
>> + (< (point) (line-end-position)))
>> + (delete-horizontal-space)
>> + (newline)
>> + (insert pfx))))))
>> + t)
>
> Please try and separate it into a `fill-region-semlf` function and then
> another one which applies it to a paragraph, so that it can also be used
> to fill a specific user-specified region (or the whole buffer).
I'm not sure about this one. The idea is that `fill-paragraph-semlf'
can be assigned as a value for `fill-paragraph-function' (I also
included a mention to this in the doc string) or it ca be called
directly. The thing is that `fill-paragraph' docs say:
The REGION argument is non-nil if called interactively; in that
case, if Transient Mark mode is enabled and the mark is active,
call `fill-region' to fill each of the paragraphs in the active
region, instead of just filling the current paragraph.
And `fill-paragraph-function' docs say:
Note: This only affects ‘fill-paragraph’ and not ‘fill-region’
nor ‘auto-fill-mode’
So, if I'm not wrong, filling regions and paragraphs is different in the
current design.
I agree that it would be useful to apply `fill-paragraph-semlf' on a
region or the whole buffer. But, the same could be said about any other
`fill-paragraph-function'. So, do we really want a specific
`fill-region-semlf' function?
I attach a new version of the patch.
Thanks!
[0001-Add-semantic-linefeed-support-for-paragraph-filling.patch (text/x-patch, attachment)]
This bug report was last modified 10 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.