;;; xterm.el --- define function key sequences and standard colors for xterm -*- lexical-binding: t -*-
-;; Copyright (C) 1995, 2001-2015 Free Software Foundation, Inc.
+;; Copyright (C) 1995, 2001-2016 Free Software Foundation, Inc.
;; Author: FSF
;; Keywords: terminals
If you select a region larger than this size, it won't be copied to your system
clipboard. Since clipboard data is base 64 encoded, the actual number of
string bytes that can be copied is 3/4 of this value."
+ :version "25.1"
:type 'integer)
(defconst xterm-paste-ending-sequence "\e[201~"
(define-key map [f59] [M-f11])
(define-key map [f60] [M-f12])
+ (define-key map [f61] [M-S-f1])
+ (define-key map [f62] [M-S-f2])
+ (define-key map [f63] [M-S-f3])
+ (define-key map [f64] [M-S-f4])
+ (define-key map [f65] [M-S-f5])
+ (define-key map [f66] [M-S-f6])
+ (define-key map [f67] [M-S-f7])
+ (define-key map [f68] [M-S-f8])
+ (define-key map [f69] [M-S-f9])
+ (define-key map [f70] [M-S-f10])
+ (define-key map [f71] [M-S-f11])
+ (define-key map [f72] [M-S-f12])
+
map)
"Keymap of possible alternative meanings for some keys.")
;;(xterm--init-activate-get-selection)
(xterm--init-activate-set-selection))))))
+(defvar xterm-query-timeout 2
+ "Seconds to wait for an answer from the terminal.
+Can be nil to mean \"no timeout\".")
+
(defun xterm--query (query handlers &optional no-async)
"Send QUERY string to the terminal and watch for a response.
HANDLERS is an alist with elements of the form (STRING . FUNCTION).
;; rather annoying (bug#6758). Maybe we could always use the asynchronous
;; approach, but it's less tested.
;; FIXME: Merge the two branches.
- (if (and (input-pending-p) (not no-async))
- (progn
- (dolist (handler handlers)
- (define-key input-decode-map (car handler)
- (lambda (&optional _prompt)
- ;; Unregister the handler, since we don't expect further answers.
- (dolist (handler handlers)
- (define-key input-decode-map (car handler) nil))
- (funcall (cdr handler))
- [])))
- (send-string-to-terminal query))
- ;; Pending input can be mistakenly returned by the calls to
- ;; read-event below. Discard it.
- (send-string-to-terminal query)
- (while handlers
- (let ((handler (pop handlers))
- (i 0))
- (while (and (< i (length (car handler)))
- (let ((evt (read-event nil nil 2)))
- (or (eq evt (aref (car handler) i))
- (progn (if evt (push evt unread-command-events))
- nil))))
- (setq i (1+ i)))
- (if (= i (length (car handler)))
- (progn (setq handlers nil)
- (funcall (cdr handler)))
- (while (> i 0)
- (push (aref (car handler) (setq i (1- i)))
- unread-command-events)))))))
+ (let ((register
+ (lambda (handlers)
+ (dolist (handler handlers)
+ (define-key input-decode-map (car handler)
+ (lambda (&optional _prompt)
+ ;; Unregister the handler, since we don't expect
+ ;; further answers.
+ (dolist (handler handlers)
+ (define-key input-decode-map (car handler) nil))
+ (funcall (cdr handler))
+ []))))))
+ (if (and (or (null xterm-query-timeout) (input-pending-p))
+ (not no-async))
+ (progn
+ (funcall register handlers)
+ (send-string-to-terminal query))
+ ;; Pending input can be mistakenly returned by the calls to
+ ;; read-event below: discard it.
+ (discard-input)
+ (send-string-to-terminal query)
+ (while handlers
+ (let ((handler (pop handlers))
+ (i 0))
+ (while (and (< i (length (car handler)))
+ (let ((evt (read-event nil nil xterm-query-timeout)))
+ (if (and (null evt) (= i 0) (not no-async))
+ ;; Timeout on the first event: fallback on async.
+ (progn
+ (funcall register (cons handler handlers))
+ (setq handlers nil)
+ nil)
+ (or (eq evt (aref (car handler) i))
+ (progn (if evt (push evt unread-command-events))
+ nil)))))
+ (setq i (1+ i)))
+ (if (= i (length (car handler)))
+ (progn (setq handlers nil)
+ (funcall (cdr handler)))
+ (while (> i 0)
+ (push (aref (car handler) (setq i (1- i)))
+ unread-command-events))))))))
(defun xterm--push-map (map basemap)
;; Use inheritance to let the main keymaps override those defaults.
(cl-defmethod gui-backend-get-selection
(type data-type
- &context (window-system (eql nil))
+ &context (window-system nil)
;; Only applies to terminals which have it enabled.
((terminal-parameter nil 'xterm--get-selection) (eql t)))
(unless (eq data-type 'STRING)
(cl-defmethod gui-backend-set-selection
(type data
- &context (window-system (eql nil))
+ &context (window-system nil)
;; Only applies to terminals which have it enabled.
((terminal-parameter nil 'xterm--set-selection) (eql t)))
"Copy DATA to the X selection using the OSC 52 escape sequence.