emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Find-file using org-protocol
@ 2023-03-15  3:41 Kai Ma
  2023-03-15 14:09 ` Max Nikulin
  0 siblings, 1 reply; 2+ messages in thread
From: Kai Ma @ 2023-03-15  3:41 UTC (permalink / raw)
  To: emacs-orgmode

Hi org

I’m using org-protocol to open local files in an Emacs client.  Yes, this is weird, but it is required for some Electron apps, because they do not allow calling arbitrary commands.

This is how I do it:

(use-package org-protocol
  :config
  (add-to-list 'org-protocol-protocol-alist
               '("org-find-file" :protocol "find-file" :function org-protocol-find-file :kill-client nil))

  (defun org-protocol-find-file (fname)
    "Process org-protocol://find-file?path= style URL."
    (let ((f (plist-get (org-protocol-parse-parameters fname nil '(:path)) :path)))
      (find-file f)
      (raise-frame)
      (select-frame-set-input-focus (selected-frame)))))

It works, but there’s a minor annoyance: the buffer it opens is not associated with the client.  And killing the client won’t kill the buffer it creates.

Upon some inspection, I find that org-protocol-check-filename-for-protocol seems to discard information about the client, so I cannot set server-buffer-clients and server-existing-buffer accordingly myself.

I’m writing to ask if there is a better way than advising server-visit-files or org-protocol-check-filename-for-protocol?

Thanks!

Regards,
Kai

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

* Re: Find-file using org-protocol
  2023-03-15  3:41 Find-file using org-protocol Kai Ma
@ 2023-03-15 14:09 ` Max Nikulin
  0 siblings, 0 replies; 2+ messages in thread
From: Max Nikulin @ 2023-03-15 14:09 UTC (permalink / raw)
  To: Kai Ma, emacs-orgmode

On 15/03/2023 10:41, Kai Ma wrote:
> 
> I’m using org-protocol to open local files in an Emacs client.  Yes,
> this is weird, but it is required for some Electron apps, because they
> do not allow calling arbitrary commands.
...
> It works, but there’s a minor annoyance: the buffer it opens is not
> associated with the client.  And killing the client won’t kill the
> buffer it creates.

Do you really need org-protocol for this purpose? I would suggest direct 
call of your function using --eval similar to `message-mailto` in 
https://git.savannah.gnu.org/cgit/emacs.git/tree/etc/emacsclient-mail.desktop

I admit that it is tricky to safely pass an argument to emacsclient, see
https://debbugs.gnu.org/57752
#57752 28.1.91; emacsclient-mail.desktop doesn't work for me.

However instead of long Exec entry in the desktop file I would use a 
script with *single* %u argument. The reason is a Firefox bug that may 
cause lost of everything besides the command and the URI.


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

end of thread, other threads:[~2023-03-15 14:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-15  3:41 Find-file using org-protocol Kai Ma
2023-03-15 14:09 ` Max Nikulin

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