From 8b18405857dbc20cb79025cffdb003db8a4eeca8 Mon Sep 17 00:00:00 2001 From: Bastien Date: Thu, 13 May 2021 14:56:18 +0200 Subject: [PATCH] Throw user errors when trying to drag inline tasks * lisp/org.el (org-metaup, org-metadown): Throw a user error explaining that dragging inline tasks is not supported. * lisp/org-inlinetask.el (org-inlinetask-insert-task) (org-inlinetask-promote, org-inlinetask-demote): Fix bug when demoting/promoting inline tasks at the end of the buffer and throw user errors instead of errors. Based on an initial patch by Carsten. Reported-by: Christian Hemminghaus Link: https://orgmode.org/list/CAE47VC=yhObXs3jexLUkf53cNzcOWUkTMqpF8QK4Dcg98QijyQ@mail.gmail.com/ --- lisp/org-inlinetask.el | 22 ++++++++++++++-------- lisp/org.el | 6 ++++++ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/lisp/org-inlinetask.el b/lisp/org-inlinetask.el index 48402b092..a1e4ef2fc 100644 --- a/lisp/org-inlinetask.el +++ b/lisp/org-inlinetask.el @@ -131,7 +131,7 @@ If there is a region wrap it inside the inline task." ;; before this one. (when (and (org-inlinetask-in-task-p) (not (and (org-inlinetask-at-task-p) (bolp)))) - (error "Cannot nest inline tasks")) + (user-error "Cannot nest inline tasks")) (or (bolp) (newline)) (let* ((indent (if org-odd-levels-only (1- (* 2 org-inlinetask-min-level)) @@ -225,7 +225,7 @@ If the task has an end part, promote it. Also, prevents level from going below `org-inlinetask-min-level'." (interactive) (if (not (org-inlinetask-in-task-p)) - (error "Not in an inline task") + (user-error "Not in an inline task") (save-excursion (let* ((lvl (org-inlinetask-get-task-level)) (next-lvl (org-get-valid-level lvl -1)) @@ -233,15 +233,18 @@ going below `org-inlinetask-min-level'." (down-task (concat (make-string next-lvl ?*))) beg) (if (< next-lvl org-inlinetask-min-level) - (error "Cannot promote an inline task at minimum level") + (user-error "Cannot promote an inline task at minimum level") (org-inlinetask-goto-beginning) (setq beg (point)) (replace-match down-task nil t nil 1) (org-inlinetask-goto-end) - (if (eobp) (beginning-of-line) (forward-line -1)) + (if (and (eobp) (looking-back "END\\s-*")) + (beginning-of-line) + (forward-line -1)) (unless (= (point) beg) + (looking-at (org-inlinetask-outline-regexp)) (replace-match down-task nil t nil 1) - (when org-adapt-indentation + (when (eq org-adapt-indentation t) (goto-char beg) (org-fixup-indentation diff)))))))) @@ -250,7 +253,7 @@ going below `org-inlinetask-min-level'." If the task has an end part, also demote it." (interactive) (if (not (org-inlinetask-in-task-p)) - (error "Not in an inline task") + (user-error "Not in an inline task") (save-excursion (let* ((lvl (org-inlinetask-get-task-level)) (next-lvl (org-get-valid-level lvl 1)) @@ -261,10 +264,13 @@ If the task has an end part, also demote it." (setq beg (point)) (replace-match down-task nil t nil 1) (org-inlinetask-goto-end) - (if (eobp) (beginning-of-line) (forward-line -1)) + (if (and (eobp) (looking-back "END\\s-*")) + (beginning-of-line) + (forward-line -1)) (unless (= (point) beg) + (looking-at (org-inlinetask-outline-regexp)) (replace-match down-task nil t nil 1) - (when org-adapt-indentation + (when (eq org-adapt-indentation t) (goto-char beg) (org-fixup-indentation diff))))))) diff --git a/lisp/org.el b/lisp/org.el index 268ce74f7..b55189d37 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -17088,6 +17088,9 @@ for more information." (transpose-regions a b c d) (goto-char c))) ((org-at-table-p) (org-call-with-arg 'org-table-move-row 'up)) + ((and (featurep 'org-inlinetask) + (org-inlinetask-in-task-p)) + (user-error "Dragging inline tasks is not supported")) ((org-at-heading-p) (call-interactively 'org-move-subtree-up)) ((org-at-item-p) (call-interactively 'org-move-item-up)) (t (org-drag-element-backward)))) @@ -17118,6 +17121,9 @@ commands for more information." (transpose-regions a b c d) (goto-char d))) ((org-at-table-p) (call-interactively 'org-table-move-row)) + ((and (featurep 'org-inlinetask) + (org-inlinetask-in-task-p)) + (user-error "Dragging inline tasks is not supported")) ((org-at-heading-p) (call-interactively 'org-move-subtree-down)) ((org-at-item-p) (call-interactively 'org-move-item-down)) (t (org-drag-element-forward))))