]> code.delx.au - gnu-emacs/blob - src/w16select.c
34ca75c409e9c89c8c3686e2ccd95dc5e827e755
[gnu-emacs] / src / w16select.c
1 /* 16-bit Windows Selection processing for emacs on MS-Windows
2
3 Copyright (C) 1996, 1997, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
4 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
5
6 This file is part of GNU Emacs.
7
8 GNU Emacs is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
20
21 /* These functions work by using WinOldAp interface. WinOldAp
22 (WINOLDAP.MOD) is a Microsoft Windows extension supporting
23 "old" (character-mode) application access to Dynamic Data Exchange,
24 menus, and the Windows clipboard. */
25
26 /* Written by Dale P. Smith <dpsm@en.com> */
27 /* Adapted to DJGPP by Eli Zaretskii <eliz@gnu.org> */
28
29 #ifdef MSDOS
30
31 #include <config.h>
32 #include <dpmi.h>
33 #include <go32.h>
34 #include <sys/farptr.h>
35 #include <setjmp.h>
36 #include "lisp.h"
37 #include "dispextern.h" /* frame.h seems to want this */
38 #include "frame.h" /* Need this to get the X window of selected_frame */
39 #include "blockinput.h"
40 #include "buffer.h"
41 #include "character.h"
42 #include "coding.h"
43 #include "composite.h"
44
45 /* If ever some function outside this file will need to call any
46 clipboard-related function, the following prototypes and constants
47 should be put on a header file. Right now, nobody else uses them. */
48
49 #define CF_TEXT 0x01
50 #define CF_BITMAP 0x02
51 #define CF_METAFILE 0x03
52 #define CF_SYLK 0x04
53 #define CF_DIF 0x05
54 #define CF_TIFF 0x06
55 #define CF_OEMTEXT 0x07
56 #define CF_DIBBITMAP 0x08
57 #define CF_WINWRITE 0x80
58 #define CF_DSPTEXT 0x81
59 #define CF_DSPBITMAP 0x82
60
61 unsigned identify_winoldap_version (void);
62 unsigned open_clipboard (void);
63 unsigned empty_clipboard (void);
64 unsigned set_clipboard_data (unsigned, void *, unsigned, int);
65 unsigned get_clipboard_data_size (unsigned);
66 unsigned get_clipboard_data (unsigned, void *, unsigned, int);
67 unsigned close_clipboard (void);
68 unsigned clipboard_compact (unsigned);
69
70 Lisp_Object QCLIPBOARD, QPRIMARY;
71
72 /* The segment address and the size of the buffer in low
73 memory used to move data between us and WinOldAp module. */
74 static struct {
75 unsigned long size;
76 unsigned short rm_segment;
77 } clipboard_xfer_buf_info;
78
79 /* The last text we put into the clipboard. This is used to prevent
80 passing back our own text from the clipboard, instead of using the
81 kill ring. The former is undesirable because the clipboard data
82 could be MULEtilated by inappropriately chosen
83 (next-)selection-coding-system. For this reason, we must store the
84 text *after* it was encoded/Unix-to-DOS-converted. */
85 static unsigned char *last_clipboard_text;
86
87 /* The size of allocated storage for storing the clipboard data. */
88 static size_t clipboard_storage_size;
89 \f
90 /* C functions to access the Windows 3.1x clipboard from DOS apps.
91
92 The information was obtained from the Microsoft Knowledge Base,
93 article Q67675 and can be found at:
94 http://www.microsoft.com/kb/developr/win_dk/q67675.htm */
95
96 /* See also Ralf Brown's Interrupt List.
97
98 I also seem to remember reading about this in Dr. Dobbs Journal a
99 while ago, but if you knew my memory... :-)
100
101 Dale P. Smith <dpsm@en.com> */
102
103 /* Return the WinOldAp support version, or 0x1700 if not supported. */
104 unsigned
105 identify_winoldap_version (void)
106 {
107 __dpmi_regs regs;
108
109 /* Calls Int 2Fh/AX=1700h
110 Return Values AX == 1700H: Clipboard functions not available
111 <> 1700H: AL = Major version number
112 AH = Minor version number */
113 regs.x.ax = 0x1700;
114 __dpmi_int(0x2f, &regs);
115 return regs.x.ax;
116 }
117
118 /* Open the clipboard, return non-zero if successfull. */
119 unsigned
120 open_clipboard (void)
121 {
122 __dpmi_regs regs;
123
124 /* Is WINOLDAP supported? */
125 /* Kludge alert!! If WinOldAp is not supported, we return a 0,
126 which is the same as ``Clipboard already open''. Currently,
127 this is taken as an error by all the functions that use
128 `open_clipboard', but if somebody someday will use that ``open''
129 clipboard, they will have interesting time debugging it... */
130 if (identify_winoldap_version () == 0x1700)
131 return 0;
132
133 /* Calls Int 2Fh/AX=1701h
134 Return Values AX == 0: Clipboard already open
135 <> 0: Clipboard opened */
136 regs.x.ax = 0x1701;
137 __dpmi_int(0x2f, &regs);
138 return regs.x.ax;
139 }
140
141 /* Empty clipboard, return non-zero if successfull. */
142 unsigned
143 empty_clipboard (void)
144 {
145 __dpmi_regs regs;
146
147 /* Calls Int 2Fh/AX=1702h
148 Return Values AX == 0: Error occurred
149 <> 0: OK, Clipboard emptied */
150 regs.x.ax = 0x1702;
151 __dpmi_int(0x2f, &regs);
152 return regs.x.ax;
153 }
154
155 /* Ensure we have a buffer in low memory with enough memory for data
156 of size WANT_SIZE. Return the linear address of the buffer. */
157 static unsigned long
158 alloc_xfer_buf (unsigned want_size)
159 {
160 __dpmi_regs regs;
161
162 /* If the usual DJGPP transfer buffer is large enough, use that. */
163 if (want_size <= _go32_info_block.size_of_transfer_buffer)
164 return __tb & 0xfffff;
165
166 /* Don't even try to allocate more than 1MB of memory: DOS cannot
167 possibly handle that (it will overflow the BX register below). */
168 if (want_size > 0xfffff)
169 return 0;
170
171 /* Need size rounded up to the nearest paragraph, and in
172 paragraph units (1 paragraph = 16 bytes). */
173 clipboard_xfer_buf_info.size = (want_size + 15) >> 4;
174
175 /* The NT DPMI host crashes us if we free DOS memory via the
176 DPMI service. Work around by calling DOS allocate/free block. */
177 regs.h.ah = 0x48;
178 regs.x.bx = clipboard_xfer_buf_info.size;
179 __dpmi_int (0x21, &regs);
180 if (regs.x.flags & 1)
181 {
182 clipboard_xfer_buf_info.size = 0;
183 return 0;
184 }
185
186 clipboard_xfer_buf_info.rm_segment = regs.x.ax;
187 return (((int)clipboard_xfer_buf_info.rm_segment) << 4) & 0xfffff;
188 }
189
190 /* Free our clipboard buffer. We always free it after use, because
191 keeping it leaves less free conventional memory for subprocesses.
192 The clipboard buffer tends to be large in size, because for small
193 clipboard data sizes we use the DJGPP transfer buffer. */
194 static void
195 free_xfer_buf (void)
196 {
197 /* If the size is 0, we used DJGPP transfer buffer, so don't free. */
198 if (clipboard_xfer_buf_info.size)
199 {
200 __dpmi_regs regs;
201
202 /* The NT DPMI host crashes us if we free DOS memory via
203 the DPMI service. Work around by calling DOS free block. */
204 regs.h.ah = 0x49;
205 regs.x.es = clipboard_xfer_buf_info.rm_segment;
206 __dpmi_int (0x21, &regs);
207 clipboard_xfer_buf_info.size = 0;
208 }
209 }
210
211 /* Copy data into the clipboard, return zero if successfull. */
212 unsigned
213 set_clipboard_data (unsigned Format, void *Data, unsigned Size, int Raw)
214 {
215 __dpmi_regs regs;
216 unsigned truelen;
217 unsigned long xbuf_addr, buf_offset;
218 unsigned char *dp = Data, *dstart = dp;
219
220 if (Format != CF_OEMTEXT)
221 return 3;
222
223 /* need to know final size after '\r' chars are inserted (the
224 standard CF_OEMTEXT clipboard format uses CRLF line endings,
225 while Emacs uses just LF internally). */
226 truelen = Size + 1; /* +1 for the terminating null */
227
228 if (!Raw)
229 {
230 /* avoid using strchr because it recomputes the length everytime */
231 while ((dp = memchr (dp, '\n', Size - (dp - dstart))) != 0)
232 {
233 truelen++;
234 dp++;
235 }
236 }
237
238 if (clipboard_compact (truelen) < truelen)
239 return 1;
240
241 if ((xbuf_addr = alloc_xfer_buf (truelen)) == 0)
242 return 1;
243
244 /* Move the buffer into the low memory, convert LF into CR-LF if needed. */
245 if (Raw)
246 {
247 dosmemput (Data, Size, xbuf_addr);
248
249 /* Terminate with a null, otherwise Windows does strange things
250 when the text size is an integral multiple of 32 bytes. */
251 _farpokeb (_dos_ds, xbuf_addr + Size, '\0');
252 }
253 else
254 {
255 dp = Data;
256 buf_offset = xbuf_addr;
257 _farsetsel (_dos_ds);
258 while (Size--)
259 {
260 /* Don't allow them to put binary data into the clipboard, since
261 it will cause yanked data to be truncated at the first null. */
262 if (*dp == '\0')
263 return 2;
264 if (*dp == '\n')
265 _farnspokeb (buf_offset++, '\r');
266 _farnspokeb (buf_offset++, *dp++);
267 }
268
269 /* Terminate with a null, otherwise Windows does strange things
270 when the text size is an integral multiple of 32 bytes. */
271 _farnspokeb (buf_offset, '\0');
272 }
273
274 /* Stash away the data we are about to put into the clipboard, so we
275 could later check inside get_clipboard_data whether the clipboard
276 still holds our data. */
277 if (clipboard_storage_size < truelen)
278 {
279 clipboard_storage_size = truelen + 100;
280 last_clipboard_text =
281 (char *) xrealloc (last_clipboard_text, clipboard_storage_size);
282 }
283 if (last_clipboard_text)
284 dosmemget (xbuf_addr, truelen, last_clipboard_text);
285
286 /* Calls Int 2Fh/AX=1703h with:
287 DX = WinOldAp-Supported Clipboard format
288 ES:BX = Pointer to data
289 SI:CX = Size of data in bytes
290 Return Values AX == 0: Error occurred
291 <> 0: OK. Data copied into the Clipboard. */
292 regs.x.ax = 0x1703;
293 regs.x.dx = Format;
294 regs.x.si = truelen >> 16;
295 regs.x.cx = truelen & 0xffff;
296 regs.x.es = xbuf_addr >> 4;
297 regs.x.bx = xbuf_addr & 15;
298 __dpmi_int(0x2f, &regs);
299
300 free_xfer_buf ();
301
302 /* If the above failed, invalidate the local copy of the clipboard. */
303 if (regs.x.ax == 0)
304 *last_clipboard_text = '\0';
305
306 /* Zero means success, otherwise (1, 2, or 3) it's an error. */
307 return regs.x.ax > 0 ? 0 : 3;
308 }
309
310 /* Return the size of the clipboard data of format FORMAT. */
311 unsigned
312 get_clipboard_data_size (unsigned Format)
313 {
314 __dpmi_regs regs;
315
316 /* Calls Int 2Fh/AX=1704h with:
317 DX = WinOldAp-Supported Clipboard format
318 Return Values DX:AX == Size of the data in bytes, including any
319 headers.
320 == 0 If data in this format is not in
321 the clipboard. */
322 regs.x.ax = 0x1704;
323 regs.x.dx = Format;
324 __dpmi_int(0x2f, &regs);
325 return ( (((unsigned)regs.x.dx) << 16) | regs.x.ax);
326 }
327
328 /* Get clipboard data, return its length.
329 Warning: this doesn't check whether DATA has enough space to hold
330 SIZE bytes. */
331 unsigned
332 get_clipboard_data (unsigned Format, void *Data, unsigned Size, int Raw)
333 {
334 __dpmi_regs regs;
335 unsigned long xbuf_addr;
336 unsigned char *dp = Data;
337
338 if (Format != CF_OEMTEXT)
339 return 0;
340
341 if (Size == 0)
342 return 0;
343
344 if ((xbuf_addr = alloc_xfer_buf (Size)) == 0)
345 return 0;
346
347 /* Calls Int 2Fh/AX=1705h with:
348 DX = WinOldAp-Supported Clipboard format
349 ES:BX = Pointer to data buffer to hold data
350 Return Values AX == 0: Error occurred (or data in this format is not
351 in the clipboard)
352 <> 0: OK */
353 regs.x.ax = 0x1705;
354 regs.x.dx = Format;
355 regs.x.es = xbuf_addr >> 4;
356 regs.x.bx = xbuf_addr & 15;
357 __dpmi_int(0x2f, &regs);
358 if (regs.x.ax != 0)
359 {
360 unsigned char null_char = '\0';
361 unsigned long xbuf_beg = xbuf_addr;
362
363 /* If last_clipboard_text is NULL, we don't want to slow down
364 the next loop by an additional test. */
365 register unsigned char *lcdp =
366 last_clipboard_text == NULL ? &null_char : last_clipboard_text;
367
368 /* Copy data from low memory, remove CR
369 characters before LF if needed. */
370 _farsetsel (_dos_ds);
371 while (Size--)
372 {
373 register unsigned char c = _farnspeekb (xbuf_addr++);
374
375 if (*lcdp == c)
376 lcdp++;
377
378 if ((*dp++ = c) == '\r' && !Raw && _farnspeekb (xbuf_addr) == '\n')
379 {
380 dp--;
381 *dp++ = '\n';
382 xbuf_addr++;
383 if (*lcdp == '\n')
384 lcdp++;
385 }
386 /* Windows reportedly rounds up the size of clipboard data
387 (passed in SIZE) to a multiple of 32, and removes trailing
388 spaces from each line without updating SIZE. We therefore
389 bail out when we see the first null character. */
390 else if (c == '\0')
391 break;
392 }
393
394 /* If the text in clipboard is identical to what we put there
395 last time set_clipboard_data was called, pretend there's no
396 data in the clipboard. This is so we don't pass our own text
397 from the clipboard (which might be troublesome if the killed
398 text includes null characters). */
399 if (last_clipboard_text &&
400 xbuf_addr - xbuf_beg == (long)(lcdp - last_clipboard_text))
401 dp = (unsigned char *)Data + 1;
402 }
403
404 free_xfer_buf ();
405
406 return (unsigned) (dp - (unsigned char *)Data - 1);
407 }
408
409 /* Close clipboard, return non-zero if successfull. */
410 unsigned
411 close_clipboard (void)
412 {
413 __dpmi_regs regs;
414
415 /* Calls Int 2Fh/AX=1708h
416 Return Values AX == 0: Error occurred
417 <> 0: OK */
418 regs.x.ax = 0x1708;
419 __dpmi_int(0x2f, &regs);
420 return regs.x.ax;
421 }
422
423 /* Compact clipboard data so that at least SIZE bytes is available. */
424 unsigned
425 clipboard_compact (unsigned Size)
426 {
427 __dpmi_regs regs;
428
429 /* Calls Int 2Fh/AX=1709H with:
430 SI:CX = Desired memory size in bytes.
431 Return Values DX:AX == Number of bytes of largest block of free memory.
432 == 0 if error or no memory */
433 regs.x.ax = 0x1709;
434 regs.x.si = Size >> 16;
435 regs.x.cx = Size & 0xffff;
436 __dpmi_int(0x2f, &regs);
437 return ((unsigned)regs.x.dx << 16) | regs.x.ax;
438 }
439 \f
440 static char no_mem_msg[] =
441 "(Not enough DOS memory to put saved text into clipboard.)";
442 static char binary_msg[] =
443 "(Binary characters in saved text; clipboard data not set.)";
444 static char system_error_msg[] =
445 "(Clipboard interface failure; clipboard data not set.)";
446
447 DEFUN ("w16-set-clipboard-data", Fw16_set_clipboard_data, Sw16_set_clipboard_data, 1, 2, 0,
448 doc: /* This sets the clipboard data to the given text. */)
449 (Lisp_Object string, Lisp_Object frame)
450 {
451 unsigned ok = 1, put_status = 0;
452 int nbytes, no_crlf_conversion;
453 unsigned char *src, *dst = NULL;
454
455 CHECK_STRING (string);
456
457 if (NILP (frame))
458 frame = Fselected_frame ();
459
460 CHECK_LIVE_FRAME (frame);
461 if ( !FRAME_MSDOS_P (XFRAME (frame)))
462 goto done;
463
464 BLOCK_INPUT;
465
466 if (!open_clipboard ())
467 goto error;
468
469 nbytes = SBYTES (string);
470 src = SDATA (string);
471
472 /* Do we need to encode this text? */
473 for (dst = src; dst < src + nbytes; dst++)
474 {
475 if (*dst == '\0' || *dst >= 0x80)
476 break;
477 }
478 if (dst >= src + nbytes)
479 {
480 /* No multibyte characters in text. We need not encode it, but we
481 will have to convert it to DOS CR-LF style. */
482 no_crlf_conversion = 0;
483 Vlast_coding_system_used = Qraw_text;
484 dst = NULL; /* so we don't try to free a random pointer */
485 }
486 else
487 {
488 /* We must encode contents of STRING according to what
489 clipboard-coding-system specifies. */
490 struct coding_system coding;
491 Lisp_Object coding_system =
492 NILP (Vnext_selection_coding_system) ?
493 Vselection_coding_system : Vnext_selection_coding_system;
494
495 setup_coding_system (Fcheck_coding_system (coding_system), &coding);
496 coding.dst_bytes = nbytes * 4;
497 coding.destination = (unsigned char *) xmalloc (coding.dst_bytes);
498 Vnext_selection_coding_system = Qnil;
499 coding.mode |= CODING_MODE_LAST_BLOCK;
500 dst = coding.destination;
501 encode_coding_object (&coding, string, 0, 0,
502 SCHARS (string), nbytes, Qnil);
503 no_crlf_conversion = 1;
504 nbytes = coding.produced;
505 Vlast_coding_system_used = CODING_ID_NAME (coding.id);
506 src = dst;
507 }
508
509 ok = empty_clipboard ()
510 && ((put_status
511 = set_clipboard_data (CF_OEMTEXT, src, nbytes, no_crlf_conversion))
512 == 0);
513
514 if (!no_crlf_conversion)
515 close_clipboard ();
516
517 if (ok) goto unblock;
518
519 error:
520
521 ok = 0;
522
523 unblock:
524 xfree (dst);
525 UNBLOCK_INPUT;
526
527 /* Notify user if the text is too large to fit into DOS memory.
528 (This will happen somewhere after 600K bytes (470K in DJGPP v1.x),
529 depending on user system configuration.) If we just silently
530 fail the function, people might wonder why their text sometimes
531 doesn't make it to the clipboard. */
532 if (put_status)
533 {
534 switch (put_status)
535 {
536 case 1:
537 message2 (no_mem_msg, sizeof (no_mem_msg) - 1, 0);
538 break;
539 case 2:
540 message2 (binary_msg, sizeof (binary_msg) - 1, 0);
541 break;
542 case 3:
543 message2 (system_error_msg, sizeof (system_error_msg) - 1, 0);
544 break;
545 }
546 sit_for (make_number (2), 0, 2);
547 }
548
549 done:
550
551 return (ok && put_status == 0 ? string : Qnil);
552 }
553
554 DEFUN ("w16-get-clipboard-data", Fw16_get_clipboard_data, Sw16_get_clipboard_data, 0, 1, 0,
555 doc: /* This gets the clipboard data in text format. */)
556 (Lisp_Object frame)
557 {
558 unsigned data_size, truelen;
559 unsigned char *htext = NULL;
560 Lisp_Object ret = Qnil;
561 int require_decoding = 0;
562
563 if (NILP (frame))
564 frame = Fselected_frame ();
565
566 CHECK_LIVE_FRAME (frame);
567 if ( !FRAME_MSDOS_P (XFRAME (frame)))
568 goto done;
569
570 BLOCK_INPUT;
571
572 if (!open_clipboard ())
573 goto unblock;
574
575 if ((data_size = get_clipboard_data_size (CF_OEMTEXT)) == 0 ||
576 (htext = (unsigned char *)xmalloc (data_size)) == 0)
577 goto closeclip;
578
579 /* need to know final size after '\r' chars are removed because
580 we can't change the string size manually, and doing an extra
581 copy is silly */
582 if ((truelen = get_clipboard_data (CF_OEMTEXT, htext, data_size, 0)) == 0)
583 goto closeclip;
584
585 /* Do we need to decode it? */
586 {
587 /* If the clipboard data contains any 8-bit Latin-1 code, we
588 need to decode it. */
589 int i;
590
591 for (i = 0; i < truelen; i++)
592 {
593 if (htext[i] >= 0x80)
594 {
595 require_decoding = 1;
596 break;
597 }
598 }
599 }
600 if (require_decoding)
601 {
602 struct coding_system coding;
603 Lisp_Object coding_system = Vnext_selection_coding_system;
604
605 truelen = get_clipboard_data (CF_OEMTEXT, htext, data_size, 1);
606 if (NILP (coding_system))
607 coding_system = Vselection_coding_system;
608 setup_coding_system (Fcheck_coding_system (coding_system), &coding);
609 coding.source = htext;
610 coding.mode |= CODING_MODE_LAST_BLOCK;
611 /* We explicitly disable composition handling because selection
612 data should not contain any composition sequence. */
613 coding.mode &= CODING_ANNOTATION_MASK;
614 decode_coding_object (&coding, Qnil, 0, 0, truelen, truelen, Qt);
615 ret = coding.dst_object;
616 Vlast_coding_system_used = CODING_ID_NAME (coding.id);
617 }
618 else
619 {
620 ret = make_unibyte_string ((char *) htext, truelen);
621 Vlast_coding_system_used = Qraw_text;
622 }
623
624 xfree (htext);
625 Vnext_selection_coding_system = Qnil;
626
627 closeclip:
628 close_clipboard ();
629
630 unblock:
631 UNBLOCK_INPUT;
632
633 done:
634
635 return (ret);
636 }
637
638 /* Support checking for a clipboard selection. */
639
640 DEFUN ("x-selection-exists-p", Fx_selection_exists_p, Sx_selection_exists_p,
641 0, 1, 0,
642 doc: /* Whether there is an owner for the given X Selection.
643 The arg should be the name of the selection in question, typically one of
644 the symbols `PRIMARY', `SECONDARY', or `CLIPBOARD'.
645 \(Those are literal upper-case symbol names, since that's what X expects.)
646 For convenience, the symbol nil is the same as `PRIMARY',
647 and t is the same as `SECONDARY'. */)
648 (Lisp_Object selection)
649 {
650 CHECK_SYMBOL (selection);
651
652 /* Return nil for SECONDARY selection. For PRIMARY (or nil)
653 selection, check if there is some text on the kill-ring;
654 for CLIPBOARD, check if the clipboard currently has valid
655 text format contents.
656
657 The test for killed text on the kill-ring emulates the Emacs
658 behavior on X, where killed text is also put into X selection
659 by the X interface code. (On MSDOS, killed text is only put
660 into the clipboard if we run under Windows, so we cannot check
661 the clipboard alone.) */
662 if ((EQ (selection, Qnil) || EQ (selection, QPRIMARY))
663 && ! NILP (Fsymbol_value (Fintern_soft (build_string ("kill-ring"),
664 Qnil))))
665 return Qt;
666
667 if (EQ (selection, QCLIPBOARD))
668 {
669 Lisp_Object val = Qnil;
670
671 if (open_clipboard ())
672 {
673 if (get_clipboard_data_size (CF_OEMTEXT))
674 val = Qt;
675 close_clipboard ();
676 }
677 return val;
678 }
679 return Qnil;
680 }
681
682 void
683 syms_of_win16select (void)
684 {
685 defsubr (&Sw16_set_clipboard_data);
686 defsubr (&Sw16_get_clipboard_data);
687 defsubr (&Sx_selection_exists_p);
688
689 DEFVAR_LISP ("selection-coding-system", Vselection_coding_system,
690 doc: /* Coding system for communicating with other programs.
691
692 For MS-Windows and MS-DOS:
693 When sending or receiving text via selection and clipboard, the text
694 is encoded or decoded by this coding system. The default value is
695 the current system default encoding on 9x/Me, `utf-16le-dos'
696 \(Unicode) on NT/W2K/XP, and `iso-latin-1-dos' on MS-DOS.
697
698 For X Windows:
699 When sending text via selection and clipboard, if the target
700 data-type matches with the type of this coding system, it is used
701 for encoding the text. Otherwise (including the case that this
702 variable is nil), a proper coding system is used as below:
703
704 data-type coding system
705 --------- -------------
706 UTF8_STRING utf-8
707 COMPOUND_TEXT compound-text-with-extensions
708 STRING iso-latin-1
709 C_STRING no-conversion
710
711 When receiving text, if this coding system is non-nil, it is used
712 for decoding regardless of the data-type. If this is nil, a
713 proper coding system is used according to the data-type as above.
714
715 See also the documentation of the variable `x-select-request-type' how
716 to control which data-type to request for receiving text.
717
718 The default value is nil. */);
719 Vselection_coding_system = intern ("iso-latin-1-dos");
720
721 DEFVAR_LISP ("next-selection-coding-system", Vnext_selection_coding_system,
722 doc: /* Coding system for the next communication with other programs.
723 Usually, `selection-coding-system' is used for communicating with
724 other programs (X Windows clients or MS Windows programs). But, if this
725 variable is set, it is used for the next communication only.
726 After the communication, this variable is set to nil. */);
727 Vnext_selection_coding_system = Qnil;
728
729 QPRIMARY = intern ("PRIMARY"); staticpro (&QPRIMARY);
730 QCLIPBOARD = intern ("CLIPBOARD"); staticpro (&QCLIPBOARD);
731 }
732
733 #endif /* MSDOS */
734