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
36 // This is the protocol MMBackend implements.
38 // Only processInput:data: is allowed to cause state changes in Vim; all other
39 // messages should only read the Vim state. (Note that setDialogReturn: is an
40 // exception to this rule; there really is no other way to deal with dialogs
41 // since they work with callbacks, so we cannot wait for them to return.)
43 // Be careful with messages with return type other than 'oneway void' -- there
44 // is a reply timeout set in MMAppController, if a message fails to get a
45 // response within the given timeout an exception will be thrown. Use
46 // @try/@catch/@finally to deal with timeouts.
48 @protocol MMBackendProtocol
49 - (oneway
void)processInput
:(int)msgid data
:(in bycopy NSData
*)data
;
50 - (oneway
void)setDialogReturn
:(in bycopy id
)obj
;
51 - (NSString
*)evaluateExpression
:(in bycopy NSString
*)expr
;
52 - (id
)evaluateExpressionCocoa
:(in bycopy NSString
*)expr
53 errorString
:(out bycopy NSString
**)errstr
;
54 - (BOOL
)starRegisterToPasteboard
:(byref NSPasteboard
*)pboard
;
55 - (oneway
void)acknowledgeConnection
;
60 // This is the protocol MMAppController implements.
62 // It handles connections between MacVim and Vim and communication from Vim to
65 // Do not add methods to this interface without a _very_ good reason (if
66 // possible, instead add a new message to the *MsgID enum below and pass it via
67 // processInput:forIdentifier). Methods should not modify the state directly
68 // but should instead delay any potential modifications (see
69 // connectBackend:pid: and processInput:forIdentifier:).
71 @protocol MMAppProtocol
72 - (unsigned)connectBackend
:(byref in id
<MMBackendProtocol
>)proxy pid
:(int)pid
;
73 - (oneway
void)processInput
:(in bycopy NSArray
*)queue
74 forIdentifier
:(unsigned)identifier
;
75 - (NSArray
*)serverList
;
79 @protocol MMVimServerProtocol
;
82 // The Vim client protocol (implemented by MMBackend).
84 // The client needs to keep track of server replies. Take a look at MMBackend
85 // if you want to implement this protocol in another program.
87 @protocol MMVimClientProtocol
88 - (oneway
void)addReply
:(in bycopy NSString
*)reply
89 server
:(in byref id
<MMVimServerProtocol
>)server
;
94 // The Vim server protocol (implemented by MMBackend).
96 // Note that addInput:client: is not asynchronous, because otherwise Vim might
97 // quit before the message has been passed (e.g. if --remote was used on the
100 @protocol MMVimServerProtocol
101 - (void)addInput
:(in bycopy NSString
*)input
102 client
:(in byref id
<MMVimClientProtocol
>)client
;
103 - (NSString
*)evaluateExpression
:(in bycopy NSString
*)expr
104 client
:(in byref id
<MMVimClientProtocol
>)client
;
110 // The following enum lists all messages that are passed between MacVim and
111 // Vim. These can be sent in processInput:data: and in processCommandQueue:.
114 // NOTE! This array must be updated whenever the enum below changes!
115 extern char *MessageStrings
[];
118 OpenWindowMsgID
= 1, // NOTE: FIRST IN ENUM MUST BE 1
130 SetTextDimensionsMsgID
,
132 SetTextDimensionsReplyMsgID
,
146 CreateScrollbarMsgID
,
147 DestroyScrollbarMsgID
,
149 SetScrollbarPositionMsgID
,
150 SetScrollbarThumbMsgID
,
155 SetDefaultColorsMsgID
,
164 AdjustLinespaceMsgID
,
167 EnterFullscreenMsgID
,
168 LeaveFullscreenMsgID
,
169 BuffersNotModifiedMsgID
,
170 BuffersModifiedMsgID
,
172 SetPreEditPositionMsgID
,
175 EnableAntialiasMsgID
,
176 DisableAntialiasMsgID
,
178 SetDocumentFilenameMsgID
,
179 OpenWithArgumentsMsgID
,
181 SetFullscreenColorMsgID
,
182 ShowFindReplaceDialogMsgID
,
184 ActivateKeyScriptMsgID
,
185 DeactivateKeyScriptMsgID
,
186 EnableImControlMsgID
,
187 DisableImControlMsgID
,
194 LastMsgID
// NOTE: MUST BE LAST MESSAGE IN ENUM!
198 #define DRAW_WIDE 0x40 /* draw wide text */
201 ClearAllDrawType
= 1,
207 SetCursorPosDrawType
,
208 DrawInvertedRectDrawType
,
212 MMInsertionPointBlock
,
213 MMInsertionPointHorizontal
,
214 MMInsertionPointVertical
,
215 MMInsertionPointHollow
,
216 MMInsertionPointVerticalRight
,
221 ToolbarLabelFlag
= 1,
223 ToolbarSizeRegularFlag
= 4
234 // Create a string holding the labels of all messages in message queue for
235 // debugging purposes (condense some messages since there may typically be LOTS
236 // of them on a queue).
237 NSString
*debugStringForMessageQueue(NSArray
*queue
);
240 // Shared user defaults (most user defaults are in Miscellaneous.h).
241 // Contrary to the user defaults in Miscellaneous.h these defaults are not
242 // intitialized to any default values. That is, unless the user sets them
243 // these keys will not be present in the user default database.
244 extern NSString
*MMLogLevelKey
;
245 extern NSString
*MMLogToStdErrKey
;
247 // Argument used to stop MacVim from opening an empty window on startup
248 // (techincally this is a user default but should not be used as such).
249 extern NSString
*MMNoWindowKey
;
251 extern NSString
*MMAutosaveRowsKey
;
252 extern NSString
*MMAutosaveColumnsKey
;
255 // Vim pasteboard type (holds motion type + string)
256 extern NSString
*VimPBoardType
;
261 @interface
NSString (MMExtras
)
262 - (NSString
*)stringByEscapingSpecialFilenameCharacters
;
266 @interface
NSColor (MMExtras
)
267 + (NSColor
*)colorWithRgbInt
:(unsigned)rgb
;
268 + (NSColor
*)colorWithArgbInt
:(unsigned)argb
;
272 @interface
NSDictionary (MMExtras
)
273 + (id
)dictionaryWithData
:(NSData
*)data
;
274 - (NSData
*)dictionaryAsData
;
277 @interface
NSMutableDictionary (MMExtras
)
278 + (id
)dictionaryWithData
:(NSData
*)data
;
284 // ODB Editor Suite Constants (taken from ODBEditorSuite.h)
285 #define keyFileSender 'FSnd'
286 #define keyFileSenderToken 'FTok'
287 #define keyFileCustomPath 'Burl'
288 #define kODBEditorSuite 'R*ch'
289 #define kAEModifiedFile 'FMod'
290 #define keyNewLocation 'New?'
291 #define kAEClosedFile 'FCls'
292 #define keySenderToken 'Tokn'
295 // MacVim Apple Event Constants
296 #define keyMMUntitledWindow 'MMuw'
301 #if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_4
302 // NSInteger was introduced in 10.5
303 # if __LP64__ || NS_BUILD_32_LIKE_64
304 typedef long NSInteger
;
305 typedef unsigned long NSUInteger
;
307 typedef int NSInteger
;
308 typedef unsigned int NSUInteger
;
312 #ifndef NSAppKitVersionNumber10_4 // Needed for pre-10.5 SDK
313 # define NSAppKitVersionNumber10_4 824
317 // Logging related functions and macros.
319 // This is a very simplistic logging facility built on top of ASL. Two user
320 // defaults allow for changing the local log filter level (MMLogLevel) and
321 // whether logs should be sent to stderr (MMLogToStdErr). (These user defaults
322 // are only checked during startup.) The default is to block level 6 (info)
323 // and 7 (debug) logs and _not_ to send logs to stderr. Apart from this
324 // "syslog" (see "man syslog") can be used to modify the ASL filters (it is
325 // currently not possible to change the local filter at runtime). For example:
326 // Enable all logs to reach the ASL database (by default 'debug' and 'info'
327 // are filtered out, see "man syslogd"):
328 // $ sudo syslog -c syslogd -d
329 // Reset the ASL database filter:
330 // $ sudo syslog -c syslogd off
331 // Change the master filter to block logs less severe than errors:
332 // $ sudo syslog -c 0 -e
333 // Change per-process filter for running MacVim process to block logs less
334 // severe than warnings:
335 // $ syslog -c MacVim -w
337 // Note that there are four ASL filters:
338 // 1) The ASL database filter (syslog -c syslogd ...)
339 // 2) The master filter (syslog -c 0 ...)
340 // 3) The per-process filter (syslog -c PID ...)
341 // 4) The local filter (MMLogLevel)
343 // To view the logs, either use "Console.app" or the "syslog" command:
344 // $ syslog -w | grep Vim
345 // To get the logs to show up in Xcode enable the MMLogToStdErr user default.
347 extern int ASLogLevel
;
351 #define ASLog(level, fmt, ...) \
352 if (level <= ASLogLevel) { \
353 asl_log(NULL, NULL, level, "%s@%d: %s", \
354 __PRETTY_FUNCTION__, __LINE__, \
355 [[NSString stringWithFormat:fmt, ##__VA_ARGS__] UTF8String]); \
358 // Note: These macros are used like ASLogErr(@"text num=%d", 42). Objective-C
359 // style specifiers (%@) are supported.
360 #define ASLogCrit(fmt, ...) ASLog(ASL_LEVEL_CRIT, fmt, ##__VA_ARGS__)
361 #define ASLogErr(fmt, ...) ASLog(ASL_LEVEL_ERR, fmt, ##__VA_ARGS__)
362 #define ASLogWarn(fmt, ...) ASLog(ASL_LEVEL_WARNING, fmt, ##__VA_ARGS__)
363 #define ASLogNotice(fmt, ...) ASLog(ASL_LEVEL_NOTICE, fmt, ##__VA_ARGS__)
364 #define ASLogInfo(fmt, ...) ASLog(ASL_LEVEL_INFO, fmt, ##__VA_ARGS__)
365 #define ASLogDebug(fmt, ...) ASLog(ASL_LEVEL_DEBUG, fmt, ##__VA_ARGS__)
366 #define ASLogTmp(fmt, ...) ASLog(ASL_LEVEL_NOTICE, fmt, ##__VA_ARGS__)