Support for Look Up "<word>" popup menu
A clear and concise description of what is hard to do In Apple's builtin applications and in the non-MacVim third party applications I use, force-clicking on a word shows a popup menu with information about the word (a dictionary definition and so on). One can also view this popup menu by right-clicking on the word and selecting Look Up "word". See the image below. I use this when writing to quickly look up words in the dictionary without having to open another window or application.
Describe the solution you'd like
Implement a way to bind the opening of this popup window to a key (or keys) or mouse action. This way we can customise how to open this menu and we can add this to the MacVim gui popup via the builtin :menu command. It would likely be a good idea to set the default settings to emulate MacOS behaviour.
Describe alternatives you've considered
I have looked into opening this window with apple script, but I could not find a way. One alternative is to write a function that takes the word under the cursor and executes :!open dict://word. This will show the word in the builtin Dictionary.app. This opens up another application, however, and shows a lot more information than just a simple definition. The Look Up window allows you to open the word in Dictionary.app anyway.
Thanks for filing this. It's been on my to-do after we refactored to the new renderer. There are really a couple things we should do on this:
- Support native lookup (Force Touch, three-finger tap, or Cmd-Ctrl-D). This requires hooking up to Apple's text input client API so macOS knows what the text under the cursors are, but the API is not terribly well documented so I kind of punted on that work. After we do that you will be able to just use the regular Cmd-Ctrl-D to look up the text under the cursor.
- Also, currently force touch is hijacked by MacVim to allow for mapping it using
<ForceClick>. Probably need to do something there to allow the user to choose what to do. - I believe this will also allows us to hook up the macOS built-in spellchecker for Touch Bar.
- Also, currently force touch is hijacked by MacVim to allow for mapping it using
- Support lookup as a Vim function, so you can do
:call mvim_lookup("http://www.google.com")or something like that (macOS's lookups support web URLs as well as dictionary). This is easier to do but I want to figure out how to do (1) first.
I also prefer to have a switch in vimrc to turn this off
Thanks for filing this. It's been on my to-do after we refactored to the new renderer. There are really a couple things we should do on this:
Support native lookup (Force Touch, three-finger tap, or Cmd-Ctrl-D). This requires hooking up to Apple's text input client API so macOS knows what the text under the cursors are, but the API is not terribly well documented so I kind of punted on that work. After we do that you will be able to just use the regular Cmd-Ctrl-D to look up the text under the cursor.
- Also, currently force touch is hijacked by MacVim to allow for mapping it using
<ForceClick>. Probably need to do something there to allow the user to choose what to do.- I believe this will also allows us to hook up the macOS built-in spellchecker for Touch Bar.
Support lookup as a Vim function, so you can do
:call mvim_lookup("http://www.google.com")or something like that (macOS's lookups support web URLs as well as dictionary). This is easier to do but I want to figure out how to do (1) first.
Yes agreed a native implementation would be ideal, though if it proves to be too much work then (2) would suffice as well. I am glad to see that it is on the todo list.
@eirnym can you explain why you would like a switch to turn this off? Lookup requires active user action to activate. It's not a passive feature, and most editors / GUI applications support it and there are system-wide settings that allow you to configure how to activate it in the OS.
This is the least used by me macOS feature. Problem there's no good dictionaries for Polish and many other languages and no way to install your own from open source dictionaries
Right but that’s not what I’m asking about. My point is if you don’t actively use this feature you can just not use it. No reason to include a preference to turn it off. It’s not like the program will randomly pop up the dictionary for you.
Also, lookup supports other things like Wikipedia and URL previews. It’s not just for dictionary.
With macOS apps I can turn this feature off in preferences (and I do). Why this feature must be turned on in MacVim while it's turned off in macOS?
#1312 will add support for this! This turned out to be a much larger task than I imagined because the degree to which you want to support this really depends on how much time you want to spend on it (e.g. supporting lookups for selected texts, data detection for URLs), and I feel like there are a lot of more ways to extend this such as custom API support. I made an epic #1311 to track the work for this so it's easier to see them in one place as they are related to each other. Annoyingly Apple uses private APIs for their implementation for native text views and WebKit/Safari, which is why third-party apps' implementation can never work as well as the native ones (e.g. Firefox or Chrome). For example, if you have a flight number (e.g. "AS 123") or package number Safari or TextEdit can natively understand how to show them, but other apps won't (unless they specifically implemented something for that). Just one of those builtin limitations.
After the initial PR though you should already be able to use Ctrl-Cmd-D or trackpad to show definition under work.
With macOS apps I can turn this feature off in preferences (and I do). Why this feature must be turned on in MacVim while it's turned off in macOS?
There isn't a way to turn this feature off completely. You can tell the OS to not do this with the trackpad which MacVim will respect of course, but you cannot disable Ctrl-Cmd-D as far as I can tell. I don't really think it will be a big deal in practice. You have to intentionally trigger this for it to show up.