all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* FR: refile-and-link
@ 2014-12-03 12:46 Adam Spiers
  2014-12-03 20:27 ` Thierry Pellé
  2014-12-05  0:21 ` Kyle Meyer
  0 siblings, 2 replies; 4+ messages in thread
From: Adam Spiers @ 2014-12-03 12:46 UTC (permalink / raw)
  To: org-mode mailing list

Hi all!

Forgive me if this has already been implemented, but I couldn't see it...

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?

Thanks!
Adam

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: FR: refile-and-link
  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
  1 sibling, 0 replies; 4+ messages in thread
From: Thierry Pellé @ 2014-12-03 20:27 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 818 bytes --]

+1

Since the destination is known after the refiling it may not be difficult.
I say this but I'am not an elisp literate ;-)

Thierry

Le 03/12/2014 13:46, Adam Spiers a écrit :
> Hi all!
>
> Forgive me if this has already been implemented, but I couldn't see it...
>
> 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?
>
> Thanks!
> Adam
>
>

-- 
Mon adresse mél changera à compter de début 2015
Celle-ci sera désormais (mutatis mutandis) *soliavos [AROBASE] 
thierry-pelle [POINT] eu*.

[-- Attachment #2: Type: text/html, Size: 1319 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: FR: refile-and-link
  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
  1 sibling, 1 reply; 4+ messages in thread
From: Kyle Meyer @ 2014-12-05  0:21 UTC (permalink / raw)
  To: Adam Spiers; +Cc: org-mode mailing list

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

--
Kyle

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: FR: refile-and-link
  2014-12-05  0:21 ` Kyle Meyer
@ 2014-12-10 23:54   ` Adam Spiers
  0 siblings, 0 replies; 4+ messages in thread
From: Adam Spiers @ 2014-12-10 23:54 UTC (permalink / raw)
  To: Kyle Meyer; +Cc: org-mode mailing list

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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-12-10 23:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.