Re: Feature request: kill-buffer for org-capture-finalize

2023-09-10 Thread Eduardo Suarez
On Sun, Sep 10, 2023 at 10:57:46AM +, Ihor Radchenko wrote:
> Then, what you can do is
> 
> (defun my-org-capture-finalize (arg)
> "Like `org-capture-finalize', but kill Org buffer with double prefix arg."
>   (interactive "P")
>   (if (equal arg '(16))
> (save-excursion
>   (org-capture-finalize)
>   (org-capture-goto-last-stored)
>   (kill-buffer))
>(org-capture-finalize arg)))
> (define-key org-capture-mode-map "\C-c\C-c" #'my-org-capture-finalize)

It worked! Thanks a lot for the help.



Re: Feature request: kill-buffer for org-capture-finalize

2023-09-10 Thread Ihor Radchenko
Eduardo Suarez  writes:

> On Sun, Sep 10, 2023 at 08:19:25AM +, Ihor Radchenko wrote:
>>   (defun my-org-capture-kill-buffer ()
>> (when (equal current-prefix-arg '(16))
>>   (save-excursion
>> (org-capture-goto-last-stored)
>> (kill-buffer
>
> Thanks for the proposed solution. I have tried it and it didn't work for me. 
> Or
> it worked somehow. If it kills the buffer, then the buffer is opened again
> right after it is killed, jumping to the last stored position. I think this is
> because of the way the 'org-capture-finalize' function is implemented:

> ...

Right.

Then, what you can do is

(defun my-org-capture-finalize (arg)
"Like `org-capture-finalize', but kill Org buffer with double prefix arg."
  (interactive "P")
  (if (equal arg '(16))
(save-excursion
  (org-capture-finalize)
  (org-capture-goto-last-stored)
  (kill-buffer))
   (org-capture-finalize arg)))
(define-key org-capture-mode-map "\C-c\C-c" #'my-org-capture-finalize)

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



Re: Feature request: kill-buffer for org-capture-finalize

2023-09-10 Thread Eduardo Suarez
On Sun, Sep 10, 2023 at 08:19:25AM +, Ihor Radchenko wrote:
>   (defun my-org-capture-kill-buffer ()
> (when (equal current-prefix-arg '(16))
>   (save-excursion
> (org-capture-goto-last-stored)
> (kill-buffer

Thanks for the proposed solution. I have tried it and it didn't work for me. Or
it worked somehow. If it kills the buffer, then the buffer is opened again
right after it is killed, jumping to the last stored position. I think this is
because of the way the 'org-capture-finalize' function is implemented:

...
(cond
 (abort-note
  (cl-case abort-note
(clean
 (message "Capture process aborted and target buffer cleaned up"))
(dirty
 (error "Capture process aborted, but target buffer could not be \
ned up correctly"
 (stay-with-capture  ;;<- this cond is executed
  (org-capture-goto-last-stored)))
...

It seems that the 'org-capture-goto-last-stored' function is called after the
hooks so the buffer is opened again.

This is just my interpretation. I'm not an expert in elisp.



Re: Feature request: kill-buffer for org-capture-finalize

2023-09-10 Thread Ihor Radchenko
Eduardo Suarez  writes:

> I have tried something simple like
>
>  (defun my-org-capture-kill-buffer ()
>(when (equal current-prefix-arg '(16))
>  (kill-buffer)))
>
> as an after-finalize hook. It seems to recognize the 'current-prefix-arg'
> variable.
>
> However,
>
> 1. it looks to me that org-capture-finalize jumps to the captured item if 
> there
> are any number greater than zero of preffix arguments,
>
> 2. the code above tries to kill the buffer I was working before invoking the
> capture process.
>
> Any hint?

  (defun my-org-capture-kill-buffer ()
(when (equal current-prefix-arg '(16))
  (save-excursion
(org-capture-goto-last-stored)
(kill-buffer

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



Re: Feature request: kill-buffer for org-capture-finalize

2023-09-09 Thread Eduardo Suarez
On Sat, Sep 09, 2023 at 09:18:27AM +, Ihor Radchenko wrote:
> For personal use-case, you can utilize
> `org-capture-after-finalize-hook', checking `current-prefix-arg' and
> killing the target org buffer according to the prefix argument passed.
> Then, for example, you can make C-u C-u C-c C-c unconditionally kill the
> target org buffer.

I have tried something simple like

 (defun my-org-capture-kill-buffer ()
   (when (equal current-prefix-arg '(16))
 (kill-buffer)))

as an after-finalize hook. It seems to recognize the 'current-prefix-arg'
variable.

However,

1. it looks to me that org-capture-finalize jumps to the captured item if there
are any number greater than zero of preffix arguments,

2. the code above tries to kill the buffer I was working before invoking the
capture process.

Any hint?



Re: Feature request: kill-buffer for org-capture-finalize

2023-09-09 Thread Ihor Radchenko
Eduardo Suarez-Santana  writes:

>> Or do you mean that you sometimes want to kill the target org buffer and
>> sometimes not?
>
> Yes, I mean that I sometimes want to kill the target org buffer and sometimes
> not. I don't want to kill the target buffer as the default behavior of my
> capture template.

I see what you want.
I am not sure if it is something commonly needed.

Unless more people are interested, I do not find this feature as useful
for inclusion to Org mode.

For personal use-case, you can utilize
`org-capture-after-finalize-hook', checking `current-prefix-arg' and
killing the target org buffer according to the prefix argument passed.
Then, for example, you can make C-u C-u C-c C-c unconditionally kill the
target org buffer.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



Re: Feature request: kill-buffer for org-capture-finalize

2023-09-08 Thread Eduardo Suarez-Santana
On Fri, Sep 08, 2023 at 12:38:07PM +, Ihor Radchenko wrote:
> Did you consider :kill-buffer property in `org-capture-templates'?
> 
>  :kill-bufferIf the target file was not yet visited by a buffer when
>  capture was invoked, kill the buffer again after capture
>  is finalized.
> 
> Or do you mean that you sometimes want to kill the target org buffer and
> sometimes not?

Yes, I mean that I sometimes want to kill the target org buffer and sometimes
not. I don't want to kill the target buffer as the default behavior of my
capture template.



Re: Feature request: kill-buffer for org-capture-finalize

2023-09-08 Thread Ihor Radchenko
Eduardo Suarez-Santana  writes:

>> May you explain a bit more about the problem you are trying to solve?
>> Isn't the temporary capture buffer killed after capture already?
>> Or do you refer to the org buffer where the capture is recorded?
>
> Sorry about that. I refer to the org buffer where the capture is recorded. I
> meant:
>
> "This would be useful to avoid having to kill the target buffer manually."
>
> I like to keep the target buffer open after the capture is finalized so I can
> review the changes later, but sometimes I'd rather prefer to kill it because I
> already assume that the changes are correct. This helps to keep the buffer 
> list
> clean.

Did you consider :kill-buffer property in `org-capture-templates'?

 :kill-bufferIf the target file was not yet visited by a buffer when
 capture was invoked, kill the buffer again after capture
 is finalized.

Or do you mean that you sometimes want to kill the target org buffer and
sometimes not?

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



Re: Feature request: kill-buffer for org-capture-finalize

2023-09-08 Thread Eduardo Suarez-Santana
On Fri, Sep 08, 2023 at 12:10:23PM +, Ihor Radchenko wrote:
> Eduardo Suarez  writes:
> 
> > The function org-capture-finalize allows an argument to 'jump-to-capture'. I
> > think it may be a good idea to add a new argument to 'kill-buffer' after the
> > capture is finalized. This would be useful to avoid having to kill the 
> > capture
> > buffer manually. I assume that if ':kill-buffer' is intended as the default
> > behavior, then it would be better to set it in the capture template.
> 
> May you explain a bit more about the problem you are trying to solve?
> Isn't the temporary capture buffer killed after capture already?
> Or do you refer to the org buffer where the capture is recorded?

Sorry about that. I refer to the org buffer where the capture is recorded. I
meant:

"This would be useful to avoid having to kill the target buffer manually."

I like to keep the target buffer open after the capture is finalized so I can
review the changes later, but sometimes I'd rather prefer to kill it because I
already assume that the changes are correct. This helps to keep the buffer list
clean.



Re: Feature request: kill-buffer for org-capture-finalize

2023-09-08 Thread Ihor Radchenko
Eduardo Suarez  writes:

> The function org-capture-finalize allows an argument to 'jump-to-capture'. I
> think it may be a good idea to add a new argument to 'kill-buffer' after the
> capture is finalized. This would be useful to avoid having to kill the capture
> buffer manually. I assume that if ':kill-buffer' is intended as the default
> behavior, then it would be better to set it in the capture template.

May you explain a bit more about the problem you are trying to solve?
Isn't the temporary capture buffer killed after capture already?
Or do you refer to the org buffer where the capture is recorded?

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



Feature request: kill-buffer for org-capture-finalize

2023-09-08 Thread Eduardo Suarez
This is a feature request.

The function org-capture-finalize allows an argument to 'jump-to-capture'. I
think it may be a good idea to add a new argument to 'kill-buffer' after the
capture is finalized. This would be useful to avoid having to kill the capture
buffer manually. I assume that if ':kill-buffer' is intended as the default
behavior, then it would be better to set it in the capture template.

I mean something like 'C-u C-u C-c C-c'.

I can't think now of a better way to do it. Any idea is welcome.

Thanks for your work.