Commit 4400e764 authored by Karoly Lorentey's avatar Karoly Lorentey
Browse files

Implement rudimentary Lisp-level terminal parameters.

* lisp/frame.el (terminal-id, terminal-parameters, terminal-parameter) 
  (set-terminal-parameter, terminal-handle-delete-frame): New functions.
  (delete-frame-functions): Add to `delete-frame-functions' hook.
  (terminal-parameter-alist): New variable.

* lisp/international/encoded-kb.el (saved-input-mode): Delete variable.
  (encoded-kbd-setup-display): Store the saved input method as a terminal

parent d5dc9206
......@@ -355,6 +355,9 @@ For the NEWS file: (Needs much, much work)
*** New functions: frame-tty-name, frame-tty-type, delete-tty,
terminal-local-value, set-terminal-local-value
terminal-id, terminal-parameters, terminal-parameter,
*** New variables: global-key-translation-map
*** The keymaps key-translation-map and function-key-map are now
......@@ -382,6 +385,23 @@ is probably not very interesting for anyone else.)
** The handling of lisp/term/*.el, and frame creation in general, is a
big, big mess. How come the terminal-specific file is loaded by
tty-create-frame-with-faces? I don't think it is necessary to load
these files for each frame; once per terminal should be enough.
** Fix frame-set-background-mode in this branch. It was recently
changed in CVS, and frame.el in multi-tty has not yet been adapted
for the changes. (It needs to look at
** I think `(set-)terminal-local-value' and the terminal parameter
mechanism should be integrated into a single framework.
** Add the following hooks: after-delete-frame-hook (for server.el,
instead of delete-frame-functions),
after-delete-terminal-functions, after-create-terminal-functions.
** Having {reset,init}_all_sys_modes in set-input-mode breaks arrow
keys on non-selected terminals under screen, and sometimes on other
terminal types as well. The other function keys continue to work
......@@ -1427,6 +1427,69 @@ Use Custom to set this variable to get the display updated."
(substitute-key-definition 'suspend-emacs 'suspend-frame global-map)
(defun terminal-id (terminal)
"Return the numerical id of terminal TERMINAL.
TERMINAL can be a terminal id, a frame, or nil (meaning the
selected frame's terminal)."
((integerp terminal)
((or (null terminal) (framep terminal))
(frame-display terminal))
(error "Invalid argument %s in `terminal-id'" terminal))))
(defvar terminal-parameter-alist nil
"An alist of terminal parameter alists.")
(defun terminal-parameters (&optional terminal)
"Return the paramater-alist of terminal TERMINAL.
It is a list of elements of the form (PARM . VALUE), where PARM is a symbol.
TERMINAL can be a terminal id, a frame, or nil (meaning the
selected frame's terminal)."
(cdr (assq (terminal-id terminal) terminal-parameter-alist)))
(defun terminal-parameter (terminal parameter)
"Return TERMINAL's value for parameter PARAMETER.
TERMINAL can be a terminal id, a frame, or nil (meaning the
selected frame's terminal)."
(cdr (assq parameter (cdr (assq (terminal-id terminal) terminal-parameter-alist)))))
(defun set-terminal-parameter (terminal parameter value)
"Set TERMINAL's value for parameter PARAMETER to VALUE.
Returns the previous value of PARAMETER.
TERMINAL can be a terminal id, a frame, or nil (meaning the
selected frame's terminal)."
(setq terminal (terminal-id terminal))
(let* ((alist (assq terminal terminal-parameter-alist))
(pair (assq parameter (cdr alist)))
(result (cdr pair)))
(pair (setcdr pair value))
(alist (setcdr alist (cons (cons parameter value) (cdr alist))))
(t (setq terminal-parameter-alist
(cons (cons terminal
(cons (cons parameter value)
(defun terminal-handle-delete-frame (frame)
"Clean up terminal parameters of FRAME, if it's the last frame on its terminal."
;; XXX We assume that the display is closed immediately after the
;; last frame is deleted on it. It would be better to create a hook
;; called `delete-display-functions', and use it instead.
(when (= 1 (length (frames-on-display-list (frame-display frame))))
(setq terminal-parameter-alist
(assq-delete-all (frame-display frame) terminal-parameter-alist))))
(add-hook 'delete-frame-functions 'terminal-handle-delete-frame)
(provide 'frame)
;; arch-tag: 82979c70-b8f2-4306-b2ad-ddbd6b328b56
......@@ -251,10 +251,6 @@ The following key sequence may cause multilingual text insertion."
;; Input mode at the time Encoded-kbd mode is turned on is saved here.
;; XXX This should be made display-local somehow.
(defvar saved-input-mode nil)
(defun encoded-kbd-setup-display (display)
"Set up a `key-translation-map' for `keyboard-coding-system' on DISPLAY.
......@@ -276,26 +272,29 @@ DISPLAY may be a display id, a frame, or nil for the selected frame's display."
;; We are turning on Encoded-kbd mode.
(let ((coding (keyboard-coding-system))
(keymap (make-sparse-keymap "encoded-kb"))
(cim (current-input-mode))
(set-keymap-parent keymap (terminal-local-value 'key-translation-map frame))
(set-terminal-local-value 'key-translation-map frame keymap)
(or saved-input-mode
(setq saved-input-mode (current-input-mode)))
(or (terminal-parameter nil 'encoded-kbd-saved-input-mode)
(set-terminal-parameter nil 'encoded-kbd-saved-input-mode cim))
(setq result (and coding (encoded-kbd-setup-keymap keymap coding)))
(if result
(if (eq result 8)
(nth 0 saved-input-mode)
(nth 1 saved-input-mode)
(nth 3 saved-input-mode)))
(setq saved-input-mode nil)
(when (and (eq result 8)
(not (memq (nth 2 cim) '(t nil))))
(nth 0 cim)
(nth 1 cim)
(nth 3 cim)))
(set-terminal-local-value nil 'encoded-kbd-saved-input-mode nil)
(error "Unsupported coding system in Encoded-kbd mode: %S"
;; We are turning off Encoded-kbd mode.
(and saved-input-mode
(apply 'set-input-mode saved-input-mode))
(setq saved-input-mode nil))))))
(unless (equal (current-input-mode)
(terminal-parameter nil 'encoded-kbd-saved-input-mode))
(apply 'set-input-mode (terminal-parameter nil 'encoded-kbd-saved-input-mode)))
(set-terminal-parameter nil 'saved-input-mode nil))))))
(provide 'encoded-kb)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment