about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/kilo.c5
-rw-r--r--src/lcurseslib.c10
-rw-r--r--src/lua.c4
3 files changed, 14 insertions, 5 deletions
diff --git a/src/kilo.c b/src/kilo.c
index f3b5665..174bdc3 100644
--- a/src/kilo.c
+++ b/src/kilo.c
@@ -1154,6 +1154,7 @@ void editorMoveCursor(int key) {
 /* Process events arriving from the standard input, which is, the user
  * is typing stuff on the terminal. */
 #define KILO_QUIT_TIMES 3
+int Quit = 0;
 void editorProcessKeypress(int fd) {
     /* When the file is modified, requires Ctrl-q to be pressed N times
      * before actually quitting. */
@@ -1176,7 +1177,7 @@ void editorProcessKeypress(int fd) {
             quit_times--;
             return;
         }
-        exit(0);
+        Quit = 1;
         break;
     case CTRL_S:        /* Ctrl-s */
         editorSave();
@@ -1263,7 +1264,7 @@ void edit(char* filename) {
     enableRawMode(STDIN_FILENO);
     editorSetStatusMessage(
         "HELP: Ctrl-S = save | Ctrl-Q = quit | Ctrl-F = find");
-    while(1) {
+    while(!Quit) {
         editorRefreshScreen();
         editorProcessKeypress(STDIN_FILENO);
     }
diff --git a/src/lcurseslib.c b/src/lcurseslib.c
index d9bcd37..515c30c 100644
--- a/src/lcurseslib.c
+++ b/src/lcurseslib.c
@@ -1,6 +1,7 @@
 #include <ncurses.h>
 #include <stdlib.h>
 #include <string.h>
+#include <unistd.h>
 
 #include "lua.h"
 #include "llimits.h"
@@ -88,15 +89,20 @@ static int Pcolor_pair (lua_State *L)
 }
 
 
-extern const char *Script_name;
+extern char **Argv;
+extern char *Script_name;
+extern void edit(char* filename);
 static int Pgetch (lua_State *L) {
   int c = wgetch(stdscr);
   if (c == ERR)
     return 0;
   if (c == 24)  /* ctrl-x */
     exit(0);
-  if (c == 5)  /* ctrl-e */
+  if (c == 5) {  /* ctrl-e */
+    /* death and rebirth */
     edit(Script_name);
+    execv(Argv[0], Argv);
+  }
   /* handle other standard menu hotkeys here */
   lua_pushinteger(L, c);
   return 1;
diff --git a/src/lua.c b/src/lua.c
index 0b6dcb3..7142641 100644
--- a/src/lua.c
+++ b/src/lua.c
@@ -245,7 +245,7 @@ static int handle_script (lua_State *L, char **argv, int n) {
   if (status == 0)
     status = docall(L, narg, 0);
   else
-    lua_pop(L, narg);      
+    lua_pop(L, narg);
   return report(L, status);
 }
 
@@ -369,6 +369,7 @@ static int pmain (lua_State *L) {
 
 
 void draw_menu(void);
+char **Argv = NULL;
 
 
 int main (int argc, char **argv) {
@@ -385,6 +386,7 @@ int main (int argc, char **argv) {
   echo();
   s.argc = argc;
   s.argv = argv;
+  Argv = argv;
   status = lua_cpcall(L, &pmain, &s);
   report(L, status);
   lua_close(L);