unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* New URL Scheme
@ 2022-10-15 19:26 Perry Smith
  2022-10-15 23:46 ` Daniel Martín
  0 siblings, 1 reply; 2+ messages in thread
From: Perry Smith @ 2022-10-15 19:26 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 2132 bytes --]

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?

Long Version:

When a Ruby on Rails app throws an exception in development mode, it creates an error page in the browser.  On the page is the exception stack which is a list of files with line numbers for the stack traceback.  There are add ons that will reformat that list.  In the past, for example, the add on would put ‘txtmt’ (as I recall) scheme in front and TextMate was rigged up to accept that when macOS sent it.  If it isn’t obvious yet, I am on macOS and build emacs using the —with-ns configure option.

I’ve edited nextstep/templates/Info.plist.in so it now has:
```xml
	<key>CFBundleURLTypes</key>
	<array>
		<dict>
			<key>CFBundleURLName</key>
			<string>Email Address URL</string>
			<key>CFBundleURLSchemes</key>
			<array>
				<string>mailto</string>
			</array>
		</dict>
		<dict>
			<key>CFBundleTypeRole</key>
			<string>Editor</string>
			<key>CFBundleURLName</key>
			<string>Emacs Local Address URL</string>
			<key>CFBundleURLSchemes</key>
			<array>
				<string>emacs</string>
			</array>
		</dict>
	</array>
```
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?

Thank you for your time,
Perry
p.s. I am subscribed to this list do not receive emails so please CC me.  I will also track down any replies in the archive.


[-- Attachment #2: Message signed with OpenPGP --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: New URL Scheme
  2022-10-15 19:26 New URL Scheme Perry Smith
@ 2022-10-15 23:46 ` Daniel Martín
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel Martín @ 2022-10-15 23:46 UTC (permalink / raw)
  To: Perry Smith; +Cc: emacs-devel

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



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

end of thread, other threads:[~2022-10-15 23:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-15 19:26 New URL Scheme Perry Smith
2022-10-15 23:46 ` Daniel Martín

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.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).