(wait_reading_process_input): Show and hide busy
[bpt/emacs.git] / src / process.c
index 9bf9c73..50b8647 100644 (file)
@@ -644,7 +644,7 @@ signal -- for a process that has got a fatal signal.\n\
 open -- for a network stream connection that is open.\n\
 closed -- for a network stream connection that is closed.\n\
 nil -- if arg is a process name and no such process exists.\n\
-PROCESS may be a process, a buffer, the name of a process or buffer, or\n\
+PROCESS may be a process, a buffer, the name of a process, or\n\
 nil, indicating the current buffer's process.")
   (process)
      register Lisp_Object process;
@@ -1442,11 +1442,9 @@ create_process (process, new_argv, current_dir)
       /* In unibyte mode, character code conversion should not take
         place but EOL conversion should.  So, setup raw-text or one
         of the subsidiary according to the information just setup.  */
-      if (NILP (Vcoding_system_for_read)
-         && !NILP (XPROCESS (process)->decode_coding_system))
+      if (!NILP (XPROCESS (process)->decode_coding_system))
        setup_raw_text_coding_system (proc_decode_coding_system[inchannel]);
-      if (NILP (Vcoding_system_for_write)
-         && !NILP (XPROCESS (process)->encode_coding_system))
+      if (!NILP (XPROCESS (process)->encode_coding_system))
        setup_raw_text_coding_system (proc_encode_coding_system[outchannel]);
     }
 
@@ -2157,6 +2155,9 @@ Return non-nil iff we received any output before the timeout expired.")
   int seconds;
   int useconds;
 
+  if (! NILP (process))
+    CHECK_PROCESS (process, 0);
+
   if (! NILP (timeout_msecs))
     {
       CHECK_NUMBER (timeout_msecs, 2);
@@ -2313,6 +2314,11 @@ wait_reading_process_input (time_limit, microsecs, read_kbd, do_display)
     {
       int timeout_reduced_for_timers = 0;
 
+#ifdef HAVE_X_WINDOWS
+      if (display_busy_cursor_p)
+       Fx_hide_busy_cursor (Qnil);
+#endif
+
       /* If calling from keyboard input, do not quit
         since we want to return C-g as an input character.
         Otherwise, do pending quit if requested.  */
@@ -2724,6 +2730,12 @@ wait_reading_process_input (time_limit, microsecs, read_kbd, do_display)
      Turn periodic alarms back on */
   start_polling ();
 #endif
+
+#ifdef HAVE_X_WINDOWS
+  if (display_busy_cursor_p)
+    if (!inhibit_busy_cursor)
+      Fx_show_busy_cursor ();
+#endif
    
   return got_some_input;
 }
@@ -2841,7 +2853,12 @@ read_process_output (proc, channel)
 
   /* At this point, NBYTES holds number of characters just received
      (including the one in proc_buffered_char[channel]).  */
-  if (nbytes <= 0) return nbytes;
+  if (nbytes <= 0)
+    {
+      if (nbytes < 0 || coding->mode & CODING_MODE_LAST_BLOCK)
+       return nbytes;
+      coding->mode |= CODING_MODE_LAST_BLOCK;
+    }
 
   /* Now set NBYTES how many bytes we must decode.  */
   nbytes += carryover;
@@ -2989,7 +3006,14 @@ read_process_output (proc, channel)
         save the match data in a special nonrecursive fashion.  */
       running_asynch_code = 1;
 
-      text = make_string_from_bytes (chars, nchars, nbytes);
+      /* The multibyteness of a string given to the filter is decided
+         by which coding system we used for decoding.  */
+      if (coding->type == coding_type_no_conversion
+         || coding->type == coding_type_raw_text)
+       text = make_unibyte_string (chars, nbytes);
+      else
+       text = make_multibyte_string (chars, nchars, nbytes);
+
       internal_condition_case_1 (read_process_output_call,
                                 Fcons (outstream,
                                        Fcons (proc, Fcons (text, Qnil))),
@@ -3082,7 +3106,10 @@ read_process_output (proc, channel)
          insert_before_markers (temp_buf, nbytes);
        }
       else
-       insert_1_both (chars, nchars, nbytes, 0, 1, 1);
+       {
+         insert_1_both (chars, nchars, nbytes, 0, 1, 1);
+         signal_after_change (opoint, 0, PT - opoint);
+       }
       set_marker_both (p->mark, p->buffer, PT, PT_BYTE);
 
       update_mode_lines++;
@@ -3194,11 +3221,11 @@ send_process (proc, buf, len, object)
 
       /* Remember the offset of data because a string or a buffer may
          be relocated.  Setting OFFSET to -1 means we don't have to
-         care relocation.  */
+         care about relocation.  */
       offset = (BUFFERP (object)
                ? BUF_PTR_BYTE_POS (XBUFFER (object), buf)
                : (STRINGP (object)
-                  ? offset = buf - XSTRING (object)->data
+                  ? buf - XSTRING (object)->data
                   : -1));
 
       if (carryover > 0)
@@ -3211,7 +3238,7 @@ send_process (proc, buf, len, object)
                buf = BUF_BYTE_ADDRESS (XBUFFER (object), offset);
              else if (STRINGP (object))
                buf = offset + XSTRING (object)->data;
-             /* Now we don't have to care relocation.  */
+             /* Now we don't have to care about relocation.  */
              offset = -1;
            }
          bcopy ((XSTRING (XPROCESS (proc)->encoding_buf)->data
@@ -3426,10 +3453,49 @@ Output from processes can arrive in between bunches.")
   return Qnil;
 }
 \f
+DEFUN ("process-running-child-p", Fprocess_running_child_p,
+       Sprocess_running_child_p, 0, 1, 0,
+  "Return t if PROCESS has given the terminal to a child.\n\
+If the operating system does not make it possible to find out,\n\
+return t unconditionally.")
+  (process)
+     Lisp_Object process;
+{
+  /* Initialize in case ioctl doesn't exist or gives an error,
+     in a way that will cause returning t.  */
+  int gid = 0;
+  Lisp_Object proc;
+  struct Lisp_Process *p;
+
+  proc = get_process (process);
+  p = XPROCESS (proc);
+
+  if (!EQ (p->childp, Qt))
+    error ("Process %s is not a subprocess",
+          XSTRING (p->name)->data);
+  if (XINT (p->infd) < 0)
+    error ("Process %s is not active",
+          XSTRING (p->name)->data);
+
+#ifdef TIOCGPGRP 
+  if (!NILP (p->subtty))
+    ioctl (XFASTINT (p->subtty), TIOCGPGRP, &gid);
+  else
+    ioctl (XINT (p->infd), TIOCGPGRP, &gid);
+#endif /* defined (TIOCGPGRP ) */
+
+  if (gid == XFASTINT (p->pid))
+    return Qnil;
+  return Qt;
+}
+\f
 /* send a signal number SIGNO to PROCESS.
-   CURRENT_GROUP means send to the process group that currently owns
-   the terminal being used to communicate with PROCESS.
+   If CURRENT_GROUP is t, that means send to the process group
+   that currently owns the terminal being used to communicate with PROCESS.
    This is used for various commands in shell mode.
+   If CURRENT_GROUP is lambda, that means send to the process group
+   that currently owns the terminal, but only if it is NOT the shell itself.
+
    If NOMSG is zero, insert signal-announcements into process's buffers
    right away.
 
@@ -3585,6 +3651,11 @@ process_send_signal (process, signo, current_group, nomsg)
         the child itself heads the pgrp.  */
       gid = - XFASTINT (p->pid);
 #endif /* ! defined (TIOCGPGRP ) */
+
+      /* If current_group is lambda, and the shell owns the terminal,
+        don't send any signal.  */
+      if (EQ (current_group, Qlambda) && gid == - XFASTINT (p->pid))
+       return;
     }
   else
     gid = - XFASTINT (p->pid);
@@ -3651,7 +3722,10 @@ Second arg CURRENT-GROUP non-nil means send signal to\n\
 the current process-group of the process's controlling terminal\n\
 rather than to the process's own process group.\n\
 If the process is a shell, this means interrupt current subjob\n\
-rather than the shell.")
+rather than the shell.\n\
+\n\
+If CURRENT-GROUP is `lambda', and if the shell owns the terminal,\n\
+don't send the signal.")
   (process, current_group)
      Lisp_Object process, current_group;
 {
@@ -3843,8 +3917,10 @@ text to PROCESS after you call this function.")
      Lisp_Object process;
 {
   Lisp_Object proc;
+  struct coding_system *coding;
 
   proc = get_process (process);
+  coding = proc_encode_coding_system[XINT (XPROCESS (proc)->outfd)];
 
   /* Make sure the process is really alive.  */
   if (! NILP (XPROCESS (proc)->raw_status_low))
@@ -3852,6 +3928,12 @@ text to PROCESS after you call this function.")
   if (! EQ (XPROCESS (proc)->status, Qrun))
     error ("Process %s not running", XSTRING (XPROCESS (proc)->name)->data);
 
+  if (CODING_REQUIRE_FLUSHING (coding))
+    {
+      coding->mode |= CODING_MODE_LAST_BLOCK;
+      send_process (proc, "", 0, Qnil);
+    }
+
 #ifdef VMS
   send_process (proc, "\032", 1, Qnil);        /* ^z */
 #else
@@ -4516,6 +4598,7 @@ The value takes effect when `start-process' is called.");
   defsubr (&Squit_process);
   defsubr (&Sstop_process);
   defsubr (&Scontinue_process);
+  defsubr (&Sprocess_running_child_p);
   defsubr (&Sprocess_send_eof);
   defsubr (&Ssignal_process);
   defsubr (&Swaiting_for_user_input_p);