diff --git a/ChangeLog b/ChangeLog
index 06af05e66abd69f94605acaffd9712ba0d9b1aec..dd0b146e36a3464e7a06bd97e74676d34f426e55 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -85,7 +85,8 @@ CVS Code -
 	  printed as-is and be interpreted as commands by xterm, which
 	  will corrupt the display.) (DLR)
 	- Add command line option -I/--ignorercfiles to ignore
-	  /etc/nanorc and ~/.nanorc. (Carl Drinkwater)
+	  /etc/nanorc and ~/.nanorc. (Carl Drinkwater).   Fix to parsing
+	  getopt args (DLR).
 	- Fix minor bugs with importing certain text files in Mac
 	  format. (DLR)
 - files.c:
diff --git a/nano.c b/nano.c
index b3f7e8161d715cf9c29cfd889e9bf991af771c22..41690aa40418d4db4a739cc9493f2d0e747cd614 100644
--- a/nano.c
+++ b/nano.c
@@ -2916,35 +2916,26 @@ int main(int argc, char *argv[])
 #endif
 
 #ifdef ENABLE_NANORC
-    /* scan through the options and handle -I/--ignorercfiles first, so
-       that it's handled before we call do_rcfile() and read the other
-       options */
-
-    /* stop getopt throwing up an error if we supply other options
-       as arguments */
-    opterr = 0;
-
+    {
+	/* scan through the options and handle -I/--ignorercfiles
+	   first, so that it's handled before we call do_rcfile() and
+	   read the other options; don't use getopt()/getopt_long()
+	   here, because there's no way to reset it properly
+	   afterward */
+	int i;
+	for (i = 1; i < argc; i++) {
+	    if (!strcmp(argv[i], "--"))
+		break;
+	    else if (!strcmp(argv[i], "-I"))
+		SET(NO_RCFILE);
 #ifdef HAVE_GETOPT_LONG
-    while ((optchr = getopt_long(argc, argv, "I",
-				 long_options, &option_index)) != EOF) {
-#else
-    while ((optchr =
-	    getopt(argc, argv, "I")) != EOF) {
+	    else if (!strcmp(argv[i], "--ignorercfiles"))
+		SET(NO_RCFILE);
 #endif
-	switch (optchr) {
-	case 'I':
-	    SET(NO_RCFILE);
-            break;
 	}
     }
-
-    if (!ISSET(NO_RCFILE))
-	do_rcfile();
-
-    /* reset the getopt variables so we can read through the command line
-       arguments again */
-    optind = 1;
-    opterr = 1;
+	if (!ISSET(NO_RCFILE))
+	    do_rcfile();
 #endif /* ENABLE_NANORC */
 
 #ifdef HAVE_GETOPT_LONG
@@ -2983,8 +2974,6 @@ int main(int argc, char *argv[])
 	    break;
 #endif
 #ifdef ENABLE_NANORC
-        /* we need -I/--ignorercfiles again to stop getopt giving us an
-	   error if we've already supplied it */
 	case 'I':
             break;
 #endif
diff --git a/nano.h b/nano.h
index f157646cb1c3a1bced8e2adecbbd54114fea3328..840913e3f266a15a74ea2d437716ec6250088840 100644
--- a/nano.h
+++ b/nano.h
@@ -186,10 +186,10 @@ typedef struct syntaxtype {
 #define SAMELINEWRAP		(1<<11)
 #define VIEW_MODE		(1<<12)
 #define USE_MOUSE		(1<<13)
-#define USE_REGEXP              (1<<14)
-#define REGEXP_COMPILED         (1<<15)
-#define TEMP_OPT         	(1<<16)
-#define CUT_TO_END         	(1<<17)
+#define USE_REGEXP		(1<<14)
+#define REGEXP_COMPILED		(1<<15)
+#define TEMP_OPT		(1<<16)
+#define CUT_TO_END		(1<<17)
 #define REVERSE_SEARCH		(1<<18)
 #define MULTIBUFFER		(1<<19)
 #define CLEAR_BACKUPSTRING	(1<<20)