From mboxrd@z Thu Jan 1 00:00:00 1970 From: Max Mikhanosha Subject: Re: Moving an item to a precise place Date: Tue, 02 Oct 2007 08:33:51 -0400 Message-ID: <87odfhelw0.wl%max@openchat.com> References: <200709160100.l8G10AqN005822@localhost.localdomain> Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Icgwm-00013K-BG for emacs-orgmode@gnu.org; Tue, 02 Oct 2007 08:33:56 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Icgwk-00012L-FK for emacs-orgmode@gnu.org; Tue, 02 Oct 2007 08:33:55 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Icgwj-00012E-Pf for emacs-orgmode@gnu.org; Tue, 02 Oct 2007 08:33:53 -0400 Received: from p84-72.acedsl.com ([66.114.84.72] helo=momoland.openchat.com) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Icgwj-0003RM-Cr for emacs-orgmode@gnu.org; Tue, 02 Oct 2007 08:33:53 -0400 Received: from momoland.openchat.com (localhost [127.0.0.1]) by momoland.openchat.com (Postfix) with ESMTP id AAC6DF40FFF1 for ; Tue, 2 Oct 2007 08:33:51 -0400 (EDT) In-Reply-To: <200709160100.l8G10AqN005822@localhost.localdomain> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org 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)))))