emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Patch org-capture-set-target-location
@ 2014-11-22 19:51 Roberto Huelga
  2014-11-23 18:15 ` Nicolas Goaziou
  0 siblings, 1 reply; 3+ messages in thread
From: Roberto Huelga @ 2014-11-22 19:51 UTC (permalink / raw)
  To: emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 732 bytes --]

Patch proposal for org-capture-set-target-location

The idea is that when somebody use the function or file+function targets
you can make the template subheading from the heading where the
custom-function set the point.
org-capture-set-target-loction force the org-capture-plist :exact-position
to (point).
So the template is inserted in the same level not as subheading

With my patch the custom-function can (org-capture-put :exact-position
nil), and now if point its placed in a heading the template is created as
his subheading.

For a use case can look at the following emacs.stackexchange question

http://emacs.stackexchange.com/questions/3750/org-capture-files-entry-under-wrong-datetree/3765#3765

Thanks.

Roberto Huelga.

[-- Attachment #1.2: Type: text/html, Size: 1484 bytes --]

[-- Attachment #2: 0001-org-capture.el-set-exact-position-only-if-not-set.patch --]
[-- Type: application/octet-stream, Size: 1493 bytes --]

From 7d3c262b14fccc728163d84aded3ec0fe8fa892f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Roberto=20Huelga=20D=C3=ADaz?= <rhuelga@gmail.com>
Date: Sat, 22 Nov 2014 20:29:56 +0100
Subject: [PATCH] org-capture.el: set :exact-position only if not set

* org-capture.el: (org-capture-set-target-location): on function and
  file+function don't set org-capture-plist :exact-position if already
  set. So now in the function you can set it to nil, and the template
  can be inserted as subheading of the places set by the function.

Patch proposal by Roberto Huelga Díaz

TINYCHANGE
---
 lisp/org-capture.el | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/lisp/org-capture.el b/lisp/org-capture.el
index 65de098..afbe607 100644
--- a/lisp/org-capture.el
+++ b/lisp/org-capture.el
@@ -935,12 +935,14 @@ Store them in the capture property list."
 	(org-capture-put-target-region-and-position)
 	(widen)
 	(funcall (nth 2 target))
-	(org-capture-put :exact-position (point))
+	(unless (memq :exact-position org-capture-plist)
+	  (org-capture-put :exact-position (point)))
 	(setq target-entry-p (and (derived-mode-p 'org-mode) (org-at-heading-p))))

        ((eq (car target) 'function)
 	(funcall (nth 1 target))
-	(org-capture-put :exact-position (point))
+	(unless (memq :exact-position org-capture-plist)
+	  (org-capture-put :exact-position (point)))
 	(setq target-entry-p (and (derived-mode-p 'org-mode) (org-at-heading-p))))

        ((eq (car target) 'clock)
--
2.1.2

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

* Re: Patch org-capture-set-target-location
  2014-11-22 19:51 Patch org-capture-set-target-location Roberto Huelga
@ 2014-11-23 18:15 ` Nicolas Goaziou
  2014-11-24 10:54   ` Roberto Huelga
  0 siblings, 1 reply; 3+ messages in thread
From: Nicolas Goaziou @ 2014-11-23 18:15 UTC (permalink / raw)
  To: Roberto Huelga; +Cc: emacs-orgmode

Hello,

Roberto Huelga <rhuelga@gmail.com> writes:

> Patch proposal for org-capture-set-target-location

Thanks for the patch.

> The idea is that when somebody use the function or file+function targets
> you can make the template subheading from the heading where the
> custom-function set the point.
> org-capture-set-target-loction force the org-capture-plist :exact-position
> to (point).
> So the template is inserted in the same level not as subheading
>
> With my patch the custom-function can (org-capture-put :exact-position
> nil), and now if point its placed in a heading the template is created as
> his subheading.

AFAIU, :exact-position is an internal property (it isn't documented in
(info "(org) Template elements"). You are not expected to set it
directly.

After a cursory look into "org-capture.el", if (point) is on a headline,
the template should create a subheading (see `org-capture-place-entry').
Can't you use that instead?


Regards,

-- 
Nicolas Goaziou

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

* Re: Patch org-capture-set-target-location
  2014-11-23 18:15 ` Nicolas Goaziou
@ 2014-11-24 10:54   ` Roberto Huelga
  0 siblings, 0 replies; 3+ messages in thread
From: Roberto Huelga @ 2014-11-24 10:54 UTC (permalink / raw)
  To: Roberto Huelga, emacs-orgmode

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

Sorry for make you lose your time.

Using the package version of 20141124 of org, the bug is present, but in
the git master, it's solved in a nicer way. By in the
org-capture-place-entry function getting out of the cond the test of
:exact-position

Package version:

    (cond
     ((org-capture-get :exact-position)
      (goto-char (org-capture-get :exact-position)))
     ((not target-entry-p)

Git Master version:

    (and (org-capture-get :exact-position)
     (goto-char (org-capture-get :exact-position)))
    (cond
     ((not target-entry-p)

Thank you very much.


On Sun, Nov 23, 2014 at 7:15 PM, Nicolas Goaziou <mail@nicolasgoaziou.fr>
wrote:

> Hello,
>
> Roberto Huelga <rhuelga@gmail.com> writes:
>
> > Patch proposal for org-capture-set-target-location
>
> Thanks for the patch.
>
> > The idea is that when somebody use the function or file+function targets
> > you can make the template subheading from the heading where the
> > custom-function set the point.
> > org-capture-set-target-loction force the org-capture-plist
> :exact-position
> > to (point).
> > So the template is inserted in the same level not as subheading
> >
> > With my patch the custom-function can (org-capture-put :exact-position
> > nil), and now if point its placed in a heading the template is created as
> > his subheading.
>
> AFAIU, :exact-position is an internal property (it isn't documented in
> (info "(org) Template elements"). You are not expected to set it
> directly.
>
> After a cursory look into "org-capture.el", if (point) is on a headline,
> the template should create a subheading (see `org-capture-place-entry').
> Can't you use that instead?
>
>
> Regards,
>
> --
> Nicolas Goaziou
>

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

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

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

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-22 19:51 Patch org-capture-set-target-location Roberto Huelga
2014-11-23 18:15 ` Nicolas Goaziou
2014-11-24 10:54   ` Roberto Huelga

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).