Commit | Line | Data |
---|---|---|
f701ab72 DC |
1 | ;;; w32-common-fns.el --- Lisp routines for Windows and Cygwin-w32 |
2 | ||
ba318903 | 3 | ;; Copyright (C) 1994, 2001-2014 Free Software Foundation, Inc. |
f701ab72 DC |
4 | |
5 | ;; This file is part of GNU Emacs. | |
6 | ||
7 | ;; GNU Emacs is free software: you can redistribute it and/or modify | |
8 | ;; it under the terms of the GNU General Public License as published by | |
9 | ;; the Free Software Foundation, either version 3 of the License, or | |
10 | ;; (at your option) any later version. | |
11 | ||
12 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
13 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | ;; GNU General Public License for more details. | |
16 | ||
17 | ;; You should have received a copy of the GNU General Public License | |
18 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | |
19 | ||
20 | ;;; Commentary: | |
21 | ;;; | |
22 | ;;; This file contains functions that are used by both native NT Emacs | |
23 | ;;; and Cygwin Emacs compiled to use the native Windows widget | |
24 | ;;; library. | |
25 | ||
38702b5b GM |
26 | (declare-function x-server-version "w32fns.c" (&optional terminal)) |
27 | ||
f701ab72 DC |
28 | (defun w32-version () |
29 | "Return the MS-Windows version numbers. | |
30 | The value is a list of three integers: the major and minor version | |
31 | numbers, and the build number." | |
32 | (x-server-version)) | |
33 | ||
34 | (defun w32-using-nt () | |
35 | "Return non-nil if running on a Windows NT descendant. | |
36 | That includes all Windows systems except for 9X/Me." | |
37 | (getenv "SystemRoot")) | |
38 | ||
39 | (declare-function w32-get-clipboard-data "w32select.c") | |
40 | (declare-function w32-set-clipboard-data "w32select.c") | |
41 | (declare-function x-server-version "w32fns.c" (&optional display)) | |
42 | ||
43 | ;;; Fix interface to (X-specific) mouse.el | |
44 | (defun x-set-selection (type data) | |
45 | "Make an X selection of type TYPE and value DATA. | |
46 | The argument TYPE (nil means `PRIMARY') says which selection, and | |
47 | DATA specifies the contents. TYPE must be a symbol. \(It can also | |
48 | be a string, which stands for the symbol with that name, but this | |
49 | is considered obsolete.) DATA may be a string, a symbol, an | |
50 | integer (or a cons of two integers or list of two integers). | |
51 | ||
52 | The selection may also be a cons of two markers pointing to the same buffer, | |
53 | or an overlay. In these cases, the selection is considered to be the text | |
54 | between the markers *at whatever time the selection is examined*. | |
55 | Thus, editing done in the buffer after you specify the selection | |
56 | can alter the effective value of the selection. | |
57 | ||
58 | The data may also be a vector of valid non-vector selection values. | |
59 | ||
60 | The return value is DATA. | |
61 | ||
62 | Interactively, this command sets the primary selection. Without | |
63 | prefix argument, it reads the selection in the minibuffer. With | |
64 | prefix argument, it uses the text of the region as the selection value. | |
65 | ||
66 | Note that on MS-Windows, primary and secondary selections set by Emacs | |
67 | are not available to other programs." | |
68 | (put 'x-selections (or type 'PRIMARY) data)) | |
69 | ||
70 | (defun x-get-selection (&optional type _data-type) | |
71 | "Return the value of an X Windows selection. | |
72 | The argument TYPE (default `PRIMARY') says which selection, | |
73 | and the argument DATA-TYPE (default `STRING') says | |
74 | how to convert the data. | |
75 | ||
76 | TYPE may be any symbol \(but nil stands for `PRIMARY'). However, | |
77 | only a few symbols are commonly used. They conventionally have | |
78 | all upper-case names. The most often used ones, in addition to | |
79 | `PRIMARY', are `SECONDARY' and `CLIPBOARD'. | |
80 | ||
81 | DATA-TYPE is usually `STRING', but can also be one of the symbols | |
02328db9 EZ |
82 | in `selection-converter-alist', which see. This argument is |
83 | ignored on MS-Windows and MS-DOS." | |
f701ab72 DC |
84 | (get 'x-selections (or type 'PRIMARY))) |
85 | ||
86 | ;; x-selection-owner-p is used in simple.el | |
aac06179 JB |
87 | (defun x-selection-owner-p (&optional selection _terminal) |
88 | "" ; placeholder for doc.c | |
89 | (and (memq selection '(nil PRIMARY SECONDARY)) | |
90 | (get 'x-selections (or selection 'PRIMARY)))) | |
f701ab72 DC |
91 | |
92 | ;; The "Windows" keys on newer keyboards bring up the Start menu | |
93 | ;; whether you want it or not - make Emacs ignore these keystrokes | |
94 | ;; rather than beep. | |
95 | (global-set-key [lwindow] 'ignore) | |
96 | (global-set-key [rwindow] 'ignore) | |
97 | ||
98 | (defvar w32-charset-info-alist) ; w32font.c | |
99 | ||
100 | \f | |
101 | ;;;; Selections | |
102 | ||
103 | ;; We keep track of the last text selected here, so we can check the | |
104 | ;; current selection against it, and avoid passing back our own text | |
105 | ;; from x-selection-value. | |
106 | (defvar x-last-selected-text nil) | |
38702b5b | 107 | (defvar x-select-enable-clipboard) |
f701ab72 DC |
108 | |
109 | (defun x-get-selection-value () | |
110 | "Return the value of the current selection. | |
111 | Consult the selection. Treat empty strings as if they were unset." | |
112 | (if x-select-enable-clipboard | |
113 | (let (text) | |
114 | ;; Don't die if x-get-selection signals an error. | |
30213927 GM |
115 | (with-demoted-errors "w32-get-clipboard-data:%s" |
116 | (setq text (w32-get-clipboard-data))) | |
f701ab72 DC |
117 | (if (string= text "") (setq text nil)) |
118 | (cond | |
119 | ((not text) nil) | |
120 | ((eq text x-last-selected-text) nil) | |
121 | ((string= text x-last-selected-text) | |
122 | ;; Record the newer string, so subsequent calls can use the 'eq' test. | |
123 | (setq x-last-selected-text text) | |
124 | nil) | |
125 | (t | |
126 | (setq x-last-selected-text text)))))) | |
127 | \f | |
128 | (defalias 'x-selection-value 'x-get-selection-value) | |
129 | ||
130 | ;; Arrange for the kill and yank functions to set and check the clipboard. | |
131 | (setq interprogram-cut-function 'x-select-text) | |
132 | (setq interprogram-paste-function 'x-get-selection-value) | |
133 | ||
134 | (provide 'w32-common-fns) |