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 // Uncomment to enable support for MacVim plugins (not to be confused with Vim
19 //#define MM_ENABLE_PLUGINS
22 // Taken from /usr/include/AvailabilityMacros.h
23 #ifndef MAC_OS_X_VERSION_10_4
24 # define MAC_OS_X_VERSION_10_4 1040
26 #ifndef MAC_OS_X_VERSION_10_5
27 # define MAC_OS_X_VERSION_10_5 1050
29 #ifndef MAC_OS_X_VERSION_10_6
30 # define MAC_OS_X_VERSION_10_6 1060
35 // This is the protocol MMBackend implements.
37 // Only processInput:data: is allowed to cause state changes in Vim; all other
38 // messages should only read the Vim state. (Note that setDialogReturn: is an
39 // exception to this rule; there really is no other way to deal with dialogs
40 // since they work with callbacks, so we cannot wait for them to return.)
42 // Be careful with messages with return type other than 'oneway void' -- there
43 // is a reply timeout set in MMAppController, if a message fails to get a
44 // response within the given timeout an exception will be thrown. Use
45 // @try/@catch/@finally to deal with timeouts.
47 @protocol MMBackendProtocol
48 - (oneway
void)processInput
:(int)msgid data
:(in bycopy NSData
*)data
;
49 - (oneway
void)setDialogReturn
:(in bycopy id
)obj
;
50 - (NSString
*)evaluateExpression
:(in bycopy NSString
*)expr
;
51 - (id
)evaluateExpressionCocoa
:(in bycopy NSString
*)expr
52 errorString
:(out bycopy NSString
**)errstr
;
53 - (BOOL
)starRegisterToPasteboard
:(byref NSPasteboard
*)pboard
;
54 - (oneway
void)acknowledgeConnection
;
59 // This is the protocol MMAppController implements.
61 // It handles connections between MacVim and Vim and communication from Vim to
64 // Do not add methods to this interface without a _very_ good reason (if
65 // possible, instead add a new message to the *MsgID enum below and pass it via
66 // processInput:forIdentifier). Methods should not modify the state directly
67 // but should instead delay any potential modifications (see
68 // connectBackend:pid: and processInput:forIdentifier:).
70 @protocol MMAppProtocol
71 - (unsigned)connectBackend
:(byref in id
<MMBackendProtocol
>)proxy pid
:(int)pid
;
72 - (oneway
void)processInput
:(in bycopy NSArray
*)queue
73 forIdentifier
:(unsigned)identifier
;
74 - (NSArray
*)serverList
;
78 @protocol MMVimServerProtocol
;
81 // The Vim client protocol (implemented by MMBackend).
83 // The client needs to keep track of server replies. Take a look at MMBackend
84 // if you want to implement this protocol in another program.
86 @protocol MMVimClientProtocol
87 - (oneway
void)addReply
:(in bycopy NSString
*)reply
88 server
:(in byref id
<MMVimServerProtocol
>)server
;
93 // The Vim server protocol (implemented by MMBackend).
95 // Note that addInput:client: is not asynchronous, because otherwise Vim might
96 // quit before the message has been passed (e.g. if --remote was used on the
99 @protocol MMVimServerProtocol
100 - (void)addInput
:(in bycopy NSString
*)input
101 client
:(in byref id
<MMVimClientProtocol
>)client
;
102 - (NSString
*)evaluateExpression
:(in bycopy NSString
*)expr
103 client
:(in byref id
<MMVimClientProtocol
>)client
;
109 // The following enum lists all messages that are passed between MacVim and
110 // Vim. These can be sent in processInput:data: and in processCommandQueue:.
113 // NOTE! This array must be updated whenever the enum below changes!
114 extern char *MessageStrings
[];
117 OpenWindowMsgID
= 1, // NOTE: FIRST IN ENUM MUST BE 1
129 SetTextDimensionsMsgID
,
131 SetTextDimensionsReplyMsgID
,
145 CreateScrollbarMsgID
,
146 DestroyScrollbarMsgID
,
148 SetScrollbarPositionMsgID
,
149 SetScrollbarThumbMsgID
,
154 SetDefaultColorsMsgID
,
163 AdjustLinespaceMsgID
,
166 EnterFullscreenMsgID
,
167 LeaveFullscreenMsgID
,
168 BuffersNotModifiedMsgID
,
169 BuffersModifiedMsgID
,
171 SetPreEditPositionMsgID
,
174 EnableAntialiasMsgID
,
175 DisableAntialiasMsgID
,
177 SetDocumentFilenameMsgID
,
178 OpenWithArgumentsMsgID
,
180 SetFullscreenColorMsgID
,
181 ShowFindReplaceDialogMsgID
,
183 ActivateKeyScriptMsgID
,
184 DeactivateKeyScriptMsgID
,
185 EnableImControlMsgID
,
186 DisableImControlMsgID
,
193 LastMsgID
// NOTE: MUST BE LAST MESSAGE IN ENUM!
198 ClearAllDrawType
= 1,
204 SetCursorPosDrawType
,
205 DrawInvertedRectDrawType
,
209 MMInsertionPointBlock
,
210 MMInsertionPointHorizontal
,
211 MMInsertionPointVertical
,
212 MMInsertionPointHollow
,
213 MMInsertionPointVerticalRight
,
218 ToolbarLabelFlag
= 1,
220 ToolbarSizeRegularFlag
= 4
231 // Create a string holding the labels of all messages in message queue for
232 // debugging purposes (condense some messages since there may typically be LOTS
233 // of them on a queue).
234 NSString
*debugStringForMessageQueue(NSArray
*queue
);
237 // Shared user defaults (most user defaults are in Miscellaneous.h).
238 // Contrary to the user defaults in Miscellaneous.h these defaults are not
239 // intitialized to any default values. That is, unless the user sets them
240 // these keys will not be present in the user default database.
241 extern NSString
*MMLogLevelKey
;
242 extern NSString
*MMLogToStdErrKey
;
244 // Argument used to stop MacVim from opening an empty window on startup
245 // (techincally this is a user default but should not be used as such).
246 extern NSString
*MMNoWindowKey
;
248 extern NSString
*MMAutosaveRowsKey
;
249 extern NSString
*MMAutosaveColumnsKey
;
250 extern NSString
*MMRendererKey
;
253 MMRendererDefault
= 0,
259 // Vim pasteboard type (holds motion type + string)
260 extern NSString
*VimPBoardType
;
265 @interface
NSString (MMExtras
)
266 - (NSString
*)stringByEscapingSpecialFilenameCharacters
;
270 @interface
NSColor (MMExtras
)
271 + (NSColor
*)colorWithRgbInt
:(unsigned)rgb
;
272 + (NSColor
*)colorWithArgbInt
:(unsigned)argb
;
276 @interface
NSDictionary (MMExtras
)
277 + (id
)dictionaryWithData
:(NSData
*)data
;
278 - (NSData
*)dictionaryAsData
;
281 @interface
NSMutableDictionary (MMExtras
)
282 + (id
)dictionaryWithData
:(NSData
*)data
;
288 // ODB Editor Suite Constants (taken from ODBEditorSuite.h)
289 #define keyFileSender 'FSnd'
290 #define keyFileSenderToken 'FTok'
291 #define keyFileCustomPath 'Burl'
292 #define kODBEditorSuite 'R*ch'
293 #define kAEModifiedFile 'FMod'
294 #define keyNewLocation 'New?'
295 #define kAEClosedFile 'FCls'
296 #define keySenderToken 'Tokn'
299 // MacVim Apple Event Constants
300 #define keyMMUntitledWindow 'MMuw'
305 #ifndef NSINTEGER_DEFINED
306 // NSInteger was introduced in 10.5
307 # if __LP64__ || NS_BUILD_32_LIKE_64
308 typedef long NSInteger
;
309 typedef unsigned long NSUInteger
;
311 typedef int NSInteger
;
312 typedef unsigned int NSUInteger
;
314 # define NSINTEGER_DEFINED 1
317 #ifndef NSAppKitVersionNumber10_4 // Needed for pre-10.5 SDK
318 # define NSAppKitVersionNumber10_4 824
321 #ifndef CGFLOAT_DEFINED
322 // On Leopard, CGFloat is float on 32bit and double on 64bit. On Tiger,
323 // we can't use this anyways, so it's just here to keep the compiler happy.
324 // However, when we're compiling for Tiger and running on Leopard, we
325 // might need the correct typedef, so this piece is copied from ATSTypes.h
327 typedef double CGFloat
;
329 typedef float CGFloat
;
334 // Logging related functions and macros.
336 // This is a very simplistic logging facility built on top of ASL. Two user
337 // defaults allow for changing the local log filter level (MMLogLevel) and
338 // whether logs should be sent to stderr (MMLogToStdErr). (These user defaults
339 // are only checked during startup.) The default is to block level 6 (info)
340 // and 7 (debug) logs and _not_ to send logs to stderr. Apart from this
341 // "syslog" (see "man syslog") can be used to modify the ASL filters (it is
342 // currently not possible to change the local filter at runtime). For example:
343 // Enable all logs to reach the ASL database (by default 'debug' and 'info'
344 // are filtered out, see "man syslogd"):
345 // $ sudo syslog -c syslogd -d
346 // Reset the ASL database filter:
347 // $ sudo syslog -c syslogd off
348 // Change the master filter to block logs less severe than errors:
349 // $ sudo syslog -c 0 -e
350 // Change per-process filter for running MacVim process to block logs less
351 // severe than warnings:
352 // $ syslog -c MacVim -w
354 // Note that there are four ASL filters:
355 // 1) The ASL database filter (syslog -c syslogd ...)
356 // 2) The master filter (syslog -c 0 ...)
357 // 3) The per-process filter (syslog -c PID ...)
358 // 4) The local filter (MMLogLevel)
360 // To view the logs, either use "Console.app" or the "syslog" command:
361 // $ syslog -w | grep Vim
362 // To get the logs to show up in Xcode enable the MMLogToStdErr user default.
364 extern int ASLogLevel
;
368 #define ASLog(level, fmt, ...) \
369 if (level <= ASLogLevel) { \
370 asl_log(NULL, NULL, level, "%s@%d: %s", \
371 __PRETTY_FUNCTION__, __LINE__, \
372 [[NSString stringWithFormat:fmt, ##__VA_ARGS__] UTF8String]); \
375 // Note: These macros are used like ASLogErr(@"text num=%d", 42). Objective-C
376 // style specifiers (%@) are supported.
377 #define ASLogCrit(fmt, ...) ASLog(ASL_LEVEL_CRIT, fmt, ##__VA_ARGS__)
378 #define ASLogErr(fmt, ...) ASLog(ASL_LEVEL_ERR, fmt, ##__VA_ARGS__)
379 #define ASLogWarn(fmt, ...) ASLog(ASL_LEVEL_WARNING, fmt, ##__VA_ARGS__)
380 #define ASLogNotice(fmt, ...) ASLog(ASL_LEVEL_NOTICE, fmt, ##__VA_ARGS__)
381 #define ASLogInfo(fmt, ...) ASLog(ASL_LEVEL_INFO, fmt, ##__VA_ARGS__)
382 #define ASLogDebug(fmt, ...) ASLog(ASL_LEVEL_DEBUG, fmt, ##__VA_ARGS__)
383 #define ASLogTmp(fmt, ...) ASLog(ASL_LEVEL_NOTICE, fmt, ##__VA_ARGS__)