Browse Source

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 <chrhemmi@gmail.com>
Link: https://orgmode.org/list/CAE47VC=yhObXs3jexLUkf53cNzcOWUkTMqpF8QK4Dcg98QijyQ@mail.gmail.com/
Bastien 4 years ago
parent
commit
8b18405857
2 changed files with 20 additions and 8 deletions
  1. 14 8
      lisp/org-inlinetask.el
  2. 6 0
      lisp/org.el

+ 14 - 8
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)))))))
 

+ 6 - 0
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))))