From mboxrd@z Thu Jan 1 00:00:00 1970 From: Leo Vivier Subject: Re: [PATCH 1/2] Fix narrowing for 1-line subtrees Date: Tue, 19 Feb 2019 16:28:28 +0100 Message-ID: <877edvn6g3.fsf@hidden> References: <20190218002547.30325-1-leo.vivier@gmail.com> <87mumsqepg.fsf@nicolasgoaziou.fr> <871s44cbzb.fsf@hidden> <87sgwkoue5.fsf@nicolasgoaziou.fr> <87d0nnnbkf.fsf@hidden> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([209.51.188.92]:33659) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gw7KS-0005HM-LK for emacs-orgmode@gnu.org; Tue, 19 Feb 2019 10:29:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gw7KQ-0005Sa-Pu for emacs-orgmode@gnu.org; Tue, 19 Feb 2019 10:29:04 -0500 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]:35390) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gw7KQ-0004ur-DV for emacs-orgmode@gnu.org; Tue, 19 Feb 2019 10:29:02 -0500 Received: by mail-wm1-x341.google.com with SMTP id y15so3251225wma.0 for ; Tue, 19 Feb 2019 07:28:31 -0800 (PST) In-Reply-To: <87d0nnnbkf.fsf@hidden> 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: Nicolas Goaziou Cc: emacs-orgmode@gnu.org Hello again, Leo Vivier writes: > I was pleased to see that property-adding functions didn't behave badly > with 1-line subtrees. Maybe we could investigate those commands and > patch their behaviour onto the problematic ones? > > If that sounds good to you, I could work on it and submit another patch. I=E2=80=99ve investigated the problem, and I=E2=80=99ve stumbled upon somet= hing interesting. I=E2=80=99ve started by looking at the differences between `org-set-propert= y' and `org-schedule' which respectively led me to `org-insert-property-drawer' and `org-add-planing-info'. The interesting difference is in the way they handle newline insertion: `org-insert-property-drawer': --------------------------------[START]-------------------------------- ... (insert "\n:PROPERTIES:\n:END:") ... ---------------------------------[END]--------------------------------- `org-add-planing-info': --------------------------------[START]-------------------------------- ...=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 (insert-before-markers "\n") ; Inside a cond ... (insert (cl-case what ; Inside a later cond (closed org-closed-string) ... ) " ") ... ---------------------------------[END]--------------------------------- By adapting the `org-add-planing-info' to insert the newline with the scheduling information, I could get it to insert its text *inside* the narrowing with a 1-line subtree. I'm providing a patch at the end of this email, but it's rough around the edges. Notably, I didn't have time to make it work with the condition tree, which means that re-scheduling as well as adding a deadline on top of a scheduled time results in spurious newlines. Correct me if I'm wrong, but I believe we'd be departing the 'hackish' territory with that solution, which would be great. Here's the patch: --------------------------------[START]-------------------------------- Move newline insertion --- lisp/org.el | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index ef6e40ca9..6c43d9b25 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -13046,18 +13046,19 @@ WHAT entry will also be removed." (unless (=3D (skip-chars-backward " \t" p) 0) (delete-region (point) (line-end-position))))))) ((not what) (throw 'exit nil)) ; Nothing to do. - (t (insert-before-markers "\n") - (backward-char 1) + (t (backward-char 1) (when org-adapt-indentation (indent-to-column (1+ (org-outline-level)))))) (when what ;; Insert planning keyword. - (insert (cl-case what - (closed org-closed-string) - (deadline org-deadline-string) - (scheduled org-scheduled-string) - (otherwise (error "Invalid planning type: %s" what))) + (insert "\n" + (cl-case what + (closed org-closed-string) + (deadline org-deadline-string) + (scheduled org-scheduled-string) + (otherwise (error "Invalid planning type: %s" what))) " ") + (end-of-line) ;; Insert associated timestamp. (let ((ts (org-insert-time-stamp time --=20 2.20.1 ---------------------------------[END]--------------------------------- HTH. Best, --=20 Leo Vivier English Studies & General Linguistics Master Student, English Department Universit=C3=A9 Rennes 2