emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* org-capture at point
@ 2020-09-29 12:11 david wen riccardi-zhu
  2020-10-03  6:45 ` Kyle Meyer
  0 siblings, 1 reply; 5+ messages in thread
From: david wen riccardi-zhu @ 2020-09-29 12:11 UTC (permalink / raw)
  To: emacs-orgmode

I use org-plus-contrib 2020928 with Emacs 27.1.

Since org-plus-contrib 20200920, I'm no longer able to get 
org-capture to insert a template at the point. Instead, it seems 
to place the entry at the appropriate heading level, above the 
current heading. Looking at the help page, perhaps it's this 
behavior:

"With a ‘C-u C-u’ prefix argument, go to the last note stored."

This happens with both a custom interactive function that calls 
(org-capture 0), and by using a zero prefix.

I'm not able to get this functionality to work:
"When called with a ‘C-0’ (zero) prefix, insert a template at 
point."

I'm not sure this is a bug -- I've had to make a handful of 
changes to my config since the 9.4 release. Any insights either 
way?

Thank you,

David

--
dwrz|朱为文


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

* Re: org-capture at point
       [not found] <mailman.57.1601395229.29559.emacs-orgmode@gnu.org>
@ 2020-09-30  5:24 ` No Wayman
  2020-10-02 18:46   ` No Wayman
  0 siblings, 1 reply; 5+ messages in thread
From: No Wayman @ 2020-09-30  5:24 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: emacs-orgmode-request


> Since org-plus-contrib 20200920, I'm no longer able to get
> org-capture to insert a template at the point. Instead, it seems
> to place the entry at the appropriate heading level, above the
> current heading. Looking at the help page, perhaps it's this
> behavior:
>
> This happens with both a custom interactive function that calls
> (org-capture 0), and by using a zero prefix.
>
> I'm not able to get this functionality to work:
> "When called with a ‘C-0’ (zero) prefix, insert a template at
> point."

I can confirm this behavior.
Looks like it was introduced with:

f5573e6a0 org-capture.el: Fix heading's level when inserting a 
template "here"

I tested by running the following:

#+begin_src emacs-lisp :lexical t
(dotimes (n 3)
  (let ((org-capture-templates
         `(( "e" "test"
             entry
             (file "/temp/null.org")
             ,(format "* %d" n)
             :immediate-finish t
             :no-save t))))
    (goto-char (point-max))
    (org-capture 0 "e")))
#+end_src


with Org built from f5573e6a0 output is:

* 1
* 2
* 0

prior to f5573e6a0 (tested on b79fef1da) output is:

* 0
* 1
* 2


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

* Re: org-capture at point
  2020-09-30  5:24 ` No Wayman
@ 2020-10-02 18:46   ` No Wayman
  2020-10-03  6:36     ` Kyle Meyer
  0 siblings, 1 reply; 5+ messages in thread
From: No Wayman @ 2020-10-02 18:46 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: emacs-orgmode-request

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


> Looks like it was introduced with:
>
> f5573e6a0 org-capture.el: Fix heading's level when inserting a
> template "here"

I believe the issue is due to `org-back-to-heading' moving point 
when calculating the heading level.
The attached patch corrects the issue on my end.
Tested by running:

#+begin_src emacs-lisp :lexical t
(dotimes (n 3)
  (let ((org-capture-templates
         `(( "e" "test"
             entry
             (file "/temp/null.org")
             ,(format "* %d" n)
             :immediate-finish t
             :no-save t))))
    (goto-char (point-max))
    (org-capture 0 "e")))
#+end_src

With a buffer containing:

* foo
** one
*** two
**** three
*** four

Which results in:

* foo
** one
*** two
**** three
*** four
*** 0
*** 1
*** 2


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: capture-here-position --]
[-- Type: text/x-patch, Size: 1281 bytes --]

From 5a35577f22cdc849ebcede6bac7b7f22da7eb16b Mon Sep 17 00:00:00 2001
From: Nicholas Vollmer <iarchivedmywholelife@gmail.com>
Date: Fri, 2 Oct 2020 14:01:35 -0400
Subject: [PATCH] org-capture.el: Fix heading's position when inserting a
 template "here"

* lisp/org-capture.el (org-capture-place-entry): Fix heading's
position when inserting a template "here" with C-0 M-x org-capture.
---
 lisp/org-capture.el | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/lisp/org-capture.el b/lisp/org-capture.el
index 67c58ffdd..020feb4d6 100644
--- a/lisp/org-capture.el
+++ b/lisp/org-capture.el
@@ -1150,10 +1150,11 @@ may have been stored before."
      (insert-here?
       ;; FIXME: level should probably set directly within (let ...).
       (setq level (org-get-valid-level
-		   (if (or (org-at-heading-p)
-			   (ignore-errors (org-back-to-heading t)))
-		       (org-outline-level)
-		     1))))
+                   (if (or (org-at-heading-p)
+                           (ignore-errors
+			     (save-excursion (org-back-to-heading t))))
+                       (org-outline-level)
+                     1))))
      ;; Insert as a child of the current entry.
      ((org-capture-get :target-entry-p)
       (setq level (org-get-valid-level
-- 
2.28.0


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

* Re: org-capture at point
  2020-10-02 18:46   ` No Wayman
@ 2020-10-03  6:36     ` Kyle Meyer
  0 siblings, 0 replies; 5+ messages in thread
From: Kyle Meyer @ 2020-10-03  6:36 UTC (permalink / raw)
  To: No Wayman; +Cc: emacs-orgmode

No Wayman writes:

>> Looks like it was introduced with:
>>
>> f5573e6a0 org-capture.el: Fix heading's level when inserting a
>> template "here"
>
> I believe the issue is due to `org-back-to-heading' moving point 
> when calculating the heading level.
> The attached patch corrects the issue on my end.

Thank you!

> Subject: [PATCH] org-capture.el: Fix heading's position when inserting a
>  template "here"
>
> * lisp/org-capture.el (org-capture-place-entry): Fix heading's
> position when inserting a template "here" with C-0 M-x org-capture.
> ---
>  lisp/org-capture.el | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/lisp/org-capture.el b/lisp/org-capture.el
> index 67c58ffdd..020feb4d6 100644
> --- a/lisp/org-capture.el
> +++ b/lisp/org-capture.el
> @@ -1150,10 +1150,11 @@ may have been stored before."
>       (insert-here?
>        ;; FIXME: level should probably set directly within (let ...).
>        (setq level (org-get-valid-level
> -		   (if (or (org-at-heading-p)
> -			   (ignore-errors (org-back-to-heading t)))
> -		       (org-outline-level)
> -		     1))))
> +                   (if (or (org-at-heading-p)
> +                           (ignore-errors
> +			     (save-excursion (org-back-to-heading t))))
> +                       (org-outline-level)
> +                     1))))

This looks correct to me, and AFAICT this doesn't break the scenario
that prompted the code you're adjusting from f5573e6a0:
https://orgmode.org/list/87lfiuxqze.fsf@alphaville.usersys.redhat.com/

Applied (8d3610df0), extending the commit message with a Reported-by
trailer and link for https://orgmode.org/list/877dscaila.fsf@dwrz.net/


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

* Re: org-capture at point
  2020-09-29 12:11 org-capture at point david wen riccardi-zhu
@ 2020-10-03  6:45 ` Kyle Meyer
  0 siblings, 0 replies; 5+ messages in thread
From: Kyle Meyer @ 2020-10-03  6:45 UTC (permalink / raw)
  To: david wen riccardi-zhu; +Cc: emacs-orgmode

david wen riccardi-zhu writes:

> I use org-plus-contrib 2020928 with Emacs 27.1.
>
> Since org-plus-contrib 20200920, I'm no longer able to get 
> org-capture to insert a template at the point. Instead, it seems 
> to place the entry at the appropriate heading level, above the 
> current heading. Looking at the help page, perhaps it's this 
> behavior:
[...]
> I'm not sure this is a bug -- I've had to make a handful of 
> changes to my config since the 9.4 release. Any insights either 
> way?

For future reference: No Wayman sent a patch to fix this in a separate
thread: <https://orgmode.org/list/87ft6wwjnr.fsf@gmail.com>.


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

end of thread, other threads:[~2020-10-03  6:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-09-29 12:11 org-capture at point david wen riccardi-zhu
2020-10-03  6:45 ` Kyle Meyer
     [not found] <mailman.57.1601395229.29559.emacs-orgmode@gnu.org>
2020-09-30  5:24 ` No Wayman
2020-10-02 18:46   ` No Wayman
2020-10-03  6:36     ` Kyle Meyer

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