Merged from miles@gnu.org--gnu-2005 (patch 142-148, 615-628)
[bpt/emacs.git] / lisp / term / x-win.el
index 76f0e5a..af168eb 100644 (file)
@@ -1,6 +1,7 @@
 ;;; x-win.el --- parse relevant switches and set up for X  -*-coding: iso-2022-7bit;-*-
 
-;; Copyright (C) 1993, 1994, 2001, 2002 Free Software Foundation, Inc.
+;; Copyright (C) 1993, 1994, 2001, 2002, 2003, 2004,
+;;   2005 Free Software Foundation, Inc.
 
 ;; Author: FSF
 ;; Keywords: terminals, i18n
@@ -19,8 +20,8 @@
 
 ;; You should have received a copy of the GNU General Public License
 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
 
 ;;; Commentary:
 
@@ -59,8 +60,6 @@
 ;; -font               *font
 ;; -foreground         *foreground
 ;; -geometry           .geometry
-;; -i                  .iconType
-;; -itype              .iconType
 ;; -iconic             .iconic
 ;; -name               .name
 ;; -reverse            *reverseVideo
 (require 'menu-bar)
 (require 'fontset)
 (require 'x-dnd)
-
-(eval-when-compile (require 'server))
+(require 'server)
 
 (defvar x-invocation-args)
+(defvar x-keysym-table)
+(defvar x-selection-timeout)
+(defvar x-session-id)
+(defvar x-session-previous-id)
 
 (defvar x-command-line-resources nil)
 
        (let ((param (nth 3 aelt)))
          (setq default-frame-alist
                (cons (cons param
-                           (string-to-int (car x-invocation-args)))
+                           (string-to-number (car x-invocation-args)))
                      default-frame-alist)
                x-invocation-args
                (cdr x-invocation-args))))))
@@ -1168,24 +1170,26 @@ XConsortium: rgb.txt,v 10.41 94/02/20 18:39:36 rws Exp")
 \f
 ;;;; Function keys
 
-;; Map certain keypad keys into ASCII characters
-;; that people usually expect.
-(define-key function-key-map [backspace] [127])
-(define-key function-key-map [delete] [127])
-(define-key function-key-map [tab] [?\t])
-(define-key function-key-map [linefeed] [?\n])
-(define-key function-key-map [clear] [?\C-l])
-(define-key function-key-map [return] [?\C-m])
-(define-key function-key-map [escape] [?\e])
-(define-key function-key-map [M-backspace] [?\M-\d])
-(define-key function-key-map [M-delete] [?\M-\d])
-(define-key function-key-map [M-tab] [?\M-\t])
-(define-key function-key-map [M-linefeed] [?\M-\n])
-(define-key function-key-map [M-clear] [?\M-\C-l])
-(define-key function-key-map [M-return] [?\M-\C-m])
-(define-key function-key-map [M-escape] [?\M-\e])
-(define-key function-key-map [iso-lefttab] [backtab])
-(define-key function-key-map [S-iso-lefttab] [backtab])
+(defun x-setup-function-keys (frame)
+  "Set up `function-key-map' on FRAME for the X window system."
+  ;; Map certain keypad keys into ASCII characters that people usually expect.
+  (with-selected-frame frame
+    (define-key local-function-key-map [backspace] [127])
+    (define-key local-function-key-map [delete] [127])
+    (define-key local-function-key-map [tab] [?\t])
+    (define-key local-function-key-map [linefeed] [?\n])
+    (define-key local-function-key-map [clear] [?\C-l])
+    (define-key local-function-key-map [return] [?\C-m])
+    (define-key local-function-key-map [escape] [?\e])
+    (define-key local-function-key-map [M-backspace] [?\M-\d])
+    (define-key local-function-key-map [M-delete] [?\M-\d])
+    (define-key local-function-key-map [M-tab] [?\M-\t])
+    (define-key local-function-key-map [M-linefeed] [?\M-\n])
+    (define-key local-function-key-map [M-clear] [?\M-\C-l])
+    (define-key local-function-key-map [M-return] [?\M-\C-m])
+    (define-key local-function-key-map [M-escape] [?\M-\e])
+    (define-key local-function-key-map [iso-lefttab] [backtab])
+    (define-key local-function-key-map [S-iso-lefttab] [backtab])))
 
 ;; These tell read-char how to convert
 ;; these special chars to ASCII.
@@ -1509,6 +1513,36 @@ as returned by `x-server-vendor'."
        (#x5f1 . ?\e,Gq\e(B)
        (#x5f2 . ?\e,Gr\e(B)
        ;; Cyrillic
+       (#x680 . ?\e$,1)R\e(B)
+       (#x681 . ?\e$,1)V\e(B)
+       (#x682 . ?\e$,1)Z\e(B)
+       (#x683 . ?\e$,1)\\e(B)
+       (#x684 . ?\e$,1)b\e(B)
+       (#x685 . ?\e$,1)n\e(B)
+       (#x686 . ?\e$,1)p\e(B)
+       (#x687 . ?\e$,1)r\e(B)
+       (#x688 . ?\e$,1)v\e(B)
+       (#x689 . ?\e$,1)x\e(B)
+       (#x68a . ?\e$,1)z\e(B)
+       (#x68c . ?\e$,1*8\e(B)
+       (#x68d . ?\e$,1*B\e(B)
+       (#x68e . ?\e$,1*H\e(B)
+       (#x68f . ?\e$,1*N\e(B)
+       (#x690 . ?\e$,1)S\e(B)
+       (#x691 . ?\e$,1)W\e(B)
+       (#x692 . ?\e$,1)[\e(B)
+       (#x693 . ?\e$,1)]\e(B)
+       (#x694 . ?\e$,1)c\e(B)
+       (#x695 . ?\e$,1)o\e(B)
+       (#x696 . ?\e$,1)q\e(B)
+       (#x697 . ?\e$,1)s\e(B)
+       (#x698 . ?\e$,1)w\e(B)
+       (#x699 . ?\e$,1)y\e(B)
+       (#x69a . ?\e$,1){\e(B)
+       (#x69c . ?\e$,1*9\e(B)
+       (#x69d . ?\e$,1*C\e(B)
+       (#x69e . ?\e$,1*I\e(B)
+       (#x69f . ?\e$,1*O\e(B)
        (#x6a1 . ?\e,Lr\e(B)
        (#x6a2 . ?\e,Ls\e(B)
        (#x6a3 . ?\e,Lq\e(B)
@@ -2101,7 +2135,11 @@ pasted text.")
   "The value of the PRIMARY X selection last time we selected or
 pasted text.")
 (defvar x-last-selected-text-cut nil
-  "The value of the X cut buffer last time we selected or pasted text.")
+  "The value of the X cut buffer last time we selected or pasted text.
+The actual text stored in the X cut buffer is what encoded from this value.")
+(defvar x-last-selected-text-cut-encoded nil
+  "The value of the X cut buffer last time we selected or pasted text.
+This is the actual text stored in the X cut buffer.")
 
 ;;; It is said that overlarge strings are slow to put into the cut buffer.
 ;;; Note this value is overridden below.
@@ -2124,19 +2162,14 @@ This is in addition to, but in preference to, the primary selection."
   ;; It becomes slow, and if really big it causes errors.
   (cond ((>= (length text) x-cut-buffer-max)
         (x-set-cut-buffer "" push)
-        (setq x-last-selected-text-cut ""))
-       ;; Don't store a multibyte string that contains
-       ;; eight-bit-control/graphic chars because they can't be
-       ;; restored correctly by x-get-cut-buffer.
-       ((and (multibyte-string-p text)
-             (let ((charsets (find-charset-string text)))
-               (or (memq 'eight-bit-control charsets)
-                   (memq 'eight-bit-graphic charsets))))
-        (x-set-cut-buffer "" push)
-        (setq x-last-selected-text-cut ""))
+        (setq x-last-selected-text-cut ""
+              x-last-selected-text-cut-encoded ""))
        (t
-        (x-set-cut-buffer text push)
-        (setq x-last-selected-text-cut text)))
+        (setq x-last-selected-text-cut text
+              x-last-selected-text-cut-encoded
+              (encode-coding-string text (or locale-coding-system
+                                             'iso-latin-1)))
+        (x-set-cut-buffer x-last-selected-text-cut-encoded push)))
   (x-set-selection 'PRIMARY text)
   (setq x-last-selected-text-primary text)
   (when x-select-enable-clipboard
@@ -2189,6 +2222,11 @@ order until succeed.")
            ctext
          utf8)))))
 
+;; Get a selection value of type TYPE by calling x-get-selection with
+;; an appropiate DATA-TYPE argument decidd by `x-select-request-type'.
+;; The return value is already decoded.  If x-get-selection causes an
+;; error, this function return nil.
+
 (defun x-selection-value (type)
   (let (text)
     (cond ((null x-select-request-type)
@@ -2296,17 +2334,23 @@ order until succeed.")
     ;; from what we remebered them to be last time we did a
     ;; cut/paste operation.
     (setq cut-text
-         (cond;; check primary selection
+         (cond;; check cut buffer
           ((or (not cut-text) (string= cut-text ""))
            (setq x-last-selected-text-cut nil))
-          ((eq      cut-text x-last-selected-text-cut) nil)
-          ((string= cut-text x-last-selected-text-cut)
+          ;; This short cut doesn't work because x-get-cut-buffer
+          ;; always returns a newly created string.
+          ;; ((eq      cut-text x-last-selected-text-cut) nil)
+          ((string= cut-text x-last-selected-text-cut-encoded)
+           ;; See the comment above.  No need of this recording.
            ;; Record the newer string,
            ;; so subsequent calls can use the `eq' test.
-           (setq x-last-selected-text-cut cut-text)
-      nil)
-     (t
-           (setq x-last-selected-text-cut cut-text))))
+           ;; (setq x-last-selected-text-cut cut-text)
+           nil)
+          (t
+           (setq x-last-selected-text-cut-encoded cut-text
+                 x-last-selected-text-cut
+                 (decode-coding-string cut-text (or locale-coding-system
+                                                    'iso-latin-1))))))
 
     ;; As we have done one selection, clear this now.
     (setq next-selection-coding-system nil)
@@ -2337,10 +2381,7 @@ order until succeed.")
 (defun x-clipboard-yank ()
   "Insert the clipboard contents, or the last stretch of killed text."
   (interactive)
-  (let ((clipboard-text 
-        (condition-case nil
-            (x-get-selection 'CLIPBOARD)
-          (error nil)))
+  (let ((clipboard-text (x-selection-value 'CLIPBOARD))
        (x-select-enable-clipboard t))
     (if (and clipboard-text (> (length clipboard-text) 0))
        (kill-new clipboard-text))