emacs-orgmode
[Top][All Lists]
Advanced

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

Re: [O] function for inserting a block


From: Nicolas Goaziou
Subject: Re: [O] function for inserting a block
Date: Tue, 17 Oct 2017 09:46:38 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux)

Hello,

Eric Abrahamsen <address@hidden> writes:

> Nicolas Goaziou <address@hidden> 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
> #+END_SRC
>
>
> 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
> #+BEGIN_FOO
> This is a paragraph.
>
> #+END_FOO
>
> This is another paragraph.
> #+END_SRC
>
> 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.

Regards,

-- 
Nicolas Goaziou



reply via email to

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