diff lisp/term/common-win.el @ 111166:6cf6c01cf9bf

Move some more shared x-, w32- things to common-win. * term/ns-win.el (x-select-text): Doc fix. * w32-fns.el (x-alternatives-map, x-setup-function-keys) (x-select-text): Move to term/common-win. * term/w32-win.el (xw-defined-colors): Move to common-win. * term/x-win.el (xw-defined-colors, x-alternatives-map) (x-setup-function-keys, x-select-text): Move to common-win. * term/common-win.el (x-select-text, x-alternatives-map) (x-setup-function-keys, xw-defined-colors): Merge x- and w32- definitions here.
author Glenn Morris <rgm@gnu.org>
date Sun, 24 Oct 2010 15:04:45 -0700
parents a3c68a313b81
children f900266d10a0
line wrap: on
line diff
--- a/lisp/term/common-win.el	Sun Oct 24 17:44:53 2010 -0400
+++ b/lisp/term/common-win.el	Sun Oct 24 15:04:45 2010 -0700
@@ -37,6 +37,67 @@
   ;; The GNU/Linux version changed in 24.1, the MS-Windows version did not.
   :version "24.1")
 
+(defvar x-last-selected-text)		; w32-fns.el
+(declare-function w32-set-clipboard-data "w32select.c"
+		  (string &optional ignored))
+
+(defun x-select-text (text)
+  "Select TEXT, a string, according to the window system.
+
+On X, if `x-select-enable-clipboard' is non-nil, copy TEXT to the
+clipboard.  If `x-select-enable-primary' is non-nil, put TEXT in
+the primary selection.
+
+On MS-Windows, make TEXT the current selection.  If
+`x-select-enable-clipboard' is non-nil, copy the text to the
+clipboard as well.
+
+On Nextstep, put TEXT in the pasteboard."
+  (if (eq system-type 'windows-nt)
+      (progn
+	(if x-select-enable-clipboard
+	    (w32-set-clipboard-data text))
+	(setq x-last-selected-text text))
+    ;; With multi-tty, this function may be called from a tty frame.
+    (when (eq (framep (selected-frame)) 'x)
+      (when x-select-enable-primary
+	(x-set-selection 'PRIMARY text)
+	(setq x-last-selected-text-primary text))
+      (when x-select-enable-clipboard
+	(x-set-selection 'CLIPBOARD text)
+	(setq x-last-selected-text-clipboard text)))))
+
+;;;; Function keys
+
+(defvar x-alternatives-map
+  (let ((map (make-sparse-keymap)))
+    ;; Map certain keypad keys into ASCII characters that people usually expect.
+    (define-key map [M-backspace] [?\M-\d])
+    (define-key map [M-delete] [?\M-\d])
+    (define-key map [M-tab] [?\M-\t])
+    (define-key map [M-linefeed] [?\M-\n])
+    (define-key map [M-clear] [?\M-\C-l])
+    (define-key map [M-return] [?\M-\C-m])
+    (define-key map [M-escape] [?\M-\e])
+    (define-key map [iso-lefttab] [backtab])
+    (define-key map [S-iso-lefttab] [backtab])
+    (and (eq system-type 'windows-nt)
+	 (define-key map [S-tab] [backtab]))
+    map)
+  "Keymap of possible alternative meanings for some keys.")
+
+(defun x-setup-function-keys (frame)
+  "Set up `function-key-map' on the graphical frame FRAME."
+  ;; Don't do this twice on the same display, or it would break
+  ;; normal-erase-is-backspace-mode.
+  (unless (terminal-parameter frame 'x-setup-function-keys)
+    ;; Map certain keypad keys into ASCII characters that people usually expect.
+    (with-selected-frame frame
+      (let ((map (copy-keymap x-alternatives-map)))
+        (set-keymap-parent map (keymap-parent local-function-key-map))
+        (set-keymap-parent local-function-key-map map)))
+    (set-terminal-parameter frame 'x-setup-function-keys t)))
+
 (defvar x-invocation-args)
 
 (defvar x-command-line-resources nil)
@@ -382,4 +443,17 @@
 For Nextstep, this is a list of non-PANTONE colors returned by
 the operating system.")
 
+(defvar w32-color-map)
+
+(defun xw-defined-colors (&optional frame)
+  "Internal function called by `defined-colors', which see."
+  (or frame (setq frame (selected-frame)))
+  (let (defined-colors)
+    (dolist (this-color (if (eq system-type 'windows-nt)
+			    (or (mapcar 'car w32-color-map) x-colors)
+			  x-colors))
+      (and (color-supported-p this-color frame t)
+	   (setq defined-colors (cons this-color defined-colors))))
+    defined-colors))
+
 ;;; common-win.el ends here