From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: function for inserting a block Date: Tue, 17 Oct 2017 09:46:38 +0200 Message-ID: <87fuaiz069.fsf@nicolasgoaziou.fr> References: <877exghblx.fsf@ericabrahamsen.net> <87efromccg.fsf@nicolasgoaziou.fr> <87ziabepxt.fsf@ericabrahamsen.net> <87bmml2fb0.fsf@ericabrahamsen.net> <87fubuzpsa.fsf@nicolasgoaziou.fr> <874lsabdop.fsf@ericabrahamsen.net> <87vak1l11m.fsf@nicolasgoaziou.fr> <87r2uoc4q7.fsf@ericabrahamsen.net> <87bmllk5xy.fsf@nicolasgoaziou.fr> <878tgmwwsa.fsf@ericabrahamsen.net> <87po9q2e8k.fsf@nicolasgoaziou.fr> <87tvyyvpst.fsf@ericabrahamsen.net> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:51707) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4MaN-0005Nw-9R for emacs-orgmode@gnu.org; Tue, 17 Oct 2017 03:46:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e4MaJ-0007RG-8I for emacs-orgmode@gnu.org; Tue, 17 Oct 2017 03:46:47 -0400 Received: from relay4-d.mail.gandi.net ([217.70.183.196]:45989) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e4MaJ-0007QY-2L for emacs-orgmode@gnu.org; Tue, 17 Oct 2017 03:46:43 -0400 In-Reply-To: <87tvyyvpst.fsf@ericabrahamsen.net> (Eric Abrahamsen's message of "Mon, 16 Oct 2017 12:46:42 -0700") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: Eric Abrahamsen Cc: emacs-orgmode@gnu.org Hello, Eric Abrahamsen writes: > Nicolas Goaziou 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. 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. You need to insert a newline character in this case. Regards, -- Nicolas Goaziou