about summary refs log tree commit diff stats
path: root/src/ips
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-06-26 14:10:03 +0200
committerbptato <nincsnevem662@gmail.com>2023-06-26 14:10:03 +0200
commit4d34f50d74b2b9c7ba2269f087018ee07334c16a (patch)
treea30edf4c16757c67903a83cb928c830e6707bfdf /src/ips
parent1a903c2b3f16e63485188b4b8a4b9efb3f6df7cd (diff)
downloadchawan-4d34f50d74b2b9c7ba2269f087018ee07334c16a.tar.gz
openEditor: check for error
Diffstat (limited to 'src/ips')
-rw-r--r--src/ips/editor.nim19
1 files changed, 11 insertions, 8 deletions
diff --git a/src/ips/editor.nim b/src/ips/editor.nim
index 5a172f79..a6a6623c 100644
--- a/src/ips/editor.nim
+++ b/src/ips/editor.nim
@@ -42,14 +42,17 @@ proc openEditor*(term: Terminal, config: Config, file: string, line = 1): bool =
   let cmd = formatEditorName(editor, file, line)
   term.quit()
   let wstatus = c_system(cstring(cmd))
-  result = WIFEXITED(wstatus) and WEXITSTATUS(wstatus) == 0
-  if not result:
-    # Hack.
-    #TODO this is a very bad idea, e.g. say the editor is writing into the
-    # file, then receives SIGINT, now the file is corrupted but Chawan will
-    # happily read it as if nothing happened.
-    # We should find a proper solution for this.
-    result = WIFSIGNALED(wstatus) and WTERMSIG(wstatus) == SIGINT
+  if wstatus == -1:
+    result = false
+  else:
+    result = WIFEXITED(wstatus) and WEXITSTATUS(wstatus) == 0
+    if not result:
+      # Hack.
+      #TODO this is a very bad idea, e.g. say the editor is writing into the
+      # file, then receives SIGINT, now the file is corrupted but Chawan will
+      # happily read it as if nothing happened.
+      # We should find a proper solution for this.
+      result = WIFSIGNALED(wstatus) and WTERMSIG(wstatus) == SIGINT
   term.restart()
 
 var tmpf_seq: int