Mercurial > hg > xemacs-beta
annotate src/console-tty.c @ 5353:38e24b8be4ea
Improve the lexical scoping in #'block, #'return-from.
lisp/ChangeLog addition:
2011-02-07 Aidan Kehoe <kehoea@parhasard.net>
* bytecomp.el:
* bytecomp.el (byte-compile-initial-macro-environment):
Shadow `block', `return-from' here, we implement them differently
when byte-compiling.
* bytecomp.el (byte-compile-active-blocks): New.
* bytecomp.el (byte-compile-block-1): New.
* bytecomp.el (byte-compile-return-from-1): New.
* bytecomp.el (return-from-1): New.
* bytecomp.el (block-1): New.
These are two aliases that exist to have their own associated
byte-compile functions, which functions implement `block' and
`return-from'.
* cl-extra.el (cl-macroexpand-all):
Fix a bug here when macros in the environment have been compiled.
* cl-macs.el (block):
* cl-macs.el (return):
* cl-macs.el (return-from):
Be more careful about lexical scope in these macros.
* cl.el:
* cl.el ('cl-block-wrapper): Removed.
* cl.el ('cl-block-throw): Removed.
These aren't needed in code generated by this XEmacs. They
shouldn't be needed in code generated by XEmacs 21.4, but if it
turns out the packages do need them, we can put them back.
2011-01-30 Mike Sperber <mike@xemacs.org>
* font-lock.el (font-lock-fontify-pending-extents): Don't fail if
`font-lock-mode' is unset, which can happen in the middle of
`revert-buffer'.
2011-01-23 Aidan Kehoe <kehoea@parhasard.net>
* cl-macs.el (delete):
* cl-macs.el (delq):
* cl-macs.el (remove):
* cl-macs.el (remq):
Don't use the compiler macro if these functions were given the
wrong number of arguments, as happens in lisp-tests.el.
* cl-seq.el (remove, remq): Removed.
I added these to subr.el, and forgot to remove them from here.
2011-01-22 Aidan Kehoe <kehoea@parhasard.net>
* bytecomp.el (byte-compile-setq, byte-compile-set):
Remove kludge allowing keywords' values to be set, all the code
that does that is gone.
* cl-compat.el (elt-satisfies-test-p):
* faces.el (set-face-parent):
* faces.el (face-doc-string):
* gtk-font-menu.el:
* gtk-font-menu.el (gtk-reset-device-font-menus):
* msw-font-menu.el:
* msw-font-menu.el (mswindows-reset-device-font-menus):
* package-get.el (package-get-installedp):
* select.el (select-convert-from-image-data):
* sound.el:
* sound.el (load-sound-file):
* x-font-menu.el (x-reset-device-font-menus-core):
Don't quote keywords, they're self-quoting, and the
win from backward-compatibility is sufficiently small now that the
style problem overrides it.
2011-01-22 Aidan Kehoe <kehoea@parhasard.net>
* cl-macs.el (block, return-from): Require that NAME be a symbol
in these macros, as always documented in the #'block docstring and
as required by Common Lisp.
* descr-text.el (unidata-initialize-unihan-database):
Correct the use of non-symbols in #'block and #'return-from in
this function.
2011-01-15 Aidan Kehoe <kehoea@parhasard.net>
* cl-extra.el (concatenate): Accept more complicated TYPEs in this
function, handing the sequences over to #'coerce if we don't
understand them here.
* cl-macs.el (inline): Don't proclaim #'concatenate as inline, its
compiler macro is more useful than doing that.
2011-01-11 Aidan Kehoe <kehoea@parhasard.net>
* subr.el (delete, delq, remove, remq): Move #'remove, #'remq
here, they don't belong in cl-seq.el; move #'delete, #'delq here
from fns.c, implement them in terms of #'delete*, allowing support
for sequences generally.
* update-elc.el (do-autoload-commands): Use #'delete*, not #'delq
here, now the latter's no longer dumped.
* cl-macs.el (delete, delq): Add compiler macros transforming
#'delete and #'delq to #'delete* calls.
2011-01-10 Aidan Kehoe <kehoea@parhasard.net>
* dialog.el (make-dialog-box): Correct a misplaced parenthesis
here, thank you Mats Lidell in 87zkr9gqrh.fsf@mail.contactor.se !
2011-01-02 Aidan Kehoe <kehoea@parhasard.net>
* dialog.el (make-dialog-box):
* list-mode.el (display-completion-list):
These functions used to use cl-parsing-keywords; change them to
use defun* instead, fixing the build. (Not sure what led to me
not including this change in d1b17a33450b!)
2011-01-02 Aidan Kehoe <kehoea@parhasard.net>
* cl-macs.el (define-star-compiler-macros):
Make sure the form has ITEM and LIST specified before attempting
to change to calls with explicit tests; necessary for some tests
in lisp-tests.el to compile correctly.
(stable-union, stable-intersection): Add compiler macros for these
functions, in the same way we do for most of the other functions
in cl-seq.el.
2011-01-01 Aidan Kehoe <kehoea@parhasard.net>
* cl-macs.el (dolist, dotimes, do-symbols, macrolet)
(symbol-macrolet):
Define these macros with defmacro* instead of parsing the argument
list by hand, for the sake of style and readability; use backquote
where appropriate, instead of calling #'list and and friends, for
the same reason.
2010-12-30 Aidan Kehoe <kehoea@parhasard.net>
* x-misc.el (device-x-display):
Provide this function, documented in the Lispref for years, but
not existing previously. Thank you Julian Bradfield, thank you
Jeff Mincy.
2010-12-30 Aidan Kehoe <kehoea@parhasard.net>
* cl-seq.el:
Move the heavy lifting from this file to C. Dump the
cl-parsing-keywords macro, but don't use defun* for the functions
we define that do take keywords, dynamic scope lossage makes that
not practical.
* subr.el (sort, fillarray): Move these aliases here.
(map-plist): #'nsublis is now built-in, but at this point #'eql
isn't necessarily available as a test; use #'eq.
* obsolete.el (cl-delete-duplicates): Make this available for old
compiler macros and old code.
(memql): Document that this is equivalent to #'member*, and worse.
* cl.el (adjoin, subst): Removed. These are in C.
2010-12-30 Aidan Kehoe <kehoea@parhasard.net>
* simple.el (assoc-ignore-case): Remove a duplicate definition of
this function (it's already in subr.el).
* iso8859-1.el (char-width):
On non-Mule, make this function equivalent to that produced by
(constantly 1), but preserve its docstring.
* subr.el (subst-char-in-string): Define this in terms of
#'substitute, #'nsubstitute.
(string-width): Define this using #'reduce and #'char-width.
(char-width): Give this a simpler definition, it makes far more
sense to check for mule at load time and redefine, as we do in
iso8859-1.el.
(store-substring): Implement this in terms of #'replace, now
#'replace is cheap.
2010-12-30 Aidan Kehoe <kehoea@parhasard.net>
* update-elc.el (lisp-files-needed-for-byte-compilation)
(lisp-files-needing-early-byte-compilation):
cl-macs belongs in the former, not the latter, it is as
fundamental as bytecomp.el.
2010-12-30 Aidan Kehoe <kehoea@parhasard.net>
* cl.el:
Provde the Common Lisp program-error, type-error as error
symbols. This doesn't nearly go far enough for anyone using the
Common Lisp errors.
2010-12-29 Aidan Kehoe <kehoea@parhasard.net>
* cl-macs.el (delete-duplicates):
If the form has an incorrect number of arguments, don't attempt a
compiler macroexpansion.
2010-12-29 Aidan Kehoe <kehoea@parhasard.net>
* cl-macs.el (cl-safe-expr-p):
Forms that start with the symbol lambda are also safe.
2010-12-29 Aidan Kehoe <kehoea@parhasard.net>
* cl-macs.el (= < > <= >=):
For these functions' compiler macros, the optimisation is safe
even if the first and the last arguments have side effects, since
they're only used the once.
2010-12-29 Aidan Kehoe <kehoea@parhasard.net>
* cl-macs.el (inline-side-effect-free-compiler-macros):
Unroll a loop here at macro-expansion time, so these compiler
macros are compiled. Use #'eql instead of #'eq in a couple of
places for better style.
2010-12-29 Aidan Kehoe <kehoea@parhasard.net>
* cl-extra.el (notany, notevery): Avoid some dynamic scope
stupidity with local variable names in these functions, when they
weren't prefixed with cl-; go into some more detail in the doc
strings.
2010-12-29 Aidan Kehoe <kehoea@parhasard.net>
* byte-optimize.el (side-effect-free-fns): #'remove, #'remq are
free of side-effects.
(side-effect-and-error-free-fns):
Drop dot, dot-marker from the list.
2010-11-17 Aidan Kehoe <kehoea@parhasard.net>
* cl-extra.el (coerce):
In the argument list, name the first argument OBJECT, not X; the
former name was always used in the doc string and is clearer.
Handle vector type specifications which include the length of the
target sequence, error if there's a mismatch.
* cl-macs.el (cl-make-type-test): Handle type specifications
starting with the symbol 'eql.
2010-11-14 Aidan Kehoe <kehoea@parhasard.net>
* cl-macs.el (eql): Don't remove the byte-compile property of this
symbol. That was necessary to override a bug in bytecomp.el where
#'eql was confused with #'eq, which bug we no longer have.
If neither expression is constant, don't attempt to handle the
expression in this compiler macro, leave it to byte-compile-eql,
which produces better code anyway.
* bytecomp.el (eq): #'eql is not the function associated with the
byte-eq byte code.
(byte-compile-eql): Add an explicit compile method for this
function, for cases where the cl-macs compiler macro hasn't
reduced it to #'eq or #'equal.
2010-10-25 Aidan Kehoe <kehoea@parhasard.net>
Add compiler macros and compilation sanity-checking for various
functions that take keywords.
* byte-optimize.el (side-effect-free-fns): #'symbol-value is
side-effect free and not error free.
* bytecomp.el (byte-compile-normal-call): Check keyword argument
lists for sanity; store information about the positions where
keyword arguments start using the new byte-compile-keyword-start
property.
* cl-macs.el (cl-const-expr-val): Take a new optional argument,
cl-not-constant, defaulting to nil, in this function; return it if
the expression is not constant.
(cl-non-fixnum-number-p): Make this into a separate function, we
want to pass it to #'every.
(eql): Use it.
(define-star-compiler-macros): Use the same code to generate the
member*, assoc* and rassoc* compiler macros; special-case some
code in #'add-to-list in subr.el.
(remove, remq): Add compiler macros for these two functions, in
preparation for #'remove being in C.
(define-foo-if-compiler-macros): Transform (remove-if-not ...) calls to
(remove ... :if-not) at compile time, which will be a real win
once the latter is in C.
(define-substitute-if-compiler-macros)
(define-subst-if-compiler-macros): Similarly for these functions.
(delete-duplicates): Change this compiler macro to use
#'plists-equal; if we don't have information about the type of
SEQUENCE at compile time, don't bother attempting to inline the
call, the function will be in C soon enough.
(equalp): Remove an old commented-out compiler macro for this, if
we want to see it it's in version control.
(subst-char-in-string): Transform this to a call to nsubstitute or
nsubstitute, if that is appropriate.
* cl.el (ldiff): Don't call setf here, this makes for a load-time
dependency problem in cl-macs.el
2010-06-14 Stephen J. Turnbull <stephen@xemacs.org>
* term/vt100.el:
Refer to XEmacs, not GNU Emacs, in permissions.
* term/bg-mouse.el:
* term/sup-mouse.el:
Put copyright notice in canonical "Copyright DATE AUTHOR" form.
Refer to XEmacs, not GNU Emacs, in permissions.
* site-load.el:
Add permission boilerplate.
* mule/canna-leim.el:
* alist.el:
Refer to XEmacs, not APEL/this program, in permissions.
* mule/canna-leim.el:
Remove my copyright, I've assigned it to the FSF.
2010-06-14 Stephen J. Turnbull <stephen@xemacs.org>
* gtk.el:
* gtk-widget-accessors.el:
* gtk-package.el:
* gtk-marshal.el:
* gtk-compose.el:
* gnome.el:
Add copyright notice based on internal evidence.
2010-06-14 Stephen J. Turnbull <stephen@xemacs.org>
* easymenu.el: Add reference to COPYING to permission notice.
* gutter.el:
* gutter-items.el:
* menubar-items.el:
Fix typo "Xmacs" in permissions notice.
2010-06-14 Stephen J. Turnbull <stephen@xemacs.org>
* auto-save.el:
* font.el:
* fontconfig.el:
* mule/kinsoku.el:
Add "part of XEmacs" text to permission notice.
2010-10-14 Aidan Kehoe <kehoea@parhasard.net>
* byte-optimize.el (side-effect-free-fns):
* cl-macs.el (remf, getf):
* cl-extra.el (tailp, cl-set-getf, cl-do-remf):
* cl.el (ldiff, endp):
Tighten up Common Lisp compatibility for #'ldiff, #'endp, #'tailp;
add circularity checking for the first two.
#'cl-set-getf and #'cl-do-remf were Lisp implementations of
#'plist-put and #'plist-remprop; change the names to aliases,
changes the macros that use them to using #'plist-put and
#'plist-remprop directly.
2010-10-12 Aidan Kehoe <kehoea@parhasard.net>
* abbrev.el (fundamental-mode-abbrev-table, global-abbrev-table):
Create both these abbrev tables using the usual
#'define-abbrev-table calls, rather than attempting to
special-case them.
* cl-extra.el: Force cl-macs to be loaded here, if cl-extra.el is
being loaded interpreted. Previously other, later files would
redundantly call (load "cl-macs") when interpreted, it's more
reasonable to do it here, once.
* cmdloop.el (read-quoted-char-radix): Use defcustom here, we
don't have any dump-order dependencies that would prevent that.
* custom.el (eval-when-compile): Don't load cl-macs when
interpreted or when byte-compiling, rely on cl-extra.el in the
former case and the appropriate entry in bytecomp-load-hook in the
latter. Get rid of custom-declare-variable-list, we have no
dump-time dependencies that would require it.
* faces.el (eval-when-compile): Don't load cl-macs when
interpreted or when byte-compiling.
* packages.el: Remove some inaccurate comments.
* post-gc.el (cleanup-simple-finalizers): Use #'delete-if-not
here, now the order of preloaded-file-list has been changed to
make it available.
* subr.el (custom-declare-variable-list): Remove. No need for it.
Also remove a stub define-abbrev-table from this file, given the
current order of preloaded-file-list there's no need for it.
2010-10-10 Aidan Kehoe <kehoea@parhasard.net>
* bytecomp.el (byte-compile-constp) Forms quoted with FUNCTION are
also constant.
(byte-compile-initial-macro-environment): In #'the, if FORM is
constant and does not match TYPE, warn at byte-compile time.
2010-10-10 Aidan Kehoe <kehoea@parhasard.net>
* backquote.el (bq-vector-contents, bq-list*): Remove; the former
is equivalent to (append VECTOR nil), the latter to (list* ...).
(bq-process-2): Use (append VECTOR nil) instead of using
#'bq-vector-contents to convert to a list.
(bq-process-1): Now we use list* instead of bq-list
* subr.el (list*): Moved from cl.el, since it is now required to
be available the first time a backquoted form is encountered.
* cl.el (list*): Move to subr.el.
2010-09-16 Aidan Kehoe <kehoea@parhasard.net>
* test-harness.el (Check-Message):
Add an omitted comma here, thank you the buildbot.
2010-09-16 Aidan Kehoe <kehoea@parhasard.net>
* hash-table.el (hash-table-key-list, hash-table-value-list)
(hash-table-key-value-alist, hash-table-key-value-plist):
Remove some useless #'nreverse calls in these files; our hash
tables have no order, it's not helpful to pretend they do.
* behavior.el (read-behavior):
Do the same in this file, in some code evidently copied from
hash-table.el.
2010-09-16 Aidan Kehoe <kehoea@parhasard.net>
* info.el (Info-insert-dir):
* format.el (format-deannotate-region):
* files.el (cd, save-buffers-kill-emacs):
Use #'some, #'every and related functions for applying boolean
operations to lists, instead of rolling our own ones that cons and
don't short-circuit.
2010-09-16 Aidan Kehoe <kehoea@parhasard.net>
* bytecomp.el (byte-compile-initial-macro-environment):
* cl-macs.el (the):
Rephrase the docstring, make its implementation when compiling
files a little nicer.
2010-09-16 Aidan Kehoe <kehoea@parhasard.net>
* descr-text.el (unidata-initialize-unicodedata-database)
(unidata-initialize-unihan-database, describe-char-unicode-data)
(describe-char-unicode-data):
Wrap calls to the database functions with (with-fboundp ...),
avoiding byte compile warnings on builds without support for the
database functions.
(describe-char): (reduce #'max ...), not (apply #'max ...), no
need to cons needlessly.
(describe-char): Remove a redundant lambda wrapping
#'extent-properties.
(describe-char-unicode-data): Call #'nsubst when replacing "" with
nil in the result of #'split-string, instead of consing inside
mapcar.
2010-09-16 Aidan Kehoe <kehoea@parhasard.net>
* x-faces.el (x-available-font-sizes):
* specifier.el (let-specifier):
* package-ui.el (pui-add-required-packages):
* msw-faces.el (mswindows-available-font-sizes):
* modeline.el (modeline-minor-mode-menu):
* minibuf.el (minibuf-directory-files):
Replace the O2N (delq nil (mapcar (lambda (W) (and X Y)) Z)) with
the ON (mapcan (lambda (W) (and X (list Y))) Z) in these files.
2010-09-16 Aidan Kehoe <kehoea@parhasard.net>
* cl-macs.el (= < > <= >=):
When these functions are handed more than two arguments, and those
arguments have no side effects, transform to a series of two
argument calls, avoiding funcall in the byte-compiled code.
* mule/mule-cmds.el (finish-set-language-environment):
Take advantage of this change in a function called 256 times at
startup.
2010-09-16 Aidan Kehoe <kehoea@parhasard.net>
* bytecomp.el (byte-compile-function-form, byte-compile-quote)
(byte-compile-quote-form):
Warn at compile time, and error at runtime, if a (quote ...) or a
(function ...) form attempts to quote more than one object.
2010-09-16 Aidan Kehoe <kehoea@parhasard.net>
* byte-optimize.el (byte-optimize-apply): Transform (apply 'nconc
(mapcar ...)) to (mapcan ...); warn about use of the first idiom.
* update-elc.el (do-autoload-commands):
* packages.el (packages-find-package-library-path):
* frame.el (frame-list):
* extents.el (extent-descendants):
* etags.el (buffer-tag-table-files):
* dumped-lisp.el (preloaded-file-list):
* device.el (device-list):
* bytecomp-runtime.el (proclaim-inline, proclaim-notinline)
Use #'mapcan, not (apply #'nconc (mapcar ...) in all these files.
* bytecomp-runtime.el (eval-when-compile, eval-and-compile):
In passing, mention that these macros also evaluate the body when
interpreted.
tests/ChangeLog addition:
2011-02-07 Aidan Kehoe <kehoea@parhasard.net>
* automated/lisp-tests.el:
Test lexical scope for `block', `return-from'; add a
Known-Bug-Expect-Failure for a contorted example that fails when
byte-compiled.
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Mon, 07 Feb 2011 12:01:24 +0000 |
parents | 71ee43b8a74d |
children | 308d34e9f07d |
rev | line source |
---|---|
428 | 1 /* TTY console functions. |
2 Copyright (C) 1994, 1995 Board of Trustees, University of Illinois. | |
3 Copyright (C) 1994, 1995 Free Software Foundation, Inc. | |
800 | 4 Copyright (C) 1996, 2001, 2002 Ben Wing. |
428 | 5 |
6 This file is part of XEmacs. | |
7 | |
8 XEmacs is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
10 Free Software Foundation; either version 2, or (at your option) any | |
11 later version. | |
12 | |
13 XEmacs is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
19 along with XEmacs; see the file COPYING. If not, write to | |
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
21 Boston, MA 02111-1307, USA. */ | |
22 | |
23 /* Synched up with: Not in FSF. */ | |
24 | |
25 /* Authors: Ben Wing and Chuck Thompson. */ | |
26 | |
27 #include <config.h> | |
28 #include "lisp.h" | |
29 | |
872 | 30 #include "console-tty-impl.h" |
428 | 31 #include "console-stream.h" |
872 | 32 |
2828 | 33 #include "elhash.h" |
428 | 34 #include "faces.h" |
872 | 35 #include "file-coding.h" |
428 | 36 #include "frame.h" |
872 | 37 #include "glyphs.h" |
428 | 38 #include "lstream.h" |
872 | 39 #include "process.h" |
40 | |
428 | 41 #include "sysdep.h" |
42 #include "sysfile.h" | |
43 | |
44 DEFINE_CONSOLE_TYPE (tty); | |
45 DECLARE_IMAGE_INSTANTIATOR_FORMAT (nothing); | |
46 DECLARE_IMAGE_INSTANTIATOR_FORMAT (string); | |
47 DECLARE_IMAGE_INSTANTIATOR_FORMAT (formatted_string); | |
48 DECLARE_IMAGE_INSTANTIATOR_FORMAT (inherit); | |
49 | |
50 Lisp_Object Qterminal_type; | |
51 Lisp_Object Qcontrolling_process; | |
52 | |
2850 | 53 Lisp_Object Vtty_seen_characters; |
2828 | 54 |
1204 | 55 static const struct memory_description tty_console_data_description_1 [] = { |
56 { XD_LISP_OBJECT, offsetof (struct tty_console, terminal_type) }, | |
57 { XD_LISP_OBJECT, offsetof (struct tty_console, instream) }, | |
58 { XD_LISP_OBJECT, offsetof (struct tty_console, outstream) }, | |
59 { XD_END } | |
60 }; | |
61 | |
3092 | 62 #ifdef NEW_GC |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
parents:
4117
diff
changeset
|
63 DEFINE_DUMPABLE_INTERNAL_LISP_OBJECT ("tty-console", tty_console, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
parents:
4117
diff
changeset
|
64 0, tty_console_data_description_1, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
parents:
4117
diff
changeset
|
65 Lisp_Tty_Console); |
3092 | 66 #else /* not NEW_GC */ |
1204 | 67 const struct sized_memory_description tty_console_data_description = { |
68 sizeof (struct tty_console), tty_console_data_description_1 | |
69 }; | |
3092 | 70 #endif /* not NEW_GC */ |
1204 | 71 |
428 | 72 |
73 static void | |
74 allocate_tty_console_struct (struct console *con) | |
75 { | |
76 /* zero out all slots except the lisp ones ... */ | |
3092 | 77 #ifdef NEW_GC |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5125
diff
changeset
|
78 CONSOLE_TTY_DATA (con) = XTTY_CONSOLE (ALLOC_NORMAL_LISP_OBJECT (tty_console)); |
3092 | 79 #else /* not NEW_GC */ |
428 | 80 CONSOLE_TTY_DATA (con) = xnew_and_zero (struct tty_console); |
3092 | 81 #endif /* not NEW_GC */ |
428 | 82 CONSOLE_TTY_DATA (con)->terminal_type = Qnil; |
83 CONSOLE_TTY_DATA (con)->instream = Qnil; | |
84 CONSOLE_TTY_DATA (con)->outstream = Qnil; | |
85 } | |
86 | |
87 static void | |
88 tty_init_console (struct console *con, Lisp_Object props) | |
89 { | |
90 Lisp_Object tty = CONSOLE_CONNECTION (con); | |
91 Lisp_Object terminal_type = Qnil; | |
92 Lisp_Object controlling_process = Qnil; | |
93 struct tty_console *tty_con; | |
94 struct gcpro gcpro1, gcpro2; | |
95 | |
96 GCPRO2 (terminal_type, controlling_process); | |
97 | |
98 terminal_type = Fplist_get (props, Qterminal_type, Qnil); | |
99 controlling_process = Fplist_get (props, Qcontrolling_process, Qnil); | |
100 | |
101 /* Determine the terminal type */ | |
102 | |
103 if (!NILP (terminal_type)) | |
104 CHECK_STRING (terminal_type); | |
105 else | |
106 { | |
867 | 107 Ibyte *temp_type = egetenv ("TERM"); |
428 | 108 |
109 if (!temp_type) | |
110 { | |
563 | 111 invalid_state ("Cannot determine terminal type", Qunbound); |
428 | 112 } |
113 else | |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4117
diff
changeset
|
114 terminal_type = build_istring (temp_type); |
428 | 115 } |
116 | |
117 /* Determine the controlling process */ | |
118 if (!NILP (controlling_process)) | |
119 CHECK_INT (controlling_process); | |
120 | |
121 /* Open the specified console */ | |
122 | |
123 allocate_tty_console_struct (con); | |
124 tty_con = CONSOLE_TTY_DATA (con); | |
125 | |
126 if (internal_equal (tty, Vstdio_str, 0)) | |
127 { | |
128 tty_con->infd = fileno (stdin); | |
129 tty_con->outfd = fileno (stdout); | |
130 tty_con->is_stdio = 1; | |
131 } | |
132 else | |
133 { | |
134 tty_con->infd = tty_con->outfd = | |
771 | 135 qxe_open (XSTRING_DATA (tty), O_RDWR); |
428 | 136 if (tty_con->infd < 0) |
563 | 137 signal_error (Qio_error, "Unable to open tty", tty); |
428 | 138 tty_con->is_stdio = 0; |
139 } | |
140 | |
802 | 141 /* set_descriptor_non_blocking (tty_con->infd); */ |
428 | 142 tty_con->instream = make_filedesc_input_stream (tty_con->infd, 0, -1, 0); |
771 | 143 Lstream_set_buffering (XLSTREAM (tty_con->instream), LSTREAM_UNBUFFERED, 0); |
428 | 144 tty_con->instream = |
771 | 145 make_coding_input_stream (XLSTREAM (tty_con->instream), |
146 get_coding_system_for_text_file (Qkeyboard, 0), | |
814 | 147 CODING_DECODE, |
148 LSTREAM_FL_READ_ONE_BYTE_AT_A_TIME); | |
771 | 149 Lstream_set_buffering (XLSTREAM (tty_con->instream), LSTREAM_UNBUFFERED, 0); |
150 tty_con->outstream = make_filedesc_output_stream (tty_con->outfd, 0, -1, 0); | |
428 | 151 tty_con->outstream = |
771 | 152 make_coding_output_stream (XLSTREAM (tty_con->outstream), |
153 get_coding_system_for_text_file (Qterminal, 0), | |
800 | 154 CODING_ENCODE, 0); |
428 | 155 tty_con->terminal_type = terminal_type; |
156 tty_con->controlling_process = controlling_process; | |
157 | |
3571 | 158 /* Defaults to 1 with Mule, 0 without. In the latter case the attribute is |
159 read-only from Lisp. */ | |
160 tty_con->multiple_width = CONSOLE_TTY_SUPPORTS_MULTIPLE_WIDTH(c); | |
161 | |
428 | 162 if (NILP (CONSOLE_NAME (con))) |
163 CONSOLE_NAME (con) = Ffile_name_nondirectory (tty); | |
164 { | |
442 | 165 pid_t tty_pg; |
166 pid_t controlling_tty_pg; | |
428 | 167 int cfd; |
168 | |
169 /* OK, the only sure-fire way I can think of to determine | |
170 whether a particular TTY is our controlling TTY is to check | |
171 if it has the same foreground process group as our controlling | |
172 TTY. This is OK because a process group can never simultaneously | |
173 be the foreground process group of two TTY's (in that case it | |
174 would have two controlling TTY's, which is not allowed). */ | |
175 | |
176 EMACS_GET_TTY_PROCESS_GROUP (tty_con->infd, &tty_pg); | |
867 | 177 cfd = qxe_open ((Ibyte *) "/dev/tty", O_RDWR, 0); |
428 | 178 EMACS_GET_TTY_PROCESS_GROUP (cfd, &controlling_tty_pg); |
771 | 179 retry_close (cfd); |
428 | 180 if (tty_pg == controlling_tty_pg) |
181 { | |
182 tty_con->controlling_terminal = 1; | |
793 | 183 Vcontrolling_terminal = wrap_console (con); |
428 | 184 munge_tty_process_group (); |
185 } | |
186 else | |
187 tty_con->controlling_terminal = 0; | |
188 } | |
189 | |
190 UNGCPRO; | |
191 } | |
192 | |
193 static void | |
194 tty_mark_console (struct console *con) | |
195 { | |
196 struct tty_console *tty_con = CONSOLE_TTY_DATA (con); | |
197 mark_object (tty_con->terminal_type); | |
198 mark_object (tty_con->instream); | |
199 mark_object (tty_con->outstream); | |
200 } | |
201 | |
202 static int | |
2286 | 203 tty_initially_selected_for_input (struct console *UNUSED (con)) |
428 | 204 { |
205 return 1; | |
206 } | |
207 | |
208 static void | |
209 free_tty_console_struct (struct console *con) | |
210 { | |
211 struct tty_console *tty_con = CONSOLE_TTY_DATA (con); | |
212 if (tty_con) | |
213 { | |
214 if (tty_con->term_entry_buffer) /* allocated in term_init () */ | |
215 { | |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4953
diff
changeset
|
216 xfree (tty_con->term_entry_buffer); |
428 | 217 tty_con->term_entry_buffer = NULL; |
218 } | |
4117 | 219 #ifndef NEW_GC |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4953
diff
changeset
|
220 xfree (tty_con); |
3092 | 221 #endif /* not NEW_GC */ |
428 | 222 CONSOLE_TTY_DATA (con) = NULL; |
223 } | |
224 } | |
225 | |
226 static void | |
227 tty_delete_console (struct console *con) | |
228 { | |
229 Lstream_close (XLSTREAM (CONSOLE_TTY_DATA (con)->instream)); | |
230 Lstream_close (XLSTREAM (CONSOLE_TTY_DATA (con)->outstream)); | |
231 if (!CONSOLE_TTY_DATA (con)->is_stdio) | |
771 | 232 retry_close (CONSOLE_TTY_DATA (con)->infd); |
428 | 233 if (CONSOLE_TTY_DATA (con)->controlling_terminal) |
234 { | |
235 Vcontrolling_terminal = Qnil; | |
236 unmunge_tty_process_group (); | |
237 } | |
238 free_tty_console_struct (con); | |
239 } | |
240 | |
241 | |
242 static struct console * | |
243 decode_tty_console (Lisp_Object console) | |
244 { | |
793 | 245 console = wrap_console (decode_console (console)); |
428 | 246 CHECK_TTY_CONSOLE (console); |
247 return XCONSOLE (console); | |
248 } | |
249 | |
250 DEFUN ("console-tty-terminal-type", Fconsole_tty_terminal_type, | |
251 0, 1, 0, /* | |
252 Return the terminal type of TTY console CONSOLE. | |
253 */ | |
254 (console)) | |
255 { | |
256 return CONSOLE_TTY_DATA (decode_tty_console (console))->terminal_type; | |
257 } | |
258 | |
259 DEFUN ("console-tty-controlling-process", Fconsole_tty_controlling_process, | |
260 0, 1, 0, /* | |
261 Return the controlling process of tty console CONSOLE. | |
262 */ | |
263 (console)) | |
264 { | |
265 return CONSOLE_TTY_DATA (decode_tty_console (console))->controlling_process; | |
266 } | |
267 | |
268 | |
269 DEFUN ("console-tty-input-coding-system", Fconsole_tty_input_coding_system, | |
270 0, 1, 0, /* | |
271 Return the input coding system of tty console CONSOLE. | |
272 */ | |
273 (console)) | |
274 { | |
771 | 275 return coding_stream_detected_coding_system |
428 | 276 (XLSTREAM (CONSOLE_TTY_DATA (decode_tty_console (console))->instream)); |
277 } | |
278 | |
279 DEFUN ("set-console-tty-input-coding-system", Fset_console_tty_input_coding_system, | |
280 0, 2, 0, /* | |
281 Set the input coding system of tty console CONSOLE to CODESYS. | |
282 CONSOLE defaults to the selected console. | |
283 CODESYS defaults to the value of `keyboard-coding-system'. | |
284 */ | |
285 (console, codesys)) | |
286 { | |
771 | 287 set_coding_stream_coding_system |
428 | 288 (XLSTREAM (CONSOLE_TTY_DATA (decode_tty_console (console))->instream), |
771 | 289 get_coding_system_for_text_file (NILP (codesys) ? Qkeyboard : codesys, |
290 0)); | |
428 | 291 return Qnil; |
292 } | |
293 | |
294 DEFUN ("console-tty-output-coding-system", Fconsole_tty_output_coding_system, | |
295 0, 1, 0, /* | |
296 Return TTY CONSOLE's output coding system. | |
297 */ | |
298 (console)) | |
299 { | |
771 | 300 return coding_stream_coding_system |
428 | 301 (XLSTREAM (CONSOLE_TTY_DATA (decode_tty_console (console))->outstream)); |
302 } | |
303 | |
304 DEFUN ("set-console-tty-output-coding-system", Fset_console_tty_output_coding_system, | |
305 0, 2, 0, /* | |
306 Set the coding system of tty output of console CONSOLE to CODESYS. | |
307 CONSOLE defaults to the selected console. | |
308 CODESYS defaults to the value of `terminal-coding-system'. | |
309 */ | |
310 (console, codesys)) | |
311 { | |
771 | 312 set_coding_stream_coding_system |
428 | 313 (XLSTREAM (CONSOLE_TTY_DATA (decode_tty_console (console))->outstream), |
771 | 314 get_coding_system_for_text_file (NILP (codesys) ? Qterminal : codesys, |
315 0)); | |
438 | 316 /* Redraw tty */ |
317 face_property_was_changed (Vdefault_face, Qfont, Qtty); | |
428 | 318 return Qnil; |
319 } | |
320 | |
3571 | 321 DEFUN ("console-tty-multiple-width", Fconsole_tty_multiple_width, |
322 0, 1, 0, /* | |
323 Return whether CONSOLE treats East Asian double-width chars as such. | |
324 | |
325 CONSOLE defaults to the selected console. Without XEmacs support for | |
326 double-width characters, this always gives nil. | |
327 */ | |
328 (console)) | |
329 { | |
330 return CONSOLE_TTY_MULTIPLE_WIDTH (decode_tty_console(console)) | |
331 ? Qt : Qnil; | |
332 } | |
333 | |
334 DEFUN ("set-console-tty-multiple-width", Fset_console_tty_multiple_width, | |
335 0, 2, 0, /* | |
336 Set whether CONSOLE treats East Asian double-width characters as such. | |
337 | |
338 CONSOLE defaults to the selected console, and VALUE defaults to nil. | |
339 Without XEmacs support for double-width characters, this throws an error if | |
340 VALUE is non-nil. | |
341 */ | |
342 (console, value)) | |
343 { | |
344 struct console *c = decode_tty_console (console); | |
345 | |
346 /* So people outside of East Asia can put (set-console-tty-multiple-width | |
347 (selected-console) nil) in their init files, independent of whether | |
348 Mule is enabled. */ | |
349 if (!CONSOLE_TTY_MULTIPLE_WIDTH (c) && NILP(value)) | |
350 { | |
351 return Qnil; | |
352 } | |
353 | |
354 if (!CONSOLE_TTY_SUPPORTS_MULTIPLE_WIDTH (c)) | |
355 { | |
356 invalid_change | |
357 ("No console support for double-width chars", | |
358 Fmake_symbol(CONSOLE_NAME(c))); | |
359 } | |
360 | |
361 CONSOLE_TTY_DATA(c)->multiple_width = NILP(value) ? 0 : 1; | |
362 | |
363 return Qnil; | |
364 } | |
365 | |
440 | 366 /* #### Move this function to lisp */ |
428 | 367 DEFUN ("set-console-tty-coding-system", Fset_console_tty_coding_system, |
368 0, 2, 0, /* | |
369 Set the input and output coding systems of tty console CONSOLE to CODESYS. | |
370 CONSOLE defaults to the selected console. | |
371 If CODESYS is nil, the values of `keyboard-coding-system' and | |
372 `terminal-coding-system' will be used for the input and | |
373 output coding systems of CONSOLE. | |
374 */ | |
375 (console, codesys)) | |
376 { | |
377 Fset_console_tty_input_coding_system (console, codesys); | |
378 Fset_console_tty_output_coding_system (console, codesys); | |
379 return Qnil; | |
380 } | |
381 | |
382 | |
383 Lisp_Object | |
384 tty_semi_canonicalize_console_connection (Lisp_Object connection, | |
578 | 385 Error_Behavior errb) |
428 | 386 { |
387 return stream_semi_canonicalize_console_connection (connection, errb); | |
388 } | |
389 | |
390 Lisp_Object | |
391 tty_canonicalize_console_connection (Lisp_Object connection, | |
578 | 392 Error_Behavior errb) |
428 | 393 { |
394 return stream_canonicalize_console_connection (connection, errb); | |
395 } | |
396 | |
397 Lisp_Object | |
398 tty_semi_canonicalize_device_connection (Lisp_Object connection, | |
578 | 399 Error_Behavior errb) |
428 | 400 { |
401 return stream_semi_canonicalize_console_connection (connection, errb); | |
402 } | |
403 | |
404 Lisp_Object | |
405 tty_canonicalize_device_connection (Lisp_Object connection, | |
578 | 406 Error_Behavior errb) |
428 | 407 { |
408 return stream_canonicalize_console_connection (connection, errb); | |
409 } | |
410 | |
2828 | 411 static Lisp_Object |
412 tty_perhaps_init_unseen_key_defaults (struct console *UNUSED(con), | |
413 Lisp_Object key) | |
414 { | |
415 Ichar val; | |
416 extern Lisp_Object Vcurrent_global_map; | |
417 | |
418 if (SYMBOLP(key)) | |
419 { | |
420 /* We've no idea what to default an unknown symbol to on the TTY. */ | |
421 return Qnil; | |
422 } | |
423 | |
424 CHECK_CHAR(key); | |
425 | |
2850 | 426 if (!(HASH_TABLEP(Vtty_seen_characters))) |
2828 | 427 { |
428 /* All the keysyms we deal with are character objects; therefore, we | |
429 can use eq as the test without worrying. */ | |
2850 | 430 Vtty_seen_characters = make_lisp_hash_table (128, HASH_TABLE_NON_WEAK, |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5127
diff
changeset
|
431 Qeq); |
2828 | 432 } |
433 | |
434 /* Might give the user an opaque error if make_lisp_hash_table fails, | |
435 but it won't crash. */ | |
2850 | 436 CHECK_HASH_TABLE(Vtty_seen_characters); |
2828 | 437 |
438 val = XCHAR(key); | |
439 | |
440 /* Same logic as in x_has_keysym; I'm not convinced it's always sane. */ | |
441 if (val < 0x80) | |
442 { | |
443 return Qnil; | |
444 } | |
445 | |
2850 | 446 if (!NILP(Fgethash(key, Vtty_seen_characters, Qnil))) |
2828 | 447 { |
448 return Qnil; | |
449 } | |
450 | |
451 if (NILP (Flookup_key (Vcurrent_global_map, key, Qnil))) | |
452 { | |
2850 | 453 Fputhash(key, Qt, Vtty_seen_characters); |
2828 | 454 Fdefine_key (Vcurrent_global_map, key, Qself_insert_command); |
455 return Qt; | |
456 } | |
457 | |
458 return Qnil; | |
459 } | |
460 | |
428 | 461 |
462 /************************************************************************/ | |
463 /* initialization */ | |
464 /************************************************************************/ | |
465 | |
466 void | |
467 syms_of_console_tty (void) | |
468 { | |
469 DEFSUBR (Fconsole_tty_terminal_type); | |
470 DEFSUBR (Fconsole_tty_controlling_process); | |
563 | 471 DEFSYMBOL (Qterminal_type); |
472 DEFSYMBOL (Qcontrolling_process); | |
428 | 473 DEFSUBR (Fconsole_tty_output_coding_system); |
474 DEFSUBR (Fset_console_tty_output_coding_system); | |
475 DEFSUBR (Fconsole_tty_input_coding_system); | |
476 DEFSUBR (Fset_console_tty_input_coding_system); | |
477 DEFSUBR (Fset_console_tty_coding_system); | |
3571 | 478 DEFSUBR (Fconsole_tty_multiple_width); |
479 DEFSUBR (Fset_console_tty_multiple_width); | |
428 | 480 } |
481 | |
482 void | |
483 console_type_create_tty (void) | |
484 { | |
485 INITIALIZE_CONSOLE_TYPE (tty, "tty", "console-tty-p"); | |
486 | |
487 /* console methods */ | |
488 CONSOLE_HAS_METHOD (tty, init_console); | |
489 CONSOLE_HAS_METHOD (tty, mark_console); | |
490 CONSOLE_HAS_METHOD (tty, initially_selected_for_input); | |
491 CONSOLE_HAS_METHOD (tty, delete_console); | |
492 CONSOLE_HAS_METHOD (tty, canonicalize_console_connection); | |
493 CONSOLE_HAS_METHOD (tty, canonicalize_device_connection); | |
494 CONSOLE_HAS_METHOD (tty, semi_canonicalize_console_connection); | |
495 CONSOLE_HAS_METHOD (tty, semi_canonicalize_device_connection); | |
2828 | 496 CONSOLE_HAS_METHOD (tty, perhaps_init_unseen_key_defaults); |
428 | 497 } |
498 | |
499 void | |
500 reinit_console_type_create_tty (void) | |
501 { | |
502 REINITIALIZE_CONSOLE_TYPE (tty); | |
503 } | |
504 | |
505 void | |
506 image_instantiator_format_create_glyphs_tty (void) | |
507 { | |
508 IIFORMAT_VALID_CONSOLE (tty, nothing); | |
509 IIFORMAT_VALID_CONSOLE (tty, string); | |
510 IIFORMAT_VALID_CONSOLE (tty, formatted_string); | |
511 IIFORMAT_VALID_CONSOLE (tty, inherit); | |
512 } | |
513 | |
514 void | |
515 vars_of_console_tty (void) | |
516 { | |
2850 | 517 DEFVAR_LISP ("tty-seen-characters", &Vtty_seen_characters /* |
518 Hash table of non-ASCII characters the TTY subsystem has seen. | |
519 */ ); | |
520 Vtty_seen_characters = Qnil; | |
428 | 521 Fprovide (Qtty); |
522 } |