Joshua Rasband's blog

Improved org-capture on MacOS

· [Joshua Rasband]

I read this post and it got me excited about using emacsclient to capture from anywhere on MacOS. I was particular about getting the capture frame to show only capture-related buffers, so I needed to make some modifications to the original code based on comments on this stackoverflow question.

Here’s my solution:

 1(defun my/make-org-capture-frame ()
 2  "Create a new frame and run `org-capture'."
 3  (interactive)
 4  (make-frame '((name . "capture")
 5                (top . 300)
 6                (left . 700)
 7                (width . 80)
 8                (height . 25)))
 9  (select-frame-by-name "capture")
10  (delete-other-windows)
11  (cl-letf (((symbol-function 'switch-to-buffer-other-window) #'switch-to-buffer) ((symbol-function 'org-display-buffer-split) #'org-display-buffer-full-frame)) (org-capture)))
12
13(defun my/org-capture-delete-frame (orig-fun &rest args)
14  (if (equal "capture" (frame-parameter nil 'name))
15      (delete-frame))
16  (apply orig-fun args))
17
18(advice-add 'user-error :around #'my/org-capture-delete-frame)
19(advice-add 'org-capture-finalize :around #'my/org-capture-delete-frame)

Now you can call emacsclient -nw --eval "(my/make-org-capture-frame)" and it will open a capture buffer in a new frame.

#emacs

Reply to this post by email ↪