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
;
252 // Vim pasteboard type (holds motion type + string)
253 extern NSString
*VimPBoardType
;
258 @interface
NSString (MMExtras
)
259 - (NSString
*)stringByEscapingSpecialFilenameCharacters
;
263 @interface
NSColor (MMExtras
)
264 + (NSColor
*)colorWithRgbInt
:(unsigned)rgb
;
265 + (NSColor
*)colorWithArgbInt
:(unsigned)argb
;
269 @interface
NSDictionary (MMExtras
)
270 + (id
)dictionaryWithData
:(NSData
*)data
;
271 - (NSData
*)dictionaryAsData
;
274 @interface
NSMutableDictionary (MMExtras
)
275 + (id
)dictionaryWithData
:(NSData
*)data
;
281 // ODB Editor Suite Constants (taken from ODBEditorSuite.h)
282 #define keyFileSender 'FSnd'
283 #define keyFileSenderToken 'FTok'
284 #define keyFileCustomPath 'Burl'
285 #define kODBEditorSuite 'R*ch'
286 #define kAEModifiedFile 'FMod'
287 #define keyNewLocation 'New?'
288 #define kAEClosedFile 'FCls'
289 #define keySenderToken 'Tokn'
292 // MacVim Apple Event Constants
293 #define keyMMUntitledWindow 'MMuw'
298 #ifndef NSINTEGER_DEFINED
299 // NSInteger was introduced in 10.5
300 # if __LP64__ || NS_BUILD_32_LIKE_64
301 typedef long NSInteger
;
302 typedef unsigned long NSUInteger
;
304 typedef int NSInteger
;
305 typedef unsigned int NSUInteger
;
307 # define NSINTEGER_DEFINED 1
310 #ifndef NSAppKitVersionNumber10_4 // Needed for pre-10.5 SDK
311 # define NSAppKitVersionNumber10_4 824
314 #ifndef CGFLOAT_DEFINED
315 // On Leopard, CGFloat is float on 32bit and double on 64bit. On Tiger,
316 // we can't use this anyways, so it's just here to keep the compiler happy.
317 // However, when we're compiling for Tiger and running on Leopard, we
318 // might need the correct typedef, so this piece is copied from ATSTypes.h
320 typedef double CGFloat
;
322 typedef float CGFloat
;
327 // Logging related functions and macros.
329 // This is a very simplistic logging facility built on top of ASL. Two user
330 // defaults allow for changing the local log filter level (MMLogLevel) and
331 // whether logs should be sent to stderr (MMLogToStdErr). (These user defaults
332 // are only checked during startup.) The default is to block level 6 (info)
333 // and 7 (debug) logs and _not_ to send logs to stderr. Apart from this
334 // "syslog" (see "man syslog") can be used to modify the ASL filters (it is
335 // currently not possible to change the local filter at runtime). For example:
336 // Enable all logs to reach the ASL database (by default 'debug' and 'info'
337 // are filtered out, see "man syslogd"):
338 // $ sudo syslog -c syslogd -d
339 // Reset the ASL database filter:
340 // $ sudo syslog -c syslogd off
341 // Change the master filter to block logs less severe than errors:
342 // $ sudo syslog -c 0 -e
343 // Change per-process filter for running MacVim process to block logs less
344 // severe than warnings:
345 // $ syslog -c MacVim -w
347 // Note that there are four ASL filters:
348 // 1) The ASL database filter (syslog -c syslogd ...)
349 // 2) The master filter (syslog -c 0 ...)
350 // 3) The per-process filter (syslog -c PID ...)
351 // 4) The local filter (MMLogLevel)
353 // To view the logs, either use "Console.app" or the "syslog" command:
354 // $ syslog -w | grep Vim
355 // To get the logs to show up in Xcode enable the MMLogToStdErr user default.
357 extern int ASLogLevel
;
361 #define ASLog(level, fmt, ...) \
362 if (level <= ASLogLevel) { \
363 asl_log(NULL, NULL, level, "%s@%d: %s", \
364 __PRETTY_FUNCTION__, __LINE__, \
365 [[NSString stringWithFormat:fmt, ##__VA_ARGS__] UTF8String]); \
368 // Note: These macros are used like ASLogErr(@"text num=%d", 42). Objective-C
369 // style specifiers (%@) are supported.
370 #define ASLogCrit(fmt, ...) ASLog(ASL_LEVEL_CRIT, fmt, ##__VA_ARGS__)
371 #define ASLogErr(fmt, ...) ASLog(ASL_LEVEL_ERR, fmt, ##__VA_ARGS__)
372 #define ASLogWarn(fmt, ...) ASLog(ASL_LEVEL_WARNING, fmt, ##__VA_ARGS__)
373 #define ASLogNotice(fmt, ...) ASLog(ASL_LEVEL_NOTICE, fmt, ##__VA_ARGS__)
374 #define ASLogInfo(fmt, ...) ASLog(ASL_LEVEL_INFO, fmt, ##__VA_ARGS__)
375 #define ASLogDebug(fmt, ...) ASLog(ASL_LEVEL_DEBUG, fmt, ##__VA_ARGS__)
376 #define ASLogTmp(fmt, ...) ASLog(ASL_LEVEL_NOTICE, fmt, ##__VA_ARGS__)