Mercurial > emacs
comparison lisp/frame.el @ 83416:4513d8dcdfd5
Reimplement and extend support for terminal-local environment variables.
* lisp/termdev.el: New file. Move terminal parameter-related functions
here from frame.el.
(terminal-getenv, with-terminal-environment): Reimplement and extend.
(terminal-setenv, terminal-setenv-internal): New functions.
* lisp/frame.el (make-frame-on-tty, framep-on-display, suspend-frame):
Extend doc string, update parameter names.
(terminal-id, terminal-parameter-alist, terminal-parameters)
(terminal-parameter-p, terminal-parameter, set-terminal-parameter)
(terminal-handle-delete-frame, terminal-getenv, terminal-getenv)
(with-terminal-environment): Move to termdev.el.
* lisp/loadup.el: Load termdev as well.
* lisp/Makefile.in (lisp, shortlisp): Add termdev.elc.
* lisp/makefile.MPW (shortlisp): Ditto.
* lisp/ebuff-menu.el (electric-buffer-menu-mode-map): Bind C-z to
`suspend-frame', not `suspend-emacs'.
* lisp/echistory.el (electric-history-map): Ditto.
* lisp/ebrowse.el (ebrowse-electric-list-mode-map): Ditto.
* lisp/ebrowse.el (ebrowse-electric-position-mode-map): Ditto.
* lisp/startup.el (normal-splash-screen): Use `save-buffers-kill-display'
instead of `save-buffers-kill-emacs'.
* lisp/x-win.el (x-initialize-window-system): Add 'global-ok option to
`terminal-getenv'.
* src/term.c (suspend-tty): Update doc string.
git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-456
author | Karoly Lorentey <lorentey@elte.hu> |
---|---|
date | Thu, 22 Dec 2005 21:02:45 +0000 |
parents | 14a4eb789b45 |
children | 2afc49c9f0c0 |
comparison
equal
deleted
inserted
replaced
83415:d2c799f58129 | 83416:4513d8dcdfd5 |
---|---|
596 (when (and (boundp 'x-initialized) (not x-initialized)) | 596 (when (and (boundp 'x-initialized) (not x-initialized)) |
597 (setq x-display-name display) | 597 (setq x-display-name display) |
598 (x-initialize-window-system)) | 598 (x-initialize-window-system)) |
599 (make-frame `((window-system . x) (display . ,display) . ,parameters))) | 599 (make-frame `((window-system . x) (display . ,display) . ,parameters))) |
600 | 600 |
601 (defun make-frame-on-tty (device type &optional parameters) | 601 (defun make-frame-on-tty (tty type &optional parameters) |
602 "Make a frame on terminal DEVICE which is of type TYPE (e.g., \"xterm\"). | 602 "Make a frame on terminal device TTY. |
603 The optional third argument PARAMETERS specifies additional frame parameters." | 603 TTY should be the file name of the tty device to use. TYPE |
604 should be the terminal type string of TTY, for example \"xterm\" | |
605 or \"vt100\". The optional third argument PARAMETERS specifies | |
606 additional frame parameters." | |
604 (interactive "fOpen frame on tty device: \nsTerminal type of %s: ") | 607 (interactive "fOpen frame on tty device: \nsTerminal type of %s: ") |
605 (unless device | 608 (unless tty |
606 (error "Invalid terminal device")) | 609 (error "Invalid terminal device")) |
607 (unless type | 610 (unless type |
608 (error "Invalid terminal type")) | 611 (error "Invalid terminal type")) |
609 (make-frame `((window-system . nil) (tty . ,device) (tty-type . ,type) . ,parameters))) | 612 (make-frame `((window-system . nil) (tty . ,tty) (tty-type . ,type) . ,parameters))) |
610 | 613 |
611 (defun make-frame-command () | 614 (defun make-frame-command () |
612 "Make a new frame, and select it if the terminal displays only one frame." | 615 "Make a new frame, and select it if the terminal displays only one frame." |
613 (interactive) | 616 (interactive) |
614 (if (and window-system (not (eq window-system 'pc))) | 617 (if (and window-system (not (eq window-system 'pc))) |
708 (let* ((terminal (terminal-id terminal)) | 711 (let* ((terminal (terminal-id terminal)) |
709 (func #'(lambda (frame) | 712 (func #'(lambda (frame) |
710 (eq (frame-display frame) terminal)))) | 713 (eq (frame-display frame) terminal)))) |
711 (filtered-frame-list func))) | 714 (filtered-frame-list func))) |
712 | 715 |
713 (defun framep-on-display (&optional display) | 716 (defun framep-on-display (&optional terminal) |
714 "Return the type of frames on DISPLAY. | 717 "Return the type of frames on TERMINAL. |
715 DISPLAY may be a display id, a display name or a frame. If it is | 718 TERMINAL may be a terminal id, a display name or a frame. If it |
716 a frame, its type is returned. | 719 is a frame, its type is returned. If TERMINAL is omitted or nil, |
717 If DISPLAY is omitted or nil, it defaults to the selected frame's display. | 720 it defaults to the selected frame's terminal device. All frames |
718 All frames on a given display are of the same type." | 721 on a given display are of the same type." |
719 (or (display-live-p display) | 722 (or (display-live-p terminal) |
720 (framep display) | 723 (framep terminal) |
721 (framep (car (frames-on-display-list display))))) | 724 (framep (car (frames-on-display-list terminal))))) |
722 | 725 |
723 (defun frame-remove-geometry-params (param-list) | 726 (defun frame-remove-geometry-params (param-list) |
724 "Return the parameter list PARAM-LIST, but with geometry specs removed. | 727 "Return the parameter list PARAM-LIST, but with geometry specs removed. |
725 This deletes all bindings in PARAM-LIST for `top', `left', `width', | 728 This deletes all bindings in PARAM-LIST for `top', `left', `width', |
726 `height', `user-size' and `user-position' parameters. | 729 `height', `user-size' and `user-position' parameters. |
794 (iconify-frame) | 797 (iconify-frame) |
795 (make-frame-visible))) | 798 (make-frame-visible))) |
796 | 799 |
797 (defun suspend-frame () | 800 (defun suspend-frame () |
798 "Do whatever is right to suspend the current frame. | 801 "Do whatever is right to suspend the current frame. |
799 Calls `suspend-emacs' if invoked from the controlling terminal, | 802 Calls `suspend-emacs' if invoked from the controlling tty device, |
800 `suspend-tty' from a secondary terminal, and | 803 `suspend-tty' from a secondary tty device, and |
801 `iconify-or-deiconify-frame' from an X frame." | 804 `iconify-or-deiconify-frame' from an X frame." |
802 (interactive) | 805 (interactive) |
803 (let ((type (framep (selected-frame)))) | 806 (let ((type (framep (selected-frame)))) |
804 (cond | 807 (cond |
805 ((eq type 'x) (iconify-or-deiconify-frame)) | 808 ((eq type 'x) (iconify-or-deiconify-frame)) |
806 ((eq type t) | 809 ((eq type t) |
807 (if (display-controlling-tty-p) | 810 (if (display-controlling-tty-p) |
808 (suspend-emacs) | 811 (suspend-emacs) |
809 (suspend-tty))) | 812 (suspend-tty))) |
810 (t (suspend-emacs))))) | 813 (t (suspend-emacs))))) |
811 | |
812 | 814 |
813 (defun make-frame-names-alist () | 815 (defun make-frame-names-alist () |
814 (let* ((current-frame (selected-frame)) | 816 (let* ((current-frame (selected-frame)) |
815 (falist | 817 (falist |
816 (cons | 818 (cons |
1423 (define-key ctl-x-5-map "2" 'make-frame-command) | 1425 (define-key ctl-x-5-map "2" 'make-frame-command) |
1424 (define-key ctl-x-5-map "1" 'delete-other-frames) | 1426 (define-key ctl-x-5-map "1" 'delete-other-frames) |
1425 (define-key ctl-x-5-map "0" 'delete-frame) | 1427 (define-key ctl-x-5-map "0" 'delete-frame) |
1426 (define-key ctl-x-5-map "o" 'other-frame) | 1428 (define-key ctl-x-5-map "o" 'other-frame) |
1427 | 1429 |
1428 (substitute-key-definition 'suspend-emacs 'suspend-frame global-map) | |
1429 | |
1430 | |
1431 (defun terminal-id (terminal) | |
1432 "Return the numerical id of terminal TERMINAL. | |
1433 | |
1434 TERMINAL can be a terminal id (an integer), a frame, or | |
1435 nil (meaning the selected frame's terminal). Alternatively, | |
1436 TERMINAL may be the name of an X display | |
1437 device (HOST.SERVER.SCREEN) or a tty device file." | |
1438 (cond | |
1439 ((integerp terminal) | |
1440 (if (display-live-p terminal) | |
1441 terminal | |
1442 (signal 'wrong-type-argument (list 'display-live-p terminal)))) | |
1443 ((or (null terminal) (framep terminal)) | |
1444 (frame-display terminal)) | |
1445 ((stringp terminal) | |
1446 (let ((f (car (filtered-frame-list (lambda (frame) | |
1447 (or (equal (frame-parameter frame 'display) terminal) | |
1448 (equal (frame-parameter frame 'tty) terminal))))))) | |
1449 (or f (error "Display %s does not exist" terminal)) | |
1450 (frame-display f))) | |
1451 (t | |
1452 (error "Invalid argument %s in `terminal-id'" terminal)))) | |
1453 | |
1454 (defvar terminal-parameter-alist nil | |
1455 "An alist of terminal parameter alists.") | |
1456 | |
1457 (defun terminal-parameters (&optional terminal) | |
1458 "Return the paramater-alist of terminal TERMINAL. | |
1459 It is a list of elements of the form (PARM . VALUE), where PARM is a symbol. | |
1460 | |
1461 TERMINAL can be a terminal id, a frame, or nil (meaning the | |
1462 selected frame's terminal)." | |
1463 (cdr (assq (terminal-id terminal) terminal-parameter-alist))) | |
1464 | |
1465 (defun terminal-parameter-p (terminal parameter) | |
1466 "Return non-nil if PARAMETER is a terminal parameter on TERMINAL. | |
1467 | |
1468 The actual value returned in that case is a cell (PARAMETER . VALUE), | |
1469 where VALUE is the current value of PARAMETER. | |
1470 | |
1471 TERMINAL can be a terminal id, a frame, or nil (meaning the | |
1472 selected frame's terminal)." | |
1473 (assq parameter (cdr (assq (terminal-id terminal) terminal-parameter-alist)))) | |
1474 | |
1475 (defun terminal-parameter (terminal parameter) | |
1476 "Return TERMINAL's value for parameter PARAMETER. | |
1477 | |
1478 TERMINAL can be a terminal id, a frame, or nil (meaning the | |
1479 selected frame's terminal)." | |
1480 (cdr (terminal-parameter-p terminal parameter))) | |
1481 | |
1482 (defun set-terminal-parameter (terminal parameter value) | |
1483 "Set TERMINAL's value for parameter PARAMETER to VALUE. | |
1484 Returns the previous value of PARAMETER. | |
1485 | |
1486 TERMINAL can be a terminal id, a frame, or nil (meaning the | |
1487 selected frame's terminal)." | |
1488 (setq terminal (terminal-id terminal)) | |
1489 (let* ((alist (assq terminal terminal-parameter-alist)) | |
1490 (pair (assq parameter (cdr alist))) | |
1491 (result (cdr pair))) | |
1492 (cond | |
1493 (pair (setcdr pair value)) | |
1494 (alist (setcdr alist (cons (cons parameter value) (cdr alist)))) | |
1495 (t (setq terminal-parameter-alist | |
1496 (cons (cons terminal | |
1497 (cons (cons parameter value) | |
1498 nil)) | |
1499 terminal-parameter-alist)))) | |
1500 result)) | |
1501 | |
1502 (defun terminal-handle-delete-frame (frame) | |
1503 "Clean up terminal parameters of FRAME, if it's the last frame on its terminal." | |
1504 ;; XXX We assume that the display is closed immediately after the | |
1505 ;; last frame is deleted on it. It would be better to create a hook | |
1506 ;; called `delete-display-functions', and use it instead. | |
1507 (when (and (frame-live-p frame) | |
1508 (= 1 (length (frames-on-display-list (frame-display frame))))) | |
1509 (setq terminal-parameter-alist | |
1510 (assq-delete-all (frame-display frame) terminal-parameter-alist)))) | |
1511 | |
1512 (add-hook 'delete-frame-functions 'terminal-handle-delete-frame) | |
1513 | |
1514 (defun terminal-getenv (variable &optional terminal) | |
1515 "Get the value of VARIABLE in the client environment of TERMINAL. | |
1516 VARIABLE should be a string. Value is nil if VARIABLE is undefined in | |
1517 the environment. Otherwise, value is a string. | |
1518 | |
1519 If TERMINAL was created by an emacsclient invocation, then the | |
1520 variable is looked up in the environment of the emacsclient | |
1521 process; otherwise the function consults the environment of the | |
1522 Emacs process. | |
1523 | |
1524 TERMINAL can be a terminal id, a frame, or nil (meaning the | |
1525 selected frame's terminal)." | |
1526 (setq terminal (terminal-id terminal)) | |
1527 (if (not (terminal-parameter-p terminal 'environment)) | |
1528 (getenv variable) | |
1529 (let ((env (terminal-parameter terminal 'environment)) | |
1530 result entry) | |
1531 (while (and env (null result)) | |
1532 (setq entry (car env) | |
1533 env (cdr env)) | |
1534 (if (and (> (length entry) (length variable)) | |
1535 (eq ?= (aref entry (length variable))) | |
1536 (equal variable (substring entry 0 (length variable)))) | |
1537 (setq result (substring entry (+ (length variable) 1))))) | |
1538 (if (null result) | |
1539 (getenv variable) | |
1540 result)))) | |
1541 | |
1542 (defmacro with-terminal-environment (terminal vars &rest body) | |
1543 "Evaluate BODY with environment variables VARS set to those of TERMINAL. | |
1544 The environment variables are then restored to their previous values. | |
1545 | |
1546 VARS should be a list of strings. | |
1547 | |
1548 TERMINAL can be a terminal id, a frame, or nil (meaning the | |
1549 selected frame's terminal). | |
1550 | |
1551 See also `terminal-getenv'." | |
1552 (declare (indent 2)) | |
1553 (let ((oldvalues (make-symbol "oldvalues")) | |
1554 (var (make-symbol "var")) | |
1555 (value (make-symbol "value")) | |
1556 (pair (make-symbol "pair"))) | |
1557 `(let (,oldvalues) | |
1558 (dolist (,var ,vars) | |
1559 (let ((,value (terminal-getenv ,var ,terminal))) | |
1560 (setq ,oldvalues (cons (cons ,var (getenv ,var)) ,oldvalues)) | |
1561 (setenv ,var ,value))) | |
1562 (unwind-protect | |
1563 (progn ,@body) | |
1564 (dolist (,pair ,oldvalues) | |
1565 (setenv (car ,pair) (cdr ,pair))))))) | |
1566 | |
1567 | |
1568 (provide 'frame) | 1430 (provide 'frame) |
1569 | 1431 |
1570 ;; arch-tag: 82979c70-b8f2-4306-b2ad-ddbd6b328b56 | 1432 ;; arch-tag: 82979c70-b8f2-4306-b2ad-ddbd6b328b56 |
1571 ;;; frame.el ends here | 1433 ;;; frame.el ends here |