comparison src/process.c @ 90776:dd7c098af727

Merge from emacs--devo--0 Patches applied: * emacs--devo--0 (patch 638-652) - Update from CVS - Merge from gnus--rel--5.10 * gnus--rel--5.10 (patch 202) - Update from CVS Revision: emacs@sv.gnu.org/emacs--unicode--0--patch-177
author Miles Bader <miles@gnu.org>
date Mon, 26 Feb 2007 23:03:45 +0000
parents 95d0cdf160ea 8e93fec28139
children c0e889bf140c
comparison
equal deleted inserted replaced
90775:7d8921cab8aa 90776:dd7c098af727
5639 } 5639 }
5640 5640
5641 UNGCPRO; 5641 UNGCPRO;
5642 } 5642 }
5643 5643
5644 static Lisp_Object
5645 send_process_object_unwind (buf)
5646 Lisp_Object buf;
5647 {
5648 Lisp_Object tembuf;
5649
5650 if (XBUFFER (buf) == current_buffer)
5651 return Qnil;
5652 tembuf = Fcurrent_buffer ();
5653 Fset_buffer (buf);
5654 Fkill_buffer (tembuf);
5655 return Qnil;
5656 }
5657
5658 /* Send current contents of region between START and END to PROC.
5659 If START is a string, send it instead.
5660 This function can evaluate Lisp code and can garbage collect. */
5661
5662 static void
5663 send_process_object (proc, start, end)
5664 Lisp_Object proc, start, end;
5665 {
5666 int count = SPECPDL_INDEX ();
5667 Lisp_Object object = STRINGP (start) ? start : Fcurrent_buffer ();
5668 struct buffer *given_buffer = current_buffer;
5669 unsigned char *buf;
5670 int len;
5671
5672 record_unwind_protect (send_process_object_unwind, Fcurrent_buffer ());
5673
5674 if (STRINGP (object) ? STRING_MULTIBYTE (object)
5675 : ! NILP (XBUFFER (object)->enable_multibyte_characters))
5676 {
5677 struct Lisp_Process *p = XPROCESS (proc);
5678 struct coding_system *coding = proc_encode_coding_system[XINT (p->outfd)];
5679
5680 if (! EQ (coding->symbol, p->encode_coding_system))
5681 /* The coding system for encoding was changed to raw-text
5682 because we sent a unibyte text previously. Now we are
5683 sending a multibyte text, thus we must encode it by the
5684 original coding system specified for the current process. */
5685 setup_coding_system (p->encode_coding_system, coding);
5686 if (! NILP (coding->pre_write_conversion))
5687 {
5688 struct gcpro gcpro1, gcpro2;
5689
5690 GCPRO2 (proc, object);
5691 call2 (coding->pre_write_conversion, start, end);
5692 UNGCPRO;
5693 if (given_buffer != current_buffer)
5694 {
5695 start = make_number (BEGV), end = make_number (ZV);
5696 object = Fcurrent_buffer ();
5697 }
5698 }
5699 }
5700
5701 if (BUFFERP (object))
5702 {
5703 EMACS_INT start_byte;
5704
5705 if (XINT (start) < GPT && XINT (end) > GPT)
5706 move_gap (XINT (end));
5707 start_byte = CHAR_TO_BYTE (XINT (start));
5708 buf = BYTE_POS_ADDR (start_byte);
5709 len = CHAR_TO_BYTE (XINT (end)) - start_byte;
5710 }
5711 else
5712 {
5713 buf = SDATA (object);
5714 len = SBYTES (object);
5715 }
5716 send_process (proc, buf, len, object);
5717
5718 unbind_to (count, Qnil);
5719 }
5720
5644 DEFUN ("process-send-region", Fprocess_send_region, Sprocess_send_region, 5721 DEFUN ("process-send-region", Fprocess_send_region, Sprocess_send_region,
5645 3, 3, 0, 5722 3, 3, 0,
5646 doc: /* Send current contents of region as input to PROCESS. 5723 doc: /* Send current contents of region as input to PROCESS.
5647 PROCESS may be a process, a buffer, the name of a process or buffer, or 5724 PROCESS may be a process, a buffer, the name of a process or buffer, or
5648 nil, indicating the current buffer's process. 5725 nil, indicating the current buffer's process.
5652 Output from processes can arrive in between bunches. */) 5729 Output from processes can arrive in between bunches. */)
5653 (process, start, end) 5730 (process, start, end)
5654 Lisp_Object process, start, end; 5731 Lisp_Object process, start, end;
5655 { 5732 {
5656 Lisp_Object proc; 5733 Lisp_Object proc;
5657 int start1, end1;
5658 5734
5659 proc = get_process (process); 5735 proc = get_process (process);
5660 validate_region (&start, &end); 5736 validate_region (&start, &end);
5661 5737 send_process_object (proc, start, end);
5662 if (XINT (start) < GPT && XINT (end) > GPT)
5663 move_gap (XINT (start));
5664
5665 start1 = CHAR_TO_BYTE (XINT (start));
5666 end1 = CHAR_TO_BYTE (XINT (end));
5667 send_process (proc, BYTE_POS_ADDR (start1), end1 - start1,
5668 Fcurrent_buffer ());
5669
5670 return Qnil; 5738 return Qnil;
5671 } 5739 }
5672 5740
5673 DEFUN ("process-send-string", Fprocess_send_string, Sprocess_send_string, 5741 DEFUN ("process-send-string", Fprocess_send_string, Sprocess_send_string,
5674 2, 2, 0, 5742 2, 2, 0,
5682 Lisp_Object process, string; 5750 Lisp_Object process, string;
5683 { 5751 {
5684 Lisp_Object proc; 5752 Lisp_Object proc;
5685 CHECK_STRING (string); 5753 CHECK_STRING (string);
5686 proc = get_process (process); 5754 proc = get_process (process);
5687 send_process (proc, SDATA (string), 5755 send_process_object (proc, string, Qnil);
5688 SBYTES (string), string);
5689 return Qnil; 5756 return Qnil;
5690 } 5757 }
5691 5758
5692 /* Return the foreground process group for the tty/pty that 5759 /* Return the foreground process group for the tty/pty that
5693 the process P uses. */ 5760 the process P uses. */