Eric Abrahamsen <e...@ericabrahamsen.net> writes:

> Nicolas Goaziou <m...@nicolasgoaziou.fr> writes:

>>> +    (if (bolp)
>>> +   (progn
>>> +     (skip-chars-backward " \n\t")
>>> +     (forward-char))
>>> +      (end-of-line)
>>> +      (insert "\n"))
>> I don't understand this part. In particular, the `forward-char' looks
>> wrong. Do you mean `forward-line' ? If so, do you handle the case where
>> buffer doesn't end with a newline character?
> This was a bit of finicky code mostly for aesthetic purposes. It has to
> do with this case (the second clause in the test I added):
> #+BEGIN_SRC org
> This is a paragraph
> This is another paragraph
> If point is on the first paragraph and the region is not active,
> `org-mark-element' will mark the paragraph and all following whitespace,
> which means we end up with:
> #+BEGIN_SRC org
> This is a paragraph.
> This is another paragraph.
> Which just looked bad to me (even though it probably behaves perfectly
> correctly). So if point is at bol, it skips back over the whitespace and
> then moves forward one char, presumably leaving point right after the
> marked element.

Then it's `forward-line', not `forward-char', because there could be
trailing spaces at the end of the paragraph, e.g.

   This is a paragraph.<SPC><SPC>

Also, my question still holds, what about the last paragraph in a buffer
not ending with a newline character, e.g.

  This is the last paragraph.<EOB>

You need to insert a newline character in this case.


Nicolas Goaziou

Reply via email to