Service "Open Selected File"

13 views
Skip to first unread message

Jean-Christophe Helary

unread,
Apr 10, 2017, 3:58:50 AM4/10/17
to aquamac...@googlegroups.com
The service "Open Selected File" fails when the selected string is a multiline string or of it ends with a line break (like when triple-clicking on a line).

The service is called in ns-win.el at:
(defun ns-spi-service-call ()

If the service name is "open-file" then (dnd-open-file ns-input-spi-arg nil) is called on just one argument.

To make the service useable on a selection of paths, the idea would be to split-string the argument and loop the call over the list of arguments.

Basically something like this (prototype):

(let (
(filepaths "/path/to/file1
/path/to/file2
/path/to/file3
"))
(setq path_list (split-string filepaths "[\f\t\n\r\v]+"))
(while path_list
(if (equal "" (car path_list))
(message "empty path")
(dnd-open-file (car path_list) nil))
(setq path_list (cdr path_list))))

So, I'm not sure exactly how to fit that into ns-win.el because it is official gnu material but unless a new function is defined to handle that behavior it would look like this:

((string-equal ns-input-spi-name "open-file")
;; split-string ns-input-spi-arg (but remove split by spaces)
;; loop over the dnd-open-file call with each substring list member
(dnd-open-file ns-input-spi-arg nil))
;; end loop

The problem I could not solve was that I wanted to have multiple files opened in their own windows and this solution only opens 1 new window with the last file and the other files are in hidden buffers.
I tried to set dnd-open-file-other-window to true in dnd.el (line 78) but that did not work.

Is there anything else I can do to solve this?

Jean-Christophe

Jean-Christophe Helary

unread,
Apr 10, 2017, 9:48:06 PM4/10/17
to aquamac...@googlegroups.com
I've eventually cleaned up the thing a bit:

1) I added a function to trim the string (because removing the " " splitter was necessary to accommodate for paths that contained spaces, but that ended up leaving leading/trailing spaces)
2) I added a function that wrapped the current dnd-open-file into a loop to al it on each member of the path list
3) I replaced the call to dnd-open-file by a call to that wrapper.

Now I still have to get the whole thing to open multiple files in multiple windows, but that's secondary.

I've sent a pull request earlier but I *do* understand that it may not be "production grade" code (I'm pretty sure it's my first "serious" elisp code...) so feel free to tell me that it can't be accepted.

Jean-Christophe

David Reitter

unread,
Apr 11, 2017, 12:15:11 AM4/11/17
to aquamac...@googlegroups.com
JC,
I’ll need to get back to you about the patch, later in the week.

As for opening in multiple window - keep in mind that users configure whether they want to use tabs or multiple frames, or none of that. Any patch needs to respect these settings in the end. The easiest way is to go through high-level lisp functions to open new files.

- David

--
http://aquamacs.org -- Aquamacs: Emacs on Mac OS X
http://aquamacs.org/donate -- Could we help you? Return the favor and support the Aquamacs Project!
> --
> You received this message because you are subscribed to the Google Groups "aquamacs-devel" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to aquamacs-deve...@googlegroups.com.

Jean-Christophe Helary

unread,
Apr 11, 2017, 4:53:32 AM4/11/17
to aquamac...@googlegroups.com

> On Apr 11, 2017, at 13:15, David Reitter <david....@gmail.com> wrote:
>
> JC,
> I’ll need to get back to you about the patch, later in the week.

There's no hurry, and honestly, I won't mind if you just scrap it. There's probably a much better way to achieve the same result.

> As for opening in multiple window - keep in mind that users configure whether they want to use tabs or multiple frames, or none of that.

Sorry, I forget that this is emacs. Other editors don't have the separate concept of buffers and windows. You're totally right about that.

Jean-Christophe

Jean-Christophe Helary

unread,
Apr 11, 2017, 9:18:37 AM4/11/17
to aquamac...@googlegroups.com
Also, something else I could not solve: when the services appear in the Service menu, the Aquamacs icon is displayed so it is easy to see what applications they come from. But when they are displayed in the Service preferences (in System Preferences) or in a contextual menu, there is nothing to identify them as coming from Aquamacs.

I thought about changing that by adding an !Aquamacs: " prefix but I could not find where the service names came from even though they seem to come from the Info.plist file. Whatever I did to that file, the registered names were not changed...

Jean-Christophe

David Reitter

unread,
Apr 11, 2017, 10:51:53 AM4/11/17
to aquamac...@googlegroups.com
Sorry, I cannot find this Services Preferences panel.

Without seeing it, though, I wonder if you are trying to work around a design decision made at the OS level. That would probably not be a good thing, unless there is something special about Aquamacs service items that distinguishes them from other app’s service items.

Normally what seems to happen, if I select some text and look at the service items that are available, is that the labels more or less hint at the application, so instead of “Open file”, you’d say “Edit this file in Aquamacs”, or “Edit this text in Aquamacs”.

In any case, I can’t see any Aquamacs service items… wonder why.



--
http://aquamacs.org -- Aquamacs: Emacs on Mac OS X
http://aquamacs.org/donate -- Could we help you? Return the favor and support the Aquamacs Project!


Jean-Christophe Helary

unread,
Apr 11, 2017, 11:17:50 AM4/11/17
to aquamac...@googlegroups.com

> On Apr 11, 2017, at 23:51, David Reitter <david....@gmail.com> wrote:
>
> Sorry, I cannot find this Services Preferences panel.

Sorry, I meant System Preferences > Keyboard > Shortcuts > Services

> Normally what seems to happen, if I select some text and look at the service items that are available, is that the labels more or less hint at the application, so instead of “Open file”, you’d say “Edit this file in Aquamacs”, or “Edit this text in Aquamacs”.
>
> In any case, I can’t see any Aquamacs service items… wonder why.

They are here, 4 of them. If you select some text and open the Service menu from the application menu, you'll see the Aquamacs icon that identifies them. When you open Services from the contextual menu, no icon.

Jean-Christophe
Reply all
Reply to author
Forward
0 new messages