4

I have recently found a way to have a floating capture window, with this setting I can create a floating capture window using:

emacsclient -n -e '(make-capture-frame)'

My knowledge of elisp and org-mode internals being close to 0, I did not find a way to have the same behaviour via the org-protocol. What I would like is that when a call happen using the org-protocol, I have a nice floating capture window in front of me.

Note that I'm not attach to use this specific code to create a floating capture window, but that is my current starting point.

Here is the code I'm currently using:

;;;
;; Capture floating frame
;;
;; taken from: http://www.windley.com/archives/2010/12/capture_mode_and_emacs.shtml
;;;

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

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

;; make the frame contain a single window. by default org-capture
;; splits the window.
(add-hook 'org-capture-mode-hook
          'delete-other-windows)

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

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

I have devised a "hacky" solution.

I have rewrite the make-capture-frame to support an optional argument, and directly call org-protocol-capture with this argument if it exist.

(defun make-capture-frame (&optional capture-url)
  "Create a new frame and run org-capture."
  (interactive)
  (make-frame '((name . "capture")
                (width . 120)
                (height . 15)))
  (select-frame-by-name "capture")
  (setq word-wrap 1)
  (setq truncate-lines nil)
  (if capture-url (org-protocol-capture capture-url) (org-capture)))

Thus I can call emacs like that:

emacsclient -n -e '(make-capture-frame)'

or

emacsclient -n -e '(make-capture-frame-test "x/test/test")'

x/test/test being the org-protocol url without the org-protocol://capture:// part.

While this is working, it is not as generic as the org-protocol allow. Thus to support any new subprotocol I have to add a specific function.

  • Without any other proposition, I'll validate mine even if it's not a perfect one... – Mayeu May 21 '16 at 18:25
  • What is make-capture-frame-test? – kshenoy Dec 25 '16 at 3:13
  • Sorry I have no clue anymore... I am not using org-mode/emacs since almost 6 months, since my trial of this editors. Maybe a typo/misscopy? – Mayeu Jan 5 '17 at 16:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.