From mboxrd@z Thu Jan 1 00:00:00 1970 From: Samuel Wales Subject: newlines and buffer corruption [was Re: [PATCH] org-capture: fix capture breaking next headline] Date: Wed, 24 Oct 2018 16:53:21 -0700 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:45367) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFSy6-0007rq-BA for emacs-orgmode@gnu.org; Wed, 24 Oct 2018 19:53:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFSy5-00064c-9D for emacs-orgmode@gnu.org; Wed, 24 Oct 2018 19:53:42 -0400 Received: from mail-lf1-x142.google.com ([2a00:1450:4864:20::142]:37199) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gFSy4-0005cq-S0 for emacs-orgmode@gnu.org; Wed, 24 Oct 2018 19:53:41 -0400 Received: by mail-lf1-x142.google.com with SMTP id a82-v6so5359404lfa.4 for ; Wed, 24 Oct 2018 16:53:23 -0700 (PDT) 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: =?UTF-8?B?TWFydGluIFlyasO2bMOk?= Cc: Org Mode whether it is an example of it i am not sure, but the case in the org-capture thread is typical of a class of buffer corruption bugs that is common in org. if you have found similar corruption in your org files and wondered why, this is probably the cause. newlines that you didn't enter are also related. examples: 1 in capture i use hooks to fix whitespace. 2 in block editing, c-c ', you can get similar issues at the end of the block. [this example, however, might be a cultural influence of the root cause and not a bug caused by the root cause.] 3 at one point long ago i reported a bug where sorting in a narrowed region would corrupt the buffer. this had gone unnoticed probably because when you sort it is not obvious that the buffer was corrupted. also there are similar things with org tree to indirect buffer. === when i looked into it a long time ago, the root cause was the design of outline mode of which org was or is a derived mode. at least one outline mode function acts as if an entry or subtree starts before the first star and ends before -- yes, before -- the final newline in the entry text contents. frequent org coders probably know this, but probably not everybody does. people write workarounds to fix it, or they have no problem with it and they code to it, or they aren't aware of it and don't account for it. for edge cases. which they forget all about when the bug occurs. then code gets called by other code, which means there are assumptions sometimes broken, or workarounds that are necessary, and then there is buffer corruption. this touches on old debates. it isn't just emacs. look at crontab and wc. i predict that more bugs [and user workarounds] will occur.