emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Nicolas Goaziou <n.goaziou@gmail.com>
To: Org mode list <emacs-orgmode@gnu.org>
Cc: Nicolas Goaziou <n.goaziou@gmail.com>
Subject: [PATCH 3/3] Promote and demote inline tasks
Date: Wed,  2 Mar 2011 17:56:04 +0100	[thread overview]
Message-ID: <1299084964-26440-3-git-send-email-n.goaziou@gmail.com> (raw)
In-Reply-To: <1299084964-26440-1-git-send-email-n.goaziou@gmail.com>

* lisp/org-inlinetask.el (org-inlinetask-promote,
  org-inlinetask-demote): new functions.

* lisp/org.el (org-metaleft, org-metaright): when point is at an
  inline task, promote or demote it.
---
 lisp/org-inlinetask.el |   49 ++++++++++++++++++++++++++++++++++++++++++++++++
 lisp/org.el            |   28 +++++++++++++++++---------
 2 files changed, 67 insertions(+), 10 deletions(-)

diff --git a/lisp/org-inlinetask.el b/lisp/org-inlinetask.el
index 6bf38df..42ba7a4 100644
--- a/lisp/org-inlinetask.el
+++ b/lisp/org-inlinetask.el
@@ -252,6 +252,55 @@ This assumes the point is inside an inline task."
     (re-search-backward (org-inlinetask-outline-regexp) nil t)
     (- (match-end 1) (match-beginning 1))))
 
+(defun org-inlinetask-promote ()
+  "Promote the inline task at point.
+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")
+    (save-excursion
+      (let* ((lvl (org-inlinetask-get-task-level))
+	     (next-lvl (org-get-valid-level lvl -1))
+	     (diff (- next-lvl lvl))
+	     (down-task (concat (make-string next-lvl ?*)))
+	     beg)
+	(if (< next-lvl org-inlinetask-min-level)
+	    (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))
+	  (unless (= (point) beg)
+	    (replace-match down-task nil t nil 1)
+	    (when org-adapt-indentation
+	      (goto-char beg)
+	      (org-fixup-indentation diff))))))))
+
+(defun org-inlinetask-demote ()
+  "Demote the inline task at point.
+If the task has an end part, also demote it."
+  (interactive)
+  (if (not (org-inlinetask-in-task-p))
+      (error "Not in an inline task")
+    (save-excursion
+      (let* ((lvl (org-inlinetask-get-task-level))
+	     (next-lvl (org-get-valid-level lvl 1))
+	     (diff (- next-lvl lvl))
+	     (down-task (concat (make-string next-lvl ?*)))
+	     beg)
+	(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))
+	(unless (= (point) beg)
+	  (replace-match down-task nil t nil 1)
+	  (when org-adapt-indentation
+	    (goto-char beg)
+	    (org-fixup-indentation diff)))))))
+
 (defvar org-export-current-backend) ; dynamically bound in org-exp.el
 (defun org-inlinetask-export-handler ()
   "Handle headlines with level larger or equal to `org-inlinetask-min-level'.
diff --git a/lisp/org.el b/lisp/org.el
index 8ae5e6f..c528707 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -17042,13 +17042,17 @@ See the individual commands for more information."
   (cond
    ((run-hook-with-args-until-success 'org-metaleft-hook))
    ((org-at-table-p) (org-call-with-arg 'org-table-move-column 'left))
-   ((or (org-on-heading-p)
-	(and (org-region-active-p)
-	     (save-excursion
-	       (goto-char (region-beginning))
-	       (org-on-heading-p))))
+   ((org-with-limited-levels
+     (or (org-on-heading-p)
+	 (and (org-region-active-p)
+	      (save-excursion
+		(goto-char (region-beginning))
+		(org-on-heading-p)))))
     (when (org-check-for-hidden 'headlines) (org-hidden-tree-error))
     (call-interactively 'org-do-promote))
+   ;; At an inline task.
+   ((org-on-heading-p)
+    (call-interactively 'org-inlinetask-promote))
    ((or (org-at-item-p)
 	(and (org-region-active-p)
 	     (save-excursion
@@ -17067,13 +17071,17 @@ See the individual commands for more information."
   (cond
    ((run-hook-with-args-until-success 'org-metaright-hook))
    ((org-at-table-p) (call-interactively 'org-table-move-column))
-   ((or (org-on-heading-p)
-	(and (org-region-active-p)
-	     (save-excursion
-	       (goto-char (region-beginning))
-	       (org-on-heading-p))))
+   ((org-with-limited-levels
+     (or (org-on-heading-p)
+	 (and (org-region-active-p)
+	      (save-excursion
+		(goto-char (region-beginning))
+		(org-on-heading-p)))))
     (when (org-check-for-hidden 'headlines) (org-hidden-tree-error))
     (call-interactively 'org-do-demote))
+   ;; At an inline task.
+   ((org-on-heading-p)
+    (call-interactively 'org-inlinetask-demote))
    ((or (org-at-item-p)
 	(and (org-region-active-p)
 	     (save-excursion
-- 
1.7.4.1

  parent reply	other threads:[~2011-03-02 16:56 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-02 16:56 [PATCH 1/3] Fix bug when narrowing to subtree with point at an inline task Nicolas Goaziou
2011-03-02 16:56 ` [PATCH 2/3] When demoting a subtree, don't change level of inline tasks within Nicolas Goaziou
2011-03-06  8:30   ` [Accepted] [O, " Bastien Guerry
2011-03-02 16:56 ` Nicolas Goaziou [this message]
2011-03-06  8:30   ` [Accepted] [O,3/3] Promote and demote inline tasks Bastien Guerry
2011-03-06  8:29 ` [Accepted] [O, 1/3] Fix bug when narrowing to subtree with point at an inline task Bastien Guerry

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1299084964-26440-3-git-send-email-n.goaziou@gmail.com \
    --to=n.goaziou@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).