Evaluate expression does not work in MacVim

8 views
Skip to first unread message

Nico Weber

unread,
May 20, 2008, 9:14:17 AM5/20/08
to vim...@googlegroups.com
Hi all,

tell application "Finder" to launch

in nearly call cocoa text fields, you can enter an apple script
expression such as '80+2' or even 'tell application "Finder" to
activate", highlight it, and hit ⇧⌘8. The result of the applescript
expression will replace the highlighted text ('80+2' will become '82',
'tell application…' will activate the finder and then complain that
no result was returned that the text could be replaced with). Try it
in TextEdit, for example.

This does not work with MacVim. I guess there's not much that can be
done about that, but I thought I'd report it anyways, especially since
other cocoa text field tricks like ⌘⌃D (look up highlighted work in
dictionary) work with MacVim.

Nico

björn

unread,
May 20, 2008, 10:41:19 AM5/20/08
to vim...@googlegroups.com
2008/5/20 Nico Weber <nicola...@gmx.de>:

The fact that this doesn't work is probably because I've purposely
broken NSTextView's concept of the "selected text". I'm guessing ⇧⌘8
tries to access the selection and since this is always empty (as far
as Cocoa knows) nothing happens. It may be possible to override the
methods that query the selection (in MMTextView) and make it work that
way. I'll put it on my todo but feel free to check that out for
yourself.

Björn

björn

unread,
May 20, 2008, 10:54:03 AM5/20/08
to vim...@googlegroups.com
2008/5/20 björn <bjorn.w...@gmail.com>:

Sorry. I should think before posting. The problem is (as you've
probably already thought of) inserting the result of the evaluation
back into MacVim. I have already taken care of implementing the part
that queries the currently selected text. Still, implementing support
for this feature should definitely be doable. I'll think about it
some more.

Björn

björn

unread,
May 20, 2008, 12:49:09 PM5/20/08
to vim...@googlegroups.com
2008/5/20 Nico Weber <nicola...@gmx.de>:

I've attached a first stab at a patch below.

The reason why this didn't already work was because I hadn't
implemented the code that receives data from a system service. The
patch below takes care of this but it is flawed in that it assumes Vim
is in Visual mode when the input is added to Vim. I have to think
about how to implement this so that it takes the text from the
pasteboard and replaces the current selection with this text, or
inserts it if there is no selection (and it must work both in Visual
and in Select mode). We might have to add a new message to the
backend which does this (e.g. "ReplaceTextMsgId").

Björn


diff --git a/src/MacVim/MMWindowController.m b/src/MacVim/MMWindowController.m
index c3b055e..b5a28a7 100644
--- a/src/MacVim/MMWindowController.m
+++ b/src/MacVim/MMWindowController.m
@@ -734,6 +734,20 @@
return [self askBackendForStarRegister:pboard];
}

+- (BOOL)readSelectionFromPasteboard:(NSPasteboard *)pboard
+{
+ // Replace the current selection with the text on the pasteboard.
+ NSArray *types = [pboard types];
+ if ([types containsObject:NSStringPboardType]) {
+ NSString *input = [NSString stringWithFormat:@"s%@",
+ [pboard stringForType:NSStringPboardType]];
+ [vimController addVimInput:input];
+ return YES;
+ }
+
+ return NO;
+}
+
@end // MMWindowController

Reply all
Reply to author
Forward
0 new messages