Mercurial > hg > xemacs-beta
view lisp/code-process.el @ 1268:fffe735e63ee
[xemacs-hg @ 2003-02-07 11:50:50 by ben]
fixes for menu crashes + better preemption behavior
This contains two related changes:
(1) Fix problems with reentrant calling of lwlib and associated
crashes when selecting menu items.
(2) Improve redisplay handling of preemption. Turn on lazy lock
and hold down page-down or page-up and you'll see what I mean.
They are related because they both touch on the code that retrieves
events and handles the internal queues.
console-msw.h, event-msw.c, event-stream.c, events.h, menubar-msw.c, menubar-x.c, menubar.h: mswindows_protect_modal_loop() has been generalized to
event_stream_protect_modal_loop(), and moved to event-stream.c.
mswindows_in_modal_loop ->in_modal_loop likewise. Changes in
event-msw.c and menubar-msw.c for the new names and calling format
(use structures instead of static variables in menubar-msw.c).
Delete former in_menu_callback and use in_modal_loop in its place.
Remove emacs_mswindows_quit_check_disallowed_p(), superseded by
in_modal_loop. Use event_stream_protect_modal_loop() in
pre_activate_callback() so that we get no lwlib reentrancy.
Rearrange some of the code in event-msw.c to be grouped better.
Make mswindows_drain_windows_queue() respect in_modal_loop and
do nothing if so.
cmdloop.c, event-stream.c: Don't conditionalize on LWLIB_MENUBARS_LUCID when giving error when
in_modal_loop, and give better error.
event-Xt.c, event-gtk.c: If in_modal_loop, only retrieve process and timeout events.
Don't retrieve any X events because processing them can lead
to reentrancy in lwlib -> death.
event-stream.c: Remove unused parameter to check_event_stream_ok() and change
all callers.
lisp.h, event-stream.c: Rearrange some functions for increased clarity -- in particular,
group all the input-pending/QUIT-related stuff together, and
put right next to next-event stuff, to which it's related.
Add the concept of "HOW_MANY" -- when asking whether user input
is pending, you can ask if at least HOW_MANY events are pending,
not just if any are. Add parameter to detect_input_pending()
for this. Change recursive_sit_for from a Lisp_Object (which
could only be Qt or Qnil) to an int, like it should be.
event-Xt.c, event-gtk.c, event-xlike-inc.c: New file.
Abstract out similar code in event_{Xt/gtk}_pending_p() and write
only once, using include-file tricks. Rewrite this function to
implement HOW_MANY and only process events when not in_modal_loop.
event-msw.c: Implement HOW_MANY and only process events when not in_modal_loop.
event-tty.c: Implement HOW_MANY.
redisplay.c: Add var `max-preempts' to control maximum number of preempts.
(#### perhaps not useful) Rewrite preemption check so that,
rather than preempting when any user events are available, only
preempt when a certain number (currently 4) of them are backed up.
This effectively allows redisplay to proceed to completion in the
presence of a fast auto-repeat (usually the auto-repeating is
generated dynamically as necessary), and you get much better
display behavior with lazy-lock active.
event-unixoid.c: Comment changes.
event-stream.c: Rewrite discard-input much more simply and safely using the
drain-queue functions. I think the old version might loop
forever if called when in_modal_loop.
SEMI-UNRELATED CHANGES:
-----------------------
event-stream.c: Turn QUIT-checking back on when running the pre-idle hook so it
can be quit out of.
indent.c: Document exact functioning of `vertical-motion' better, and its
differences from GNU Emacs.
| author | ben |
|---|---|
| date | Fri, 07 Feb 2003 11:50:54 +0000 |
| parents | 13305f7e85f0 |
| children | f32f3ddaf534 |
line wrap: on
line source
;;; code-process.el --- Process coding functions for XEmacs. ;; Copyright (C) 1985-1987, 1993, 1994, 1997 Free Software Foundation, Inc. ;; Copyright (C) 1995, 2000, 2002 Ben Wing ;; Copyright (C) 1997 MORIOKA Tomohiko ;; Author: Ben Wing ;; MORIOKA Tomohiko ;; Maintainer: XEmacs Development Team ;; Keywords: mule, multilingual, coding system, process ;; This file is part of XEmacs. ;; This file is very similar to code-process.el ;; XEmacs is free software; you can redistribute it and/or modify it ;; under the terms of the GNU General Public License as published by ;; the Free Software Foundation; either version 2, or (at your option) ;; any later version. ;; XEmacs is distributed in the hope that it will be useful, but ;; WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;; General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with XEmacs; see the file COPYING. If not, write to the Free ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA ;; 02111-1307, USA. ;;; Code: (defvar process-coding-system-alist nil "Alist to decide a coding system to use for a process I/O operation. The format is ((PATTERN . VAL) ...), where PATTERN is a regular expression matching a program name, VAL is a coding system, a cons of coding systems, or a function symbol. If VAL is a coding system, it is used for both decoding what received from the program and encoding what sent to the program. If VAL is a cons of coding systems, the car part is used for decoding, and the cdr part is used for encoding. If VAL is a function symbol, it is called with two arguments, a symbol indicating the operation being performed (one of `start-process', `call-process', `open-network-stream', or `open-multicast-group') and the program name. The function must return a coding system or a cons of coding systems which are used as above.") (defun call-process (program &optional infile buffer displayp &rest args) "Call PROGRAM synchronously in separate process. The program's input comes from file INFILE (nil means `/dev/null'). XEmacs feature: INFILE can also be a list of (BUFFER [START [END]]), i.e. a list of one to three elements, consisting of a buffer and optionally a start position or start and end position. In this case, input comes from the buffer, starting from START (defaults to the beginning of the buffer) and ending at END (defaults to the end of the buffer). Insert output in BUFFER before point; t means current buffer; nil for BUFFER means discard it; 0 means discard and don't wait. If BUFFER is a string, then find or create a buffer with that name, then insert the output in that buffer, before point. BUFFER can also have the form (REAL-BUFFER STDERR-FILE); in that case, REAL-BUFFER says what to do with standard output, as above, while STDERR-FILE says what to do with standard error in the child. STDERR-FILE may be nil (discard standard error output), t (mix it with ordinary output), a file name string, or (XEmacs feature) a buffer object. If STDERR-FILE is a buffer object (but not the name of a buffer, since that would be interpreted as a file), the standard error output will be inserted into the buffer before point. Fourth arg DISPLAY non-nil means redisplay buffer as output is inserted. Remaining arguments are strings passed as command arguments to PROGRAM. If BUFFER is 0, returns immediately with value nil. Otherwise waits for PROGRAM to terminate and returns a numeric exit status or a signal description string. If you quit, the process is first killed with SIGINT, then with SIGKILL if you quit again before the process exits. If INFILE is a file, we transfer its exact contents to the process without any encoding/decoding. (#### This policy might change.) Otherwise, the read/write coding systems used for process I/O on the process are determined as follows: 1. `coding-system-for-read', `coding-system-for-write', if non-nil. (Intended as a temporary overriding mechanism for use by Lisp code.) 2. The matching value for the process name from `process-coding-system-alist', if any, and if non-nil. The value may be either a single coding system, used for both read and write; or a cons of read/write; or a function, called to get one of the other two values. 3. For writing: If a buffer was given in INFILE, the value of `buffer-file-coding-system' in that buffer. For reading: if a buffer was given in BUFFER, the value of `buffer-file-coding-system-for-read' in that buffer. 4. The value of `default-process-coding-system', which should be a cons of read/write coding systems, if the values are non-nil. 5. The coding system `undecided' for read, and `raw-text' for write. Note that the processes of determining the read and write coding systems proceed essentially independently one from the other, as in `start-process'." (let (cs-r cs-w) (let (ret) (catch 'found (let ((alist process-coding-system-alist) (case-fold-search nil)) (while alist (if (string-match (car (car alist)) program) (throw 'found (setq ret (cdr (car alist))))) (setq alist (cdr alist)) ))) (if (functionp ret) (setq ret (funcall ret 'call-process program))) (cond ((consp ret) (setq cs-r (car ret) cs-w (cdr ret))) ((and ret (find-coding-system ret)) (setq cs-r ret cs-w ret)))) (let ((coding-system-for-read (or coding-system-for-read cs-r (let ((thebuf (if (consp buffer) (car buffer) buffer))) (and (or (bufferp thebuf) (stringp thebuf)) (get-buffer thebuf) (symbol-value-in-buffer 'buffer-file-coding-system-for-read (get-buffer thebuf)))) (car default-process-coding-system) 'undecided)) (coding-system-for-write (or coding-system-for-write cs-w (and (consp infile) (symbol-value-in-buffer 'buffer-file-coding-system (get-buffer (car infile)))) (cdr default-process-coding-system) 'raw-text))) (apply 'call-process-internal program infile buffer displayp args)))) (defun call-process-region (start end program &optional deletep buffer displayp &rest args) "Send text from START to END to a synchronous process running PROGRAM. Delete the text if fourth arg DELETEP is non-nil. Insert output in BUFFER before point; t means current buffer; nil for BUFFER means discard it; 0 means discard and don't wait. If BUFFER is a string, then find or create a buffer with that name, then insert the output in that buffer, before point. BUFFER can also have the form (REAL-BUFFER STDERR-FILE); in that case, REAL-BUFFER says what to do with standard output, as above, while STDERR-FILE says what to do with standard error in the child. STDERR-FILE may be nil (discard standard error output), t (mix it with ordinary output), a file name string, or (XEmacs feature) a buffer object. If STDERR-FILE is a buffer object (but not the name of a buffer, since that would be interpreted as a file), the standard error output will be inserted into the buffer before point. Sixth arg DISPLAYP non-nil means redisplay buffer as output is inserted. Remaining args are passed to PROGRAM at startup as command args. If BUFFER is 0, returns immediately with value nil. Otherwise waits for PROGRAM to terminate and returns a numeric exit status or a signal description string. If you quit, the process is first killed with SIGINT, then with SIGKILL if you quit again before the process exits. The read/write coding systems used for process I/O on the process are the same as for `call-process'." ;; We used to delete the text before calling call-process; that was when ;; a temporary file was used to pass the text to call-process. Now that ;; we don't do that, we delete the text afterward; if it's being inserted ;; in the same buffer, make sure we track the insertion, and don't get ;; any of it in the deleted region if insertion happens at either end ;; of the region. (let ((s (and deletep (copy-marker start t))) (e (and deletep (copy-marker end)))) (let ((retval (apply #'call-process program (list (current-buffer) start end) buffer displayp args))) ;; If start and end were the same originally, s will be beyond e now (if (and deletep (> e s)) (delete-region s e)) retval))) (defun start-process (name buffer program &rest program-args) "Start a program in a subprocess. Return the process object for it. NAME is name for process. It is modified if necessary to make it unique. BUFFER is the buffer or (buffer-name) to associate with the process. Process output goes at end of that buffer, unless you specify an output stream or filter function to handle the output. BUFFER may be also nil, meaning that this process is not associated with any buffer. BUFFER can also have the form (REAL-BUFFER STDERR-BUFFER); in that case, REAL-BUFFER says what to do with standard output, as above, while STDERR-BUFFER says what to do with standard error in the child. STDERR-BUFFER may be nil (discard standard error output, unless a stderr filter is set). Note that if you do not use this form at process creation, stdout and stderr will be mixed in the output buffer, and this cannot be changed, even by setting a stderr filter. Third arg is program file name. It is searched for as in the shell. Remaining arguments are strings to give program as arguments. The read/write coding systems used for process I/O on the process are determined as follows: 1. `coding-system-for-read', `coding-system-for-write', if non-nil. (Intended as a temporary overriding mechanism for use by Lisp code.) 2. The matching value for the process name from `process-coding-system-alist', if any, and if non-nil. The value may be either a single coding system, used for both read and write; or a cons of read/write; or a function, called to get one of the other two values. 3. The value of `default-process-coding-system', which should be a cons of read/write coding systems, if the values are non-nil. 4. The coding system `undecided' for read, and `raw-text' for write. Note that the processes of determining the read and write coding systems proceed essentially independently one from the other. For example, a value determined from `process-coding-system-alist' might specify a read coding system but not a write coding system, in which the read coding system is as specified and the write coding system comes from proceeding to step 3 (and looking in `default-process-coding-system'). You can change the coding systems later on using `set-process-coding-system', `set-process-input-coding-system', or `set-process-output-coding-system'. See also `set-process-filter' and `set-process-stderr-filter'." (let (cs-r cs-w) (let (ret) (catch 'found (let ((alist process-coding-system-alist) (case-fold-search nil)) (while alist (if (string-match (car (car alist)) program) (throw 'found (setq ret (cdr (car alist))))) (setq alist (cdr alist)) ))) (if (functionp ret) (setq ret (funcall ret 'start-process program))) (cond ((consp ret) (setq cs-r (car ret) cs-w (cdr ret))) ((and ret (find-coding-system ret)) (setq cs-r ret cs-w ret)))) (let ((coding-system-for-read (or coding-system-for-read cs-r (car default-process-coding-system) 'undecided)) (coding-system-for-write (or coding-system-for-write cs-w (cdr default-process-coding-system) 'raw-text))) (apply 'start-process-internal name buffer program program-args) ))) (defvar network-coding-system-alist nil "Alist to decide a coding system to use for a network I/O operation. The format is ((PATTERN . VAL) ...), where PATTERN is a regular expression matching a network service name or is a port number to connect to, VAL is a coding system, a cons of coding systems, or a function symbol. If VAL is a coding system, it is used for both decoding what received from the network stream and encoding what sent to the network stream. If VAL is a cons of coding systems, the car part is used for decoding, and the cdr part is used for encoding. If VAL is a function symbol, the function must return a coding system or a cons of coding systems which are used as above. See also the function `find-operation-coding-system'.") (defun open-network-stream (name buffer host service &optional protocol) "Open a TCP connection for a service to a host. Return a process object to represent the connection. Input and output work as for subprocesses; `delete-process' closes it. NAME is name for process. It is modified if necessary to make it unique. BUFFER is the buffer (or buffer-name) to associate with the process. Process output goes at end of that buffer, unless you specify an output stream or filter function to handle the output. BUFFER may be also nil, meaning that this process is not associated with any buffer. Third arg is name of the host to connect to, or its IP address. Fourth arg SERVICE is name of the service desired, or an integer specifying a port number to connect to. Fifth argument PROTOCOL is a network protocol. Currently 'tcp (Transmission Control Protocol) and 'udp (User Datagram Protocol) are supported. When omitted, 'tcp is assumed. Output via `process-send-string' and input via buffer or filter (see `set-process-filter') are stream-oriented. That means UDP datagrams are not guaranteed to be sent and received in discrete packets. (But small datagrams around 500 bytes that are not truncated by `process-send-string' are usually fine.) Note further that UDP protocol does not guard against lost packets. The read/write coding systems used for process I/O on the process are determined as follows: 1. `coding-system-for-read', `coding-system-for-write', if non-nil. (Intended as a temporary overriding mechanism for use by Lisp code.) 2. The matching value for the service from `network-coding-system-alist', if any, and if non-nil. The value may be either a single coding system, used for both read and write; or a cons of read/write; or a function, called to get one of the other two values. 3. The value of `default-network-coding-system', which should be a cons of read/write coding systems, if the values are non-nil. 4. The coding system `undecided' for read, and `raw-text' for write. Note that the processes of determining the read and write coding systems proceed essentially independently one from the other, as in `start-process'. You can change the coding systems later on using `set-process-coding-system', `set-process-input-coding-system', or `set-process-output-coding-system'." (let (cs-r cs-w) (let (ret) (catch 'found (let ((alist network-coding-system-alist) (case-fold-search nil) pattern) (while alist (setq pattern (car (car alist))) (and (cond ((numberp pattern) (and (numberp service) (eq pattern service))) ((stringp pattern) (or (and (stringp service) (string-match pattern service)) (and (numberp service) (string-match pattern (number-to-string service)))))) (throw 'found (setq ret (cdr (car alist))))) (setq alist (cdr alist)) ))) (if (functionp ret) (setq ret (funcall ret 'open-network-stream service))) (cond ((consp ret) (setq cs-r (car ret) cs-w (cdr ret))) ((and ret (find-coding-system ret)) (setq cs-r ret cs-w ret)))) (let ((coding-system-for-read (or coding-system-for-read cs-r (car default-network-coding-system) 'undecided)) (coding-system-for-write (or coding-system-for-write cs-w (cdr default-network-coding-system) 'raw-text))) (open-network-stream-internal name buffer host service protocol)))) (defun set-buffer-process-coding-system (decoding encoding) "Set coding systems for the process associated with the current buffer. DECODING is the coding system to be used to decode input from the process, ENCODING is the coding system to be used to encode output to the process. For a list of possible values of CODING-SYSTEM, use \\[coding-system-list]." (interactive "zCoding-system for process input: \nzCoding-system for process output: ") (let ((proc (get-buffer-process (current-buffer)))) (if (null proc) (error "no process") (get-coding-system decoding) (get-coding-system encoding) (set-process-coding-system proc decoding encoding))) (force-mode-line-update)) ;;; code-process.el ends here
