arg1 = arg;
       event_location_up location = string_to_event_location (&arg1,
                                                             current_language);
+
+      if (*arg1)
+       error (_("Junk at end of line specification."));
+
       std::vector<symtab_and_line> sals = decode_line_1 (location.get (),
                                                         DECODE_LINE_LIST_MODE,
                                                         NULL, NULL, 0);
 
       sal = sals[0];
 
-      if (*arg1)
-       error (_("Junk at end of line specification."));
-
       /* If line was specified by address, first print exactly which
         line, and which file.  In this case, sal.symtab == 0 means
         address is outside of all known source files, not that user
 
 gdb_test "list fooc:/foo/bar/baz.c" "No source file named fooc."
 
 # PR cli/28665, gdb/28797
-gdb_test "list task 123" \
-    "Junk at end of line specification\\."
-gdb_test "list if (0)" \
-    "Junk at end of line specification\\."
-gdb_test "list thread 1" \
-    "Junk at end of line specification\\."
-gdb_test "list -force-condition" \
-    "Junk at end of line specification\\."
-gdb_test "list ,," \
-    "Junk at end of line specification\\."
+save_vars { env(EDITOR) } {
+    setenv EDITOR true
+
+    foreach cmd {list edit} {
+       gdb_test "${cmd} task 123" \
+           "Junk at end of line specification\\."
+       gdb_test "${cmd} if (0)" \
+           "Junk at end of line specification\\."
+       gdb_test "${cmd} thread 1" \
+           "Junk at end of line specification\\."
+       gdb_test "${cmd} -force-condition" \
+           "Junk at end of line specification\\."
+       gdb_test "${cmd} ,," \
+           "Junk at end of line specification\\."
+    }
+}