@@ -166,45 +166,11 @@ - (void)inputSourceChanged:(NSNotification *)notification;
166
166
167
167
@implementation MMAppController
168
168
169
- + (void)initialize
169
+ /// Register the default settings for MacVim. Supports an optional
170
+ /// "-IgnoreUserDefaults 1" command-line argument, which will override
171
+ /// persisted user settings to have a clean environment.
172
+ + (void)registerDefaults
170
173
{
171
- static BOOL initDone = NO;
172
- if (initDone) return;
173
- initDone = YES;
174
-
175
- ASLInit();
176
-
177
- // HACK! The following user default must be reset, else Ctrl-q (or
178
- // whichever key is specified by the default) will be blocked by the input
179
- // manager (interpretKeyEvents: swallows that key). (We can't use
180
- // NSUserDefaults since it only allows us to write to the registration
181
- // domain and this preference has "higher precedence" than that so such a
182
- // change would have no effect.)
183
- CFPreferencesSetAppValue(CFSTR("NSQuotedKeystrokeBinding"),
184
- CFSTR(""),
185
- kCFPreferencesCurrentApplication);
186
-
187
- // Also disable NSRepeatCountBinding -- it is not enabled by default, but
188
- // it does not make much sense to support it since Vim has its own way of
189
- // dealing with repeat counts.
190
- CFPreferencesSetAppValue(CFSTR("NSRepeatCountBinding"),
191
- CFSTR(""),
192
- kCFPreferencesCurrentApplication);
193
-
194
- if ([NSWindow respondsToSelector:@selector(setAllowsAutomaticWindowTabbing:)]) {
195
- // Disable automatic tabbing on 10.12+. MacVim already has its own
196
- // tabbing interface, so we don't want multiple hierarchy of tabs mixing
197
- // native and Vim tabs. MacVim also doesn't work well with native tabs
198
- // right now since it doesn't respond well to the size change, and it
199
- // doesn't show the native menu items (e.g. move tab to new window) in
200
- // all the tabs.
201
- //
202
- // Note: MacVim cannot use macOS native tabs for Vim tabs because Vim
203
- // assumes only one tab can be shown at a time, and it would be hard to
204
- // handle native tab's "move tab to a new window" functionality.
205
- [NSWindow setAllowsAutomaticWindowTabbing:NO];
206
- }
207
-
208
174
int tabMinWidthKey;
209
175
int tabMaxWidthKey;
210
176
int tabOptimumWidthKey;
@@ -218,7 +184,9 @@ + (void)initialize
218
184
tabOptimumWidthKey = 132;
219
185
}
220
186
221
- NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
187
+ NSUserDefaults *ud = NSUserDefaults.standardUserDefaults;
188
+
189
+ NSDictionary *macvimDefaults = [NSDictionary dictionaryWithObjectsAndKeys:
222
190
[NSNumber numberWithBool:NO], MMNoWindowKey,
223
191
[NSNumber numberWithInt:tabMinWidthKey],
224
192
MMTabMinWidthKey,
@@ -244,6 +212,9 @@ + (void)initialize
244
212
[NSNumber numberWithInt:MMUntitledWindowAlways],
245
213
MMUntitledWindowKey,
246
214
[NSNumber numberWithBool:NO], MMNoWindowShadowKey,
215
+ [NSNumber numberWithInt:0], MMAppearanceModeSelectionKey,
216
+ [NSNumber numberWithBool:NO], MMNoTitleBarWindowKey,
217
+ [NSNumber numberWithBool:NO], MMTitlebarAppearsTransparentKey,
247
218
[NSNumber numberWithBool:NO], MMZoomBothKey,
248
219
@"", MMLoginShellCommandKey,
249
220
@"", MMLoginShellArgumentKey,
@@ -271,7 +242,58 @@ + (void)initialize
271
242
[NSNumber numberWithBool:0], MMScrollOneDirectionOnlyKey,
272
243
nil];
273
244
274
- [[NSUserDefaults standardUserDefaults] registerDefaults:dict];
245
+ [ud registerDefaults:macvimDefaults];
246
+
247
+ NSArray<NSString *> *arguments = NSProcessInfo.processInfo.arguments;
248
+ if ([arguments containsObject:@"-IgnoreUserDefaults"]) {
249
+ NSDictionary<NSString *, id> *argDefaults = [ud volatileDomainForName:NSArgumentDomain];
250
+ NSMutableDictionary<NSString *, id> *combinedDefaults = [NSMutableDictionary dictionaryWithCapacity: macvimDefaults.count];
251
+ [combinedDefaults setDictionary:macvimDefaults];
252
+ [combinedDefaults addEntriesFromDictionary:argDefaults];
253
+ [ud setVolatileDomain:combinedDefaults forName:NSArgumentDomain];
254
+ }
255
+ }
256
+
257
+ + (void)initialize
258
+ {
259
+ static BOOL initDone = NO;
260
+ if (initDone) return;
261
+ initDone = YES;
262
+
263
+ ASLInit();
264
+
265
+ // HACK! The following user default must be reset, else Ctrl-q (or
266
+ // whichever key is specified by the default) will be blocked by the input
267
+ // manager (interpreargumenttKeyEvents: swallows that key). (We can't use
268
+ // NSUserDefaults since it only allows us to write to the registration
269
+ // domain and this preference has "higher precedence" than that so such a
270
+ // change would have no effect.)
271
+ CFPreferencesSetAppValue(CFSTR("NSQuotedKeystrokeBinding"),
272
+ CFSTR(""),
273
+ kCFPreferencesCurrentApplication);
274
+
275
+ // Also disable NSRepeatCountBinding -- it is not enabled by default, but
276
+ // it does not make much sense to support it since Vim has its own way of
277
+ // dealing with repeat counts.
278
+ CFPreferencesSetAppValue(CFSTR("NSRepeatCountBinding"),
279
+ CFSTR(""),
280
+ kCFPreferencesCurrentApplication);
281
+
282
+ if ([NSWindow respondsToSelector:@selector(setAllowsAutomaticWindowTabbing:)]) {
283
+ // Disable automatic tabbing on 10.12+. MacVim already has its own
284
+ // tabbing interface, so we don't want multiple hierarchy of tabs mixing
285
+ // native and Vim tabs. MacVim also doesn't work well with native tabs
286
+ // right now since it doesn't respond well to the size change, and it
287
+ // doesn't show the native menu items (e.g. move tab to new window) in
288
+ // all the tabs.
289
+ //
290
+ // Note: MacVim cannot use macOS native tabs for Vim tabs because Vim
291
+ // assumes only one tab can be shown at a time, and it would be hard to
292
+ // handle native tab's "move tab to a new window" functionality.
293
+ [NSWindow setAllowsAutomaticWindowTabbing:NO];
294
+ }
295
+
296
+ [MMAppController registerDefaults];
275
297
276
298
NSArray *types = [NSArray arrayWithObject:NSPasteboardTypeString];
277
299
[NSApp registerServicesMenuSendTypes:types returnTypes:types];
@@ -1296,25 +1318,50 @@ - (BOOL)validateMenuItem:(NSMenuItem *)item
1296
1318
return YES;
1297
1319
}
1298
1320
1299
- - (IBAction)newWindow:(id)sender
1321
+ /// Open a new Vim window, potentially taking from cached (if preload is used).
1322
+ ///
1323
+ /// @param mode Determine whether to use clean mode or not. Preload will only
1324
+ /// be used if using normal mode.
1325
+ ///
1326
+ /// @param activate Activate the window after it's opened.
1327
+ - (void)openNewWindow:(enum NewWindowMode)mode activate:(BOOL)activate
1300
1328
{
1301
- ASLogDebug(@"Open new window");
1329
+ if (activate)
1330
+ [self activateWhenNextWindowOpens];
1302
1331
1303
1332
// A cached controller requires no loading times and results in the new
1304
1333
// window popping up instantaneously. If the cache is empty it may take
1305
1334
// 1-2 seconds to start a new Vim process.
1306
- MMVimController *vc = [self takeVimControllerFromCache];
1335
+ MMVimController *vc = (mode == NewWindowNormal) ? [self takeVimControllerFromCache] : nil ;
1307
1336
if (vc) {
1308
1337
[[vc backendProxy] acknowledgeConnection];
1309
1338
} else {
1310
- [self launchVimProcessWithArguments:nil workingDirectory:nil];
1339
+ NSArray *args = (mode == NewWindowNormal) ? nil
1340
+ : (mode == NewWindowClean ? @[@"--clean"]
1341
+ : @[@"--clean", @"-u", @"NONE"]);
1342
+ [self launchVimProcessWithArguments:args workingDirectory:nil];
1311
1343
}
1312
1344
}
1313
1345
1346
+ - (IBAction)newWindow:(id)sender
1347
+ {
1348
+ ASLogDebug(@"Open new window");
1349
+ [self openNewWindow:NewWindowNormal activate:NO];
1350
+ }
1351
+
1352
+ - (IBAction)newWindowClean:(id)sender
1353
+ {
1354
+ [self openNewWindow:NewWindowClean activate:NO];
1355
+ }
1356
+
1357
+ - (IBAction)newWindowCleanNoDefaults:(id)sender
1358
+ {
1359
+ [self openNewWindow:NewWindowCleanNoDefaults activate:NO];
1360
+ }
1361
+
1314
1362
- (IBAction)newWindowAndActivate:(id)sender
1315
1363
{
1316
- [self activateWhenNextWindowOpens];
1317
- [self newWindow:sender];
1364
+ [self openNewWindow:NewWindowNormal activate:YES];
1318
1365
}
1319
1366
1320
1367
- (IBAction)fileOpen:(id)sender
0 commit comments