emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: New URL Scheme


From: Daniel Martín
Subject: Re: New URL Scheme
Date: Sun, 16 Oct 2022 01:46:07 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (darwin)

Perry Smith <pedz@easesoftware.com> writes:

> TL; DR
>
> When I do “open file:/some/path/to/file.txt” on macOS, if file.txt has
> been set up right, it opens in Emacs.  How does that happen?  What is
> the earliest point I can hook into if I want to create a new scheme?

It opens Emacs if Emacs is the default application to open .txt files.
You can specify the program you want to use to open a particular file by
passing -e to the open command.  The man page explains this in detail.

To change the default program that opens a particular file type, take a
look at
https://support.apple.com/guide/mac-help/choose-an-app-to-open-a-file-on-mac-mh35597/mac

> I’m thinking that I can teach the add on to prepend “emacs:” as the scheme.  
> I think this will be better than using “file:” as the scheme since that may 
> or may not be sent to Emacs — depending upon how Info is set up for the 
> particular file.
>
> Currently, I can now say “open emacs:/some/path/to/file.txt” and Emacs
> is brought to the front so it is being triggered but the file isn’t
> loaded.  I’m assuming some piece of code is looking at the “emacs”
> scheme and going “Nope!  Not me!” and doing nothing.   Lot of
> assumptions where but my question is, where is the piece of code that
> is being given the URL and deciding to do nothing?

The reason it opens Emacs but does nothing is that the application (in
this case, Emacs) needs to handle the new URL scheme by implementing
some code that parses the URL and visits the file.  Concretely, macOS
will call this method on the application delegate when a registered URL
scheme is invoked:
https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1623112-application

I recommend reading this article to understand how URL schemes are
handled on macOS and how you could create one for Emacs:
https://developer.apple.com/documentation/xcode/defining-a-custom-url-scheme-for-your-app


reply via email to

[Prev in Thread] Current Thread [Next in Thread]