1 /* vi:set ts=8 sts=4 sw=4 ft=objc:
3 * VIM - Vi IMproved by Bram Moolenaar
4 * MacVim GUI port by Bjorn Winckler
6 * Do ":help uganda" in Vim to read copying and usage conditions.
7 * Do ":help credits" in Vim to see a list of people who contributed.
8 * See README.txt for an overview of the Vim source code.
11 #import <Cocoa/Cocoa.h>
16 // Enable support for MacVim plugins (not to be confused with Vim plugins!).
18 #define MM_ENABLE_PLUGINS
23 // This is the protocol MMBackend implements.
25 // Only processInput:data: is allowed to cause state changes in Vim; all other
26 // messages should only read the Vim state. (Note that setDialogReturn: is an
27 // exception to this rule; there really is no other way to deal with dialogs
28 // since they work with callbacks, so we cannot wait for them to return.)
30 // Be careful with messages with return type other than 'oneway void' -- there
31 // is a reply timeout set in MMAppController, if a message fails to get a
32 // response within the given timeout an exception will be thrown. Use
33 // @try/@catch/@finally to deal with timeouts.
35 @protocol MMBackendProtocol
36 - (oneway
void)processInput
:(int)msgid data
:(in bycopy NSData
*)data
;
37 - (oneway
void)setDialogReturn
:(in bycopy id
)obj
;
38 - (NSString
*)evaluateExpression
:(in bycopy NSString
*)expr
;
39 - (id
)evaluateExpressionCocoa
:(in bycopy NSString
*)expr
40 errorString
:(out bycopy NSString
**)errstr
;
41 - (BOOL
)starRegisterToPasteboard
:(byref NSPasteboard
*)pboard
;
42 - (oneway
void)acknowledgeConnection
;
47 // This is the protocol MMAppController implements.
49 // It handles connections between MacVim and Vim and communication from Vim to
52 // Do not add methods to this interface without a _very_ good reason (if
53 // possible, instead add a new message to the *MsgID enum below and pass it via
54 // processInput:forIdentifier). Methods should not modify the state directly
55 // but should instead delay any potential modifications (see
56 // connectBackend:pid: and processInput:forIdentifier:).
58 @protocol MMAppProtocol
59 - (unsigned)connectBackend
:(byref in id
<MMBackendProtocol
>)proxy pid
:(int)pid
;
60 - (oneway
void)processInput
:(in bycopy NSArray
*)queue
61 forIdentifier
:(unsigned)identifier
;
62 - (NSArray
*)serverList
;
66 @protocol MMVimServerProtocol
;
69 // The Vim client protocol (implemented by MMBackend).
71 // The client needs to keep track of server replies. Take a look at MMBackend
72 // if you want to implement this protocol in another program.
74 @protocol MMVimClientProtocol
75 - (oneway
void)addReply
:(in bycopy NSString
*)reply
76 server
:(in byref id
<MMVimServerProtocol
>)server
;
81 // The Vim server protocol (implemented by MMBackend).
83 // Note that addInput:client: is not asynchronous, because otherwise Vim might
84 // quit before the message has been passed (e.g. if --remote was used on the
87 @protocol MMVimServerProtocol
88 - (void)addInput
:(in bycopy NSString
*)input
89 client
:(in byref id
<MMVimClientProtocol
>)client
;
90 - (NSString
*)evaluateExpression
:(in bycopy NSString
*)expr
91 client
:(in byref id
<MMVimClientProtocol
>)client
;
97 // The following enum lists all messages that are passed between MacVim and
98 // Vim. These can be sent in processInput:data: and in processCommandQueue:.
101 // NOTE! This array must be updated whenever the enum below changes!
102 extern char *MessageStrings
[];
105 OpenWindowMsgID
= 1, // NOTE: FIRST IN ENUM MUST BE 1
117 SetTextDimensionsMsgID
,
119 SetTextDimensionsReplyMsgID
,
133 CreateScrollbarMsgID
,
134 DestroyScrollbarMsgID
,
136 SetScrollbarPositionMsgID
,
137 SetScrollbarThumbMsgID
,
142 SetDefaultColorsMsgID
,
151 AdjustLinespaceMsgID
,
154 EnterFullscreenMsgID
,
155 LeaveFullscreenMsgID
,
156 BuffersNotModifiedMsgID
,
157 BuffersModifiedMsgID
,
159 SetPreEditPositionMsgID
,
162 EnableAntialiasMsgID
,
163 DisableAntialiasMsgID
,
165 SetDocumentFilenameMsgID
,
166 OpenWithArgumentsMsgID
,
168 SetFullscreenColorMsgID
,
169 ShowFindReplaceDialogMsgID
,
171 ActivateKeyScriptMsgID
,
172 DeactivateKeyScriptMsgID
,
173 EnableImControlMsgID
,
174 DisableImControlMsgID
,
180 LastMsgID
// NOTE: MUST BE LAST MESSAGE IN ENUM!
184 #define DRAW_WIDE 0x40 /* draw wide text */
187 ClearAllDrawType
= 1,
193 SetCursorPosDrawType
,
194 DrawInvertedRectDrawType
,
198 MMInsertionPointBlock
,
199 MMInsertionPointHorizontal
,
200 MMInsertionPointVertical
,
201 MMInsertionPointHollow
,
202 MMInsertionPointVerticalRight
,
207 ToolbarLabelFlag
= 1,
209 ToolbarSizeRegularFlag
= 4
220 // Create a string holding the labels of all messages in message queue for
221 // debugging purposes (condense some messages since there may typically be LOTS
222 // of them on a queue).
223 NSString
*debugStringForMessageQueue(NSArray
*queue
);
226 // Shared user defaults (most user defaults are in Miscellaneous.h).
227 // Contrary to the user defaults in Miscellaneous.h these defaults are not
228 // intitialized to any default values. That is, unless the user sets them
229 // these keys will not be present in the user default database.
230 extern NSString
*MMLogLevelKey
;
231 extern NSString
*MMLogToStdErrKey
;
233 // Argument used to stop MacVim from opening an empty window on startup
234 // (techincally this is a user default but should not be used as such).
235 extern NSString
*MMNoWindowKey
;
238 // Vim pasteboard type (holds motion type + string)
239 extern NSString
*VimPBoardType
;
244 @interface
NSString (MMExtras
)
245 - (NSString
*)stringByEscapingSpecialFilenameCharacters
;
249 @interface
NSColor (MMExtras
)
250 + (NSColor
*)colorWithRgbInt
:(unsigned)rgb
;
251 + (NSColor
*)colorWithArgbInt
:(unsigned)argb
;
255 @interface
NSDictionary (MMExtras
)
256 + (id
)dictionaryWithData
:(NSData
*)data
;
257 - (NSData
*)dictionaryAsData
;
260 @interface
NSMutableDictionary (MMExtras
)
261 + (id
)dictionaryWithData
:(NSData
*)data
;
267 // ODB Editor Suite Constants (taken from ODBEditorSuite.h)
268 #define keyFileSender 'FSnd'
269 #define keyFileSenderToken 'FTok'
270 #define keyFileCustomPath 'Burl'
271 #define kODBEditorSuite 'R*ch'
272 #define kAEModifiedFile 'FMod'
273 #define keyNewLocation 'New?'
274 #define kAEClosedFile 'FCls'
275 #define keySenderToken 'Tokn'
278 // MacVim Apple Event Constants
279 #define keyMMUntitledWindow 'MMuw'
284 #if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_4
285 // NSInteger was introduced in 10.5
286 # if __LP64__ || NS_BUILD_32_LIKE_64
287 typedef long NSInteger
;
288 typedef unsigned long NSUInteger
;
290 typedef int NSInteger
;
291 typedef unsigned int NSUInteger
;
295 #ifndef NSAppKitVersionNumber10_4 // Needed for pre-10.5 SDK
296 # define NSAppKitVersionNumber10_4 824
300 // Logging related functions and macros.
302 // This is a very simplistic logging facility built on top of ASL. Two user
303 // defaults allow for changing the local log filter level (MMLogLevel) and
304 // whether logs should be sent to stderr (MMLogToStdErr). (These user defaults
305 // are only checked during startup.) The default is to block level 6 (info)
306 // and 7 (debug) logs and _not_ to send logs to stderr. Apart from this
307 // "syslog" (see "man syslog") can be used to modify the ASL filters (it is
308 // currently not possible to change the local filter at runtime). For example:
309 // Enable all logs to reach the ASL database (by default 'debug' and 'info'
310 // are filtered out, see "man syslogd"):
311 // $ sudo syslog -c syslogd -d
312 // Reset the ASL database filter:
313 // $ sudo syslog -c syslogd off
314 // Change the master filter to block logs less severe than errors:
315 // $ sudo syslog -c 0 -e
316 // Change per-process filter for running MacVim process to block logs less
317 // severe than warnings:
318 // $ syslog -c MacVim -w
320 // Note that there are four ASL filters:
321 // 1) The ASL database filter (syslog -c syslogd ...)
322 // 2) The master filter (syslog -c 0 ...)
323 // 3) The per-process filter (syslog -c PID ...)
324 // 4) The local filter (MMLogLevel)
326 // To view the logs, either use "Console.app" or the "syslog" command:
327 // $ syslog -w | grep Vim
328 // To get the logs to show up in Xcode enable the MMLogToStdErr user default.
330 extern int ASLogLevel
;
334 #define ASLog(level, fmt, ...) \
335 if (level <= ASLogLevel) { \
336 asl_log(NULL, NULL, level, "%s@%d: %s", \
337 __PRETTY_FUNCTION__, __LINE__, \
338 [[NSString stringWithFormat:fmt, ##__VA_ARGS__] UTF8String]); \
341 // Note: These macros are used like ASLogErr(@"text num=%d", 42). Objective-C
342 // style specifiers (%@) are supported.
343 #define ASLogCrit(fmt, ...) ASLog(ASL_LEVEL_CRIT, fmt, ##__VA_ARGS__)
344 #define ASLogErr(fmt, ...) ASLog(ASL_LEVEL_ERR, fmt, ##__VA_ARGS__)
345 #define ASLogWarn(fmt, ...) ASLog(ASL_LEVEL_WARNING, fmt, ##__VA_ARGS__)
346 #define ASLogNotice(fmt, ...) ASLog(ASL_LEVEL_NOTICE, fmt, ##__VA_ARGS__)
347 #define ASLogInfo(fmt, ...) ASLog(ASL_LEVEL_INFO, fmt, ##__VA_ARGS__)
348 #define ASLogDebug(fmt, ...) ASLog(ASL_LEVEL_DEBUG, fmt, ##__VA_ARGS__)