@@ -166,45 +166,11 @@ - (void)inputSourceChanged:(NSNotification *)notification;
166166
167167@implementation MMAppController
168168
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
170173{
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-
208174 int tabMinWidthKey;
209175 int tabMaxWidthKey;
210176 int tabOptimumWidthKey;
@@ -218,7 +184,9 @@ + (void)initialize
218184 tabOptimumWidthKey = 132 ;
219185 }
220186
221- NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
187+ NSUserDefaults *ud = NSUserDefaults .standardUserDefaults ;
188+
189+ NSDictionary *macvimDefaults = [NSDictionary dictionaryWithObjectsAndKeys:
222190 [NSNumber numberWithBool: NO ], MMNoWindowKey,
223191 [NSNumber numberWithInt: tabMinWidthKey],
224192 MMTabMinWidthKey,
@@ -244,6 +212,10 @@ + (void)initialize
244212 [NSNumber numberWithInt: MMUntitledWindowAlways],
245213 MMUntitledWindowKey,
246214 [NSNumber numberWithBool: NO ], MMNoWindowShadowKey,
215+ [NSNumber numberWithBool: NO ], MMDisableLaunchAnimationKey,
216+ [NSNumber numberWithInt: 0 ], MMAppearanceModeSelectionKey,
217+ [NSNumber numberWithBool: NO ], MMNoTitleBarWindowKey,
218+ [NSNumber numberWithBool: NO ], MMTitlebarAppearsTransparentKey,
247219 [NSNumber numberWithBool: NO ], MMZoomBothKey,
248220 @" " , MMLoginShellCommandKey,
249221 @" " , MMLoginShellArgumentKey,
@@ -271,7 +243,58 @@ + (void)initialize
271243 [NSNumber numberWithBool: 0 ], MMScrollOneDirectionOnlyKey,
272244 nil ];
273245
274- [[NSUserDefaults standardUserDefaults ] registerDefaults: dict];
246+ [ud registerDefaults: macvimDefaults];
247+
248+ NSArray <NSString *> *arguments = NSProcessInfo .processInfo .arguments ;
249+ if ([arguments containsObject: @" -IgnoreUserDefaults" ]) {
250+ NSDictionary <NSString *, id > *argDefaults = [ud volatileDomainForName: NSArgumentDomain ];
251+ NSMutableDictionary <NSString *, id > *combinedDefaults = [NSMutableDictionary dictionaryWithCapacity: macvimDefaults.count];
252+ [combinedDefaults setDictionary: macvimDefaults];
253+ [combinedDefaults addEntriesFromDictionary: argDefaults];
254+ [ud setVolatileDomain: combinedDefaults forName: NSArgumentDomain ];
255+ }
256+ }
257+
258+ + (void )initialize
259+ {
260+ static BOOL initDone = NO ;
261+ if (initDone) return ;
262+ initDone = YES ;
263+
264+ ASLInit ();
265+
266+ // HACK! The following user default must be reset, else Ctrl-q (or
267+ // whichever key is specified by the default) will be blocked by the input
268+ // manager (interpreargumenttKeyEvents: swallows that key). (We can't use
269+ // NSUserDefaults since it only allows us to write to the registration
270+ // domain and this preference has "higher precedence" than that so such a
271+ // change would have no effect.)
272+ CFPreferencesSetAppValue (CFSTR (" NSQuotedKeystrokeBinding" ),
273+ CFSTR (" " ),
274+ kCFPreferencesCurrentApplication );
275+
276+ // Also disable NSRepeatCountBinding -- it is not enabled by default, but
277+ // it does not make much sense to support it since Vim has its own way of
278+ // dealing with repeat counts.
279+ CFPreferencesSetAppValue (CFSTR (" NSRepeatCountBinding" ),
280+ CFSTR (" " ),
281+ kCFPreferencesCurrentApplication );
282+
283+ if ([NSWindow respondsToSelector: @selector (setAllowsAutomaticWindowTabbing: )]) {
284+ // Disable automatic tabbing on 10.12+. MacVim already has its own
285+ // tabbing interface, so we don't want multiple hierarchy of tabs mixing
286+ // native and Vim tabs. MacVim also doesn't work well with native tabs
287+ // right now since it doesn't respond well to the size change, and it
288+ // doesn't show the native menu items (e.g. move tab to new window) in
289+ // all the tabs.
290+ //
291+ // Note: MacVim cannot use macOS native tabs for Vim tabs because Vim
292+ // assumes only one tab can be shown at a time, and it would be hard to
293+ // handle native tab's "move tab to a new window" functionality.
294+ [NSWindow setAllowsAutomaticWindowTabbing: NO ];
295+ }
296+
297+ [MMAppController registerDefaults ];
275298
276299 NSArray *types = [NSArray arrayWithObject: NSPasteboardTypeString ];
277300 [NSApp registerServicesMenuSendTypes: types returnTypes: types];
@@ -1296,25 +1319,60 @@ - (BOOL)validateMenuItem:(NSMenuItem *)item
12961319 return YES ;
12971320}
12981321
1299- - (IBAction )newWindow : (id )sender
1322+ // / Open a new Vim window, potentially taking from cached (if preload is used).
1323+ // /
1324+ // / @param mode Determine whether to use clean mode or not. Preload will only
1325+ // / be used if using normal mode.
1326+ // /
1327+ // / @param activate Activate the window after it's opened.
1328+ - (void )openNewWindow : (enum NewWindowMode)mode activate : (BOOL )activate
13001329{
1301- ASLogDebug (@" Open new window" );
1330+ if (activate)
1331+ [self activateWhenNextWindowOpens ];
13021332
13031333 // A cached controller requires no loading times and results in the new
13041334 // window popping up instantaneously. If the cache is empty it may take
13051335 // 1-2 seconds to start a new Vim process.
1306- MMVimController *vc = [self takeVimControllerFromCache ];
1336+ MMVimController *vc = (mode == NewWindowNormal) ? [self takeVimControllerFromCache ] : nil ;
13071337 if (vc) {
13081338 [[vc backendProxy ] acknowledgeConnection ];
13091339 } else {
1310- [self launchVimProcessWithArguments: nil workingDirectory: nil ];
1340+ NSArray *args = (mode == NewWindowNormal) ? nil
1341+ : (mode == NewWindowClean ? @[@" --clean" ]
1342+ : @[@" --clean" , @" -u" , @" NONE" ]);
1343+ [self launchVimProcessWithArguments: args workingDirectory: nil ];
13111344 }
13121345}
13131346
1347+ - (IBAction )newWindow : (id )sender
1348+ {
1349+ ASLogDebug (@" Open new window" );
1350+ [self openNewWindow: NewWindowNormal activate: NO ];
1351+ }
1352+
1353+ - (IBAction )newWindowClean : (id )sender
1354+ {
1355+ [self openNewWindow: NewWindowClean activate: NO ];
1356+ }
1357+
1358+ - (IBAction )newWindowCleanNoDefaults : (id )sender
1359+ {
1360+ [self openNewWindow: NewWindowCleanNoDefaults activate: NO ];
1361+ }
1362+
13141363- (IBAction )newWindowAndActivate : (id )sender
13151364{
1316- [self activateWhenNextWindowOpens ];
1317- [self newWindow: sender];
1365+ [self openNewWindow: NewWindowNormal activate: YES ];
1366+ }
1367+
1368+ - (IBAction )newWindowCleanAndActivate : (id )sender
1369+ {
1370+ [self openNewWindow: NewWindowClean activate: YES ];
1371+ }
1372+
1373+ - (IBAction )newWindowCleanNoDefaultsAndActivate : (id )sender
1374+ {
1375+ [self openNewWindow: NewWindowCleanNoDefaults activate: YES ];
13181376}
13191377
13201378- (IBAction )fileOpen : (id )sender
0 commit comments