emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Orgmode] Moving an item to a precise place


From: Max Mikhanosha
Subject: Re: [Orgmode] Moving an item to a precise place
Date: Tue, 02 Oct 2007 08:33:51 -0400
User-agent: Wanderlust/2.15.3 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.8 (Shijō) APEL/10.6 Emacs/22.0.51 (x86_64-unknown-linux-gnu) MULE/5.0 (SAKAKI)

Hi Xavier,

At Sun, 16 Sep 2007 03:00:10 +0200,
Xavier Maillard wrote:
> 
> So let's say I have this organization:
> 
> * Project 1
> ** TODO Ask foo about bar
> 
> * Project 2
> ** TODO Write customer report
> 
> * Project 3
> 
> How can I move the TODO from "Project 1" to "Project 3" directly
> -i.e. move by "name"

I'm catching up on reading my mailing lists, therefore you may have
already found a different way to do it, but just in case below is what
I wrote for myself for same functionality that you asked for.

Regards,
  Max

;;; Below code provides a function M-x org-quicky-refile which cuts a
;;; heading, then scans the file for the names of top level headings,
;;; and asks for the heading name to paste the item into (with
;;; standard Emacs completion)
;;;
;;; Simply bind org-quicky-refile to a key in org-mode-map.
;;;
;;; Bugs: leaves empty line sometimes, but this is a bug in
;;  org-paste-subtree IMHO.
;;;
;;; Possible improvements: only collect headings with specific tags
;;; as targets, so that one can tag 3rd/4th level headings as target

(defun org-quicky-get-heading (&optional no-props)
  (if (looking-at "^\\*+[ \t]+\\([^\r\n]*?\\)[ 
\t]*\\(:[a-zA-Z0-9:address@hidden)?[ \t]*[\r\n]")        
      (if no-props (org-match-string-no-properties 1) 
        (match-string 1)) ""))

(defun org-quicky-get-toplevel-headings ()
  "Return a list of top level headings"
  (let (headings) 
    (save-excursion
      (goto-char (point-min))
      (while (not (eobp))
        (when (and (looking-at outline-regexp)
                   (= (org-outline-level) 1))
          (push (cons (org-quicky-get-heading t) (point-marker)) headings))
        (forward-line)))
    (nreverse headings)))

(defmacro when* (expr &rest body)
  `(let ((it ,expr))
     (when it
       ,@body)))

(defvar org-quicky-refile-history nil)

(defun org-quicky-refile (&optional arg)
  (interactive)
  (let* ((headings (org-quicky-get-toplevel-headings))
         (completion-ignore-case t)
         pos)
    (when* (completing-read 
            "Project: " (mapcar #'car headings)
            nil t nil 'org-quicky-refile-history)
           (setq pos (cdr (assoc it headings)))
           (org-cut-special)
           (save-excursion 
             (goto-char pos)
             (setq pos (or (save-excursion 
                             (outline-get-next-sibling))
                           (point-max)))
             (goto-char pos)
             (org-paste-subtree 2)))))





reply via email to

[Prev in Thread] Current Thread [Next in Thread]