emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Max Mikhanosha <max@openchat.com>
To: emacs-orgmode@gnu.org
Subject: Re: Moving an item to a precise place
Date: Tue, 02 Oct 2007 08:33:51 -0400	[thread overview]
Message-ID: <87odfhelw0.wl%max@openchat.com> (raw)
In-Reply-To: <200709160100.l8G10AqN005822@localhost.localdomain>

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:_@]+\\)?[ \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)))))

  parent reply	other threads:[~2007-10-02 12:33 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-16  1:00 Moving an item to a precise place Xavier Maillard
2007-09-16 12:40 ` Bastien
2007-09-17 11:59   ` Carsten Dominik
2007-09-19 16:26     ` John Rakestraw
2007-09-20  8:45       ` Carsten Dominik
2007-09-27 10:51         ` emacs on the N800 Daniel M German
2007-09-27 18:50           ` Cezar
2007-09-27 20:34             ` Daniel M German
2007-09-29 19:58           ` Michael Olson
2007-12-11 23:47           ` Adam Spiers
2007-12-11 23:55             ` Adam Spiers
2007-12-12 16:33             ` Daniel M German
2007-12-12 17:06               ` Adam Spiers
2007-12-12 17:43                 ` Daniel M German
2007-12-13 16:27                   ` Adam Spiers
2007-12-22 18:22                     ` Adam Spiers
2007-12-22 18:40                       ` Bastien
2007-12-12 19:26               ` Leo
     [not found]             ` <87wsrkmazl.fsf@bzg.ath.cx>
     [not found]               ` <20071212112928.GA16499@atlantic.linksys.moosehall>
     [not found]                 ` <877ijjapbz.fsf@bzg.ath.cx>
     [not found]                   ` <m1ejdr4zue.fsf@se.dmg>
2007-12-12 17:25                     ` Adam Spiers
2007-12-12 17:34                     ` Tim O'Callaghan
2007-12-12 17:48                       ` Daniel M German
     [not found]                   ` <20071212160219.GC16499@atlantic.linksys.moosehall>
     [not found]                     ` <87zlwdrcav.fsf@bzg.ath.cx>
2007-12-14 10:09                       ` Adam Spiers
2007-12-14 10:23                         ` Daniel M German
2007-12-14 10:48                           ` Adam Spiers
2007-12-14 11:32                             ` Bastien
2007-12-14 10:40                         ` Adam Spiers
     [not found]               ` <m1odcv50mh.fsf@se.dmg>
2007-12-22 16:05                 ` Bastien
2007-12-22 17:58                   ` Adam Spiers
2007-10-02 12:33 ` Max Mikhanosha [this message]
2007-10-04 10:02   ` Moving an item to a precise place Carsten Dominik

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=87odfhelw0.wl%max@openchat.com \
    --to=max@openchat.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).