From adff3182ba51523423ce15cf26347c2b8b130826 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jan=20Dj=C3=A4rv?= Date: Mon, 30 Jul 2012 22:10:31 +0200 Subject: [PATCH] Don't open files from Cocoa-parsed command line. --eval '(whatever)' will open '(whatever)' if --eval is the last option. * src/nsterm.m (ns_do_open_file): New variable. (ns_term_init): Set ns_do_open_file to NO after run returns. (openFile, openTempFile, openFileWithoutUI, openFiles): Open files only if ns_do_open_file. --- src/ChangeLog | 7 +++++++ src/nsterm.m | 30 ++++++++++++++++++++---------- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 5354c6e29ba..a7e6cb52eae 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2012-07-30 Jan Djärv + + * nsterm.m (ns_do_open_file): New variable. + (ns_term_init): Set ns_do_open_file to NO after run returns. + (openFile, openTempFile, openFileWithoutUI, openFiles): Open + files only if ns_do_open_file. + 2012-07-30 Paul Eggert * lisp.h (SWITCH_ENUM_CAST): Remove. All uses removed. diff --git a/src/nsterm.m b/src/nsterm.m index 1f06d49c5b9..4e181e9d1d2 100644 --- a/src/nsterm.m +++ b/src/nsterm.m @@ -195,6 +195,7 @@ static int n_emacs_events_pending = 0; static NSMutableArray *ns_pending_files, *ns_pending_service_names, *ns_pending_service_args; static BOOL inNsSelect = 0; +static BOOL ns_do_open_file = NO; /* Convert modifiers in a NeXTstep event to emacs style modifiers. */ #define NS_FUNCTION_KEY_MASK 0x800000 @@ -4025,7 +4026,7 @@ ns_term_init (Lisp_Object display_name) ns_pending_service_names = [[NSMutableArray alloc] init]; ns_pending_service_args = [[NSMutableArray alloc] init]; - /* Start app and create the main menu, window, view. +/* Start app and create the main menu, window, view. Needs to be here because ns_initialize_display_info () uses AppKit classes. The view will then ask the NSApp to stop and return to Emacs. */ [EmacsApp sharedApplication]; @@ -4205,7 +4206,7 @@ ns_term_init (Lisp_Object display_name) #endif /* MAC OS X menu setup */ [NSApp run]; - + ns_do_open_file = YES; return dpyinfo; } @@ -4446,7 +4447,8 @@ ns_term_shutdown (int sig) /* Notification from the Workspace to open a file */ - (BOOL)application: sender openFile: (NSString *)file { - [ns_pending_files addObject: file]; + if (ns_do_open_file) + [ns_pending_files addObject: file]; return YES; } @@ -4454,7 +4456,8 @@ ns_term_shutdown (int sig) /* Open a file as a temporary file */ - (BOOL)application: sender openTempFile: (NSString *)file { - [ns_pending_files addObject: file]; + if (ns_do_open_file) + [ns_pending_files addObject: file]; return YES; } @@ -4462,7 +4465,8 @@ ns_term_shutdown (int sig) /* Notification from the Workspace to open a file noninteractively (?) */ - (BOOL)application: sender openFileWithoutUI: (NSString *)file { - [ns_pending_files addObject: file]; + if (ns_do_open_file) + [ns_pending_files addObject: file]; return YES; } @@ -4470,11 +4474,17 @@ ns_term_shutdown (int sig) /* Notification from the Workspace to open multiple files */ - (void)application: sender openFiles: (NSArray *)fileList { - NSEnumerator *files = [fileList objectEnumerator]; - NSString *file; - while ((file = [files nextObject]) != nil) - [ns_pending_files addObject: file]; - + /* Don't open files from the command line, Cocoa parses the command line + wrong anyway, --option value tries to open value if --option is the last + option. */ + if (ns_ignore_open_file) + { + NSEnumerator *files = [fileList objectEnumerator]; + NSString *file; + while ((file = [files nextObject]) != nil) + [ns_pending_files addObject: file]; + } + [self replyToOpenOrPrint: NSApplicationDelegateReplySuccess]; } -- 2.39.2