From: Adam Spiers <orgmode@adamspiers.org>
To: Kyle Meyer <kyle@kyleam.com>
Cc: org-mode mailing list <emacs-orgmode@gnu.org>
Subject: Re: FR: refile-and-link
Date: Wed, 10 Dec 2014 23:54:47 +0000 [thread overview]
Message-ID: <20141210235447.GA4108@pacific.linksys.moosehall> (raw)
In-Reply-To: <871tofx7xx.fsf@kyleam.com>
On Thu, Dec 04, 2014 at 07:21:30PM -0500, Kyle Meyer wrote:
> Adam Spiers <orgmode@adamspiers.org> wrote:
> > Forgive me if this has already been implemented, but I couldn't see
> > it...
>
> I don't know of a command that does this.
>
> > I'm looking for something similar to the "extract method" operation
> > which refactoring IDEs can perform on code. You would select a
> > headline (or maybe even region), hit `refile-and-link', and then after
> > the normal refiling, a link to the refiled section would be inserted
> > in the place where the refiled section previously lived.
> >
> > Thoughts?
>
> The last refile location is stored in org-bookmark-names-plist. The
> (lightly tested) function below uses that information to create a link
> to the refiled heading.
>
> #+begin_src emacs-lisp
> (defun org-refile-and-link ()
> "Refile heading, adding a link to the new location.
> Prefix arguments are interpreted by `org-refile'."
> (interactive)
> (when (member current-prefix-arg '(3 (4) (16)))
> (user-error "Linking is incompatible with that prefix argument"))
> (let ((heading (org-get-heading t t))
> (orig-file (buffer-file-name)))
> (call-interactively #'org-refile)
> (let* ((refile-file
> (bookmark-get-filename
> (assoc (plist-get org-bookmark-names-plist :last-refile)
> bookmark-alist)))
> (same-file (string= orig-file refile-file))
> (link (if same-file
> (concat "*" heading)
> (concat refile-file "::*" heading)))
> (desc heading))
> (open-line 1)
> (insert (org-make-link-string link desc)))))
> #+end_src
Thanks a lot! I've noticed a couple of minor issues - hopefully I'll
fix them when I get time and then maybe submit a patch.
prev parent reply other threads:[~2014-12-10 23:55 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-12-03 12:46 FR: refile-and-link Adam Spiers
2014-12-03 20:27 ` Thierry Pellé
2014-12-05 0:21 ` Kyle Meyer
2014-12-10 23:54 ` Adam Spiers [this message]
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=20141210235447.GA4108@pacific.linksys.moosehall \
--to=orgmode@adamspiers.org \
--cc=emacs-orgmode@gnu.org \
--cc=kyle@kyleam.com \
/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).