emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* org-capture quitting and make-capture-frame
@ 2017-10-23 14:59 Tyler Smith
  2017-10-23 20:03 ` Nicolas Goaziou
  0 siblings, 1 reply; 4+ messages in thread
From: Tyler Smith @ 2017-10-23 14:59 UTC (permalink / raw)
  To: Emacs Org-Mode Help

Hi,

I use org-capture with a new frame, so I can call it quickly when from
the OS (see
http://www.windley.com/archives/2010/12/capture_mode_and_emacs.shtml).

This works well, except that if I quit a capture, the frame is left
hanging. I looked through the code, and this is due to org-capture
calling `(user-error "Abort")` in response to my entering 'q' to
indicate I want to cancel my capture. 

It would be nice to allow for some configuration here. In my case, I
have replaced this line:

    ((equal entry "q")
	    (user-error "Abort"))

(source:
http://orgmode.org/cgit.cgi/org-mode.git/tree/lisp/org-capture.el?h=emacs-sync#n632
)

with

    ((equal entry "q")
       (if (equal "capture" (frame-parameter nil 'name))  
           (delete-frame))

That will work for my use case, until org-mode is updated at least.
Would it be possible to do something like this instead:

    ((equal entry "q")
      (funcall org-capture-quite-function))

That would allow you to provide a sensible default, such as '(user-error
"Abort")', while allowing users to tweak this behaviour, as needed for
cleaning up capture frames.

I've pasted the additional functions I'm using below, FYI.

Best,

Tyler

(defun make-capture-frame ()  
  "Create a new frame and run org-capture."  
  (interactive)  
  (select-frame-set-input-focus
   (make-frame '((name . "capture") 
                 (width . 120) 
                 (height . 15))))  
  (setq word-wrap 1)
  (setq truncate-lines nil)
  (org-capture))

(defadvice org-switch-to-buffer-other-window 
  (after supress-window-splitting activate)  
  "Delete the extra window if we're in a capture frame"  
  (if (equal "capture" (frame-parameter nil 'name))  
      (delete-other-windows)))

(defadvice org-capture-destroy 
    (after delete-capture-frame activate)  
  "Advise capture-destroy to close the frame"  
  (if (equal "capture" (frame-parameter nil 'name))  
      (delete-frame)))

(defadvice org-capture-finalize 
    (after delete-capture-frame activate)  
  "Advise capture-finalize to close the frame"  
  (if (equal "capture" (frame-parameter nil 'name))  
      (delete-frame)))
 

-- 
plantarum.ca

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

* Re: org-capture quitting and make-capture-frame
  2017-10-23 14:59 org-capture quitting and make-capture-frame Tyler Smith
@ 2017-10-23 20:03 ` Nicolas Goaziou
  2017-10-23 20:41   ` Tyler Smith
  0 siblings, 1 reply; 4+ messages in thread
From: Nicolas Goaziou @ 2017-10-23 20:03 UTC (permalink / raw)
  To: Tyler Smith; +Cc: Emacs Org-Mode Help

Hello,

Tyler Smith <tyler@plantarum.ca> writes:

> Hi,
>
> I use org-capture with a new frame, so I can call it quickly when from
> the OS (see
> http://www.windley.com/archives/2010/12/capture_mode_and_emacs.shtml).
>
> This works well, except that if I quit a capture, the frame is left
> hanging. I looked through the code, and this is due to org-capture
> calling `(user-error "Abort")` in response to my entering 'q' to
> indicate I want to cancel my capture. 
>
> It would be nice to allow for some configuration here. In my case, I
> have replaced this line:
>
>     ((equal entry "q")
> 	    (user-error "Abort"))
>
> (source:
> http://orgmode.org/cgit.cgi/org-mode.git/tree/lisp/org-capture.el?h=emacs-sync#n632
> )
>
> with
>
>     ((equal entry "q")
>        (if (equal "capture" (frame-parameter nil 'name))  
>            (delete-frame))
>
> That will work for my use case, until org-mode is updated at least.
> Would it be possible to do something like this instead:
>
>     ((equal entry "q")
>       (funcall org-capture-quite-function))

Wouldn't it make more sense to turn it into 

 (message "Abort")

? After all, it is not an error. It also allow to call other functions,
e.g., `delete-frame' after exiting capture.

WDYT?

Regards,

-- 
Nicolas Goaziou

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

* Re: org-capture quitting and make-capture-frame
  2017-10-23 20:03 ` Nicolas Goaziou
@ 2017-10-23 20:41   ` Tyler Smith
  2017-10-23 21:11     ` Nicolas Goaziou
  0 siblings, 1 reply; 4+ messages in thread
From: Tyler Smith @ 2017-10-23 20:41 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: Emacs Org-Mode Help

On Mon, Oct 23, 2017, at 04:03 PM, Nicolas Goaziou wrote:
> 
> Wouldn't it make more sense to turn it into 
> 
>  (message "Abort")
> 
> ? After all, it is not an error. It also allow to call other functions,
> e.g., `delete-frame' after exiting capture.
> 
> WDYT?
> 

I did think it was odd that this called an error, as it isn't an error
at all. 

I'm not sure how calling `(message ...)` at that point would enable
calling `delete-frame` after exiting capture? At the moment I'm calling
`delete` frame it by advising org-capture-destroy and
org-capture-finalize. I don't think either are called when you quit out
of the template selection dialog. Quitting needs to do something that
you can respond to, either with a hook, an advised function or something
else?

My proposal was just the first thing that I thought of, I'm sure there
are better solutions. That could be (message ...), but I'm missing
something in that case.

Best,

Tyler

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

* Re: org-capture quitting and make-capture-frame
  2017-10-23 20:41   ` Tyler Smith
@ 2017-10-23 21:11     ` Nicolas Goaziou
  0 siblings, 0 replies; 4+ messages in thread
From: Nicolas Goaziou @ 2017-10-23 21:11 UTC (permalink / raw)
  To: Tyler Smith; +Cc: Emacs Org-Mode Help

Tyler Smith <tyler@plantarum.ca> writes:

> Quitting needs to do something that you can respond to, either with
> a hook, an advised function or something else?

I thought `org-capture-finalize' would be called anyway. But it isn't
the case.

> My proposal was just the first thing that I thought of, I'm sure there
> are better solutions. That could be (message ...), but I'm missing
> something in that case.

You could use

  (condition-case nil
      (progn
        (org-capture)
        (delete-other-windows))
    (error (delete-frame)))

Obviously, this relies on the fact that exiting raises an error.


Regards,

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

end of thread, other threads:[~2017-10-23 21:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-23 14:59 org-capture quitting and make-capture-frame Tyler Smith
2017-10-23 20:03 ` Nicolas Goaziou
2017-10-23 20:41   ` Tyler Smith
2017-10-23 21:11     ` Nicolas Goaziou

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