| 1 | /* NeXT/Open/GNUstep / MacOSX Cocoa selection processing for emacs. |
| 2 | Copyright (C) 1993, 1994, 2005, 2006, 2008 |
| 3 | Free Software Foundation, Inc. |
| 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 | /* |
| 21 | Originally by Carl Edman |
| 22 | Updated by Christian Limpach (chris@nice.ch) |
| 23 | OpenStep/Rhapsody port by Scott Bender (sbender@harmony-ds.com) |
| 24 | MacOSX/Aqua port by Christophe de Dinechin (descubes@earthlink.net) |
| 25 | GNUstep port and post-20 update by Adrian Robert (arobert@cogsci.ucsd.edu) |
| 26 | */ |
| 27 | |
| 28 | #include "config.h" |
| 29 | #include "lisp.h" |
| 30 | #include "nsterm.h" |
| 31 | #include "termhooks.h" |
| 32 | |
| 33 | #define CUT_BUFFER_SUPPORT |
| 34 | |
| 35 | Lisp_Object QPRIMARY, QSECONDARY, QTEXT, QFILE_NAME; |
| 36 | |
| 37 | static Lisp_Object Vns_sent_selection_hooks; |
| 38 | static Lisp_Object Vns_lost_selection_hooks; |
| 39 | static Lisp_Object Vselection_alist; |
| 40 | static Lisp_Object Vselection_converter_alist; |
| 41 | |
| 42 | /* 23: new */ |
| 43 | /* Coding system for communicating with other programs. */ |
| 44 | static Lisp_Object Vselection_coding_system; |
| 45 | /* Coding system for the next communicating with other programs. */ |
| 46 | static Lisp_Object Vnext_selection_coding_system; |
| 47 | static Lisp_Object Qforeign_selection; |
| 48 | |
| 49 | NSString *NXSecondaryPboard; |
| 50 | |
| 51 | |
| 52 | |
| 53 | /* ========================================================================== |
| 54 | |
| 55 | Internal utility functions |
| 56 | |
| 57 | ========================================================================== */ |
| 58 | |
| 59 | |
| 60 | static NSString * |
| 61 | symbol_to_nsstring (Lisp_Object sym) |
| 62 | { |
| 63 | CHECK_SYMBOL (sym); |
| 64 | if (EQ (sym, QPRIMARY)) return NSGeneralPboard; |
| 65 | if (EQ (sym, QSECONDARY)) return NXSecondaryPboard; |
| 66 | if (EQ (sym, QTEXT)) return NSStringPboardType; |
| 67 | return [NSString stringWithUTF8String: XSTRING (XSYMBOL (sym)->xname)->data]; |
| 68 | } |
| 69 | |
| 70 | |
| 71 | static Lisp_Object |
| 72 | ns_string_to_symbol (NSString *t) |
| 73 | { |
| 74 | if ([t isEqualToString: NSGeneralPboard]) |
| 75 | return QPRIMARY; |
| 76 | if ([t isEqualToString: NXSecondaryPboard]) |
| 77 | return QSECONDARY; |
| 78 | if ([t isEqualToString: NSStringPboardType]) |
| 79 | return QTEXT; |
| 80 | if ([t isEqualToString: NSFilenamesPboardType]) |
| 81 | return QFILE_NAME; |
| 82 | if ([t isEqualToString: NSTabularTextPboardType]) |
| 83 | return QTEXT; |
| 84 | return intern ([t UTF8String]); |
| 85 | } |
| 86 | |
| 87 | |
| 88 | static Lisp_Object |
| 89 | clean_local_selection_data (Lisp_Object obj) |
| 90 | { |
| 91 | if (CONSP (obj) |
| 92 | && INTEGERP (XCAR (obj)) |
| 93 | && CONSP (XCDR (obj)) |
| 94 | && INTEGERP (XCAR (XCDR (obj))) |
| 95 | && NILP (XCDR (XCDR (obj)))) |
| 96 | obj = Fcons (XCAR (obj), XCDR (obj)); |
| 97 | |
| 98 | if (CONSP (obj) |
| 99 | && INTEGERP (XCAR (obj)) |
| 100 | && INTEGERP (XCDR (obj))) |
| 101 | { |
| 102 | if (XINT (XCAR (obj)) == 0) |
| 103 | return XCDR (obj); |
| 104 | if (XINT (XCAR (obj)) == -1) |
| 105 | return make_number (- XINT (XCDR (obj))); |
| 106 | } |
| 107 | |
| 108 | if (VECTORP (obj)) |
| 109 | { |
| 110 | int i; |
| 111 | int size = ASIZE (obj); |
| 112 | Lisp_Object copy; |
| 113 | |
| 114 | if (size == 1) |
| 115 | return clean_local_selection_data (AREF (obj, 0)); |
| 116 | copy = Fmake_vector (make_number (size), Qnil); |
| 117 | for (i = 0; i < size; i++) |
| 118 | AREF (copy, i) = clean_local_selection_data (AREF (obj, i)); |
| 119 | return copy; |
| 120 | } |
| 121 | |
| 122 | return obj; |
| 123 | } |
| 124 | |
| 125 | |
| 126 | static void |
| 127 | ns_declare_pasteboard (id pb) |
| 128 | { |
| 129 | [pb declareTypes: ns_send_types owner: NSApp]; |
| 130 | } |
| 131 | |
| 132 | |
| 133 | static void |
| 134 | ns_undeclare_pasteboard (id pb) |
| 135 | { |
| 136 | [pb declareTypes: [NSArray array] owner: nil]; |
| 137 | } |
| 138 | |
| 139 | |
| 140 | static void |
| 141 | ns_string_to_pasteboard_internal (id pb, Lisp_Object str, NSString *gtype) |
| 142 | { |
| 143 | if (EQ (str, Qnil)) |
| 144 | { |
| 145 | [pb declareTypes: [NSArray array] owner: nil]; |
| 146 | } |
| 147 | else |
| 148 | { |
| 149 | char *utfStr; |
| 150 | NSString *type, *nsStr; |
| 151 | NSEnumerator *tenum; |
| 152 | |
| 153 | CHECK_STRING (str); |
| 154 | |
| 155 | utfStr = XSTRING (str)->data; |
| 156 | nsStr = [NSString stringWithUTF8String: utfStr]; |
| 157 | |
| 158 | if (gtype == nil) |
| 159 | { |
| 160 | [pb declareTypes: ns_send_types owner: nil]; |
| 161 | tenum = [ns_send_types objectEnumerator]; |
| 162 | while ( (type = [tenum nextObject]) ) |
| 163 | [pb setString: nsStr forType: type]; |
| 164 | } |
| 165 | else |
| 166 | { |
| 167 | [pb setString: nsStr forType: gtype]; |
| 168 | } |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | |
| 173 | static Lisp_Object |
| 174 | ns_get_local_selection (Lisp_Object selection_name, |
| 175 | Lisp_Object target_type) |
| 176 | { |
| 177 | Lisp_Object local_value; |
| 178 | Lisp_Object handler_fn, value, type, check; |
| 179 | int count; |
| 180 | |
| 181 | local_value = assq_no_quit (selection_name, Vselection_alist); |
| 182 | |
| 183 | if (NILP (local_value)) return Qnil; |
| 184 | |
| 185 | count = specpdl_ptr - specpdl; |
| 186 | specbind (Qinhibit_quit, Qt); |
| 187 | CHECK_SYMBOL (target_type); |
| 188 | handler_fn = Fcdr (Fassq (target_type, Vselection_converter_alist)); |
| 189 | if (!NILP (handler_fn)) |
| 190 | value = call3 (handler_fn, selection_name, target_type, |
| 191 | XCAR (XCDR (local_value))); |
| 192 | else |
| 193 | value = Qnil; |
| 194 | unbind_to (count, Qnil); |
| 195 | |
| 196 | check = value; |
| 197 | if (CONSP (value) && SYMBOLP (XCAR (value))) |
| 198 | { |
| 199 | type = XCAR (value); |
| 200 | check = XCDR (value); |
| 201 | } |
| 202 | |
| 203 | if (STRINGP (check) || VECTORP (check) || SYMBOLP (check) |
| 204 | || INTEGERP (check) || NILP (value)) |
| 205 | return value; |
| 206 | |
| 207 | if (CONSP (check) |
| 208 | && INTEGERP (XCAR (check)) |
| 209 | && (INTEGERP (XCDR (check))|| |
| 210 | (CONSP (XCDR (check)) |
| 211 | && INTEGERP (XCAR (XCDR (check))) |
| 212 | && NILP (XCDR (XCDR (check)))))) |
| 213 | return value; |
| 214 | |
| 215 | // FIXME: Why `quit' rather than `error'? |
| 216 | Fsignal (Qquit, Fcons (build_string ( |
| 217 | "invalid data returned by selection-conversion function"), |
| 218 | Fcons (handler_fn, Fcons (value, Qnil)))); |
| 219 | // FIXME: Beware, `quit' can return!! |
| 220 | return Qnil; |
| 221 | } |
| 222 | |
| 223 | |
| 224 | static Lisp_Object |
| 225 | ns_get_foreign_selection (Lisp_Object symbol, Lisp_Object target) |
| 226 | { |
| 227 | id pb; |
| 228 | pb =[NSPasteboard pasteboardWithName: symbol_to_nsstring (symbol)]; |
| 229 | return ns_string_from_pasteboard (pb); |
| 230 | } |
| 231 | |
| 232 | |
| 233 | static void |
| 234 | ns_handle_selection_request (struct input_event *event) |
| 235 | { |
| 236 | // FIXME: BIG UGLY HACK!!! |
| 237 | id pb = (id)*(EMACS_INT*)&(event->x); |
| 238 | NSString *type = (NSString *)*(EMACS_INT*)&(event->y); |
| 239 | Lisp_Object selection_name, selection_data, target_symbol, data; |
| 240 | Lisp_Object successful_p, rest; |
| 241 | |
| 242 | selection_name = ns_string_to_symbol ([(NSPasteboard *)pb name]); |
| 243 | target_symbol = ns_string_to_symbol (type); |
| 244 | selection_data = assq_no_quit (selection_name, Vselection_alist); |
| 245 | successful_p = Qnil; |
| 246 | |
| 247 | if (!NILP (selection_data)) |
| 248 | { |
| 249 | data = ns_get_local_selection (selection_name, target_symbol); |
| 250 | if (!NILP (data)) |
| 251 | { |
| 252 | if (STRINGP (data)) |
| 253 | ns_string_to_pasteboard_internal (pb, data, type); |
| 254 | successful_p = Qt; |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | if (!EQ (Vns_sent_selection_hooks, Qunbound)) |
| 259 | { |
| 260 | for (rest = Vns_sent_selection_hooks; CONSP (rest); rest = Fcdr (rest)) |
| 261 | call3 (Fcar (rest), selection_name, target_symbol, successful_p); |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | |
| 266 | static void |
| 267 | ns_handle_selection_clear (struct input_event *event) |
| 268 | { |
| 269 | id pb = (id)*(EMACS_INT*)&(event->x); |
| 270 | Lisp_Object selection_name, selection_data, rest; |
| 271 | |
| 272 | selection_name = ns_string_to_symbol ([(NSPasteboard *)pb name]); |
| 273 | selection_data = assq_no_quit (selection_name, Vselection_alist); |
| 274 | if (NILP (selection_data)) return; |
| 275 | |
| 276 | if (EQ (selection_data, Fcar (Vselection_alist))) |
| 277 | Vselection_alist = Fcdr (Vselection_alist); |
| 278 | else |
| 279 | { |
| 280 | for (rest = Vselection_alist; !NILP (rest); rest = Fcdr (rest)) |
| 281 | if (EQ (selection_data, Fcar (Fcdr (rest)))) |
| 282 | Fsetcdr (rest, Fcdr (Fcdr (rest))); |
| 283 | } |
| 284 | |
| 285 | if (!EQ (Vns_lost_selection_hooks, Qunbound)) |
| 286 | { |
| 287 | for (rest = Vns_lost_selection_hooks;CONSP (rest); rest = Fcdr (rest)) |
| 288 | call1 (Fcar (rest), selection_name); |
| 289 | } |
| 290 | } |
| 291 | |
| 292 | |
| 293 | |
| 294 | /* ========================================================================== |
| 295 | |
| 296 | Functions used externally |
| 297 | |
| 298 | ========================================================================== */ |
| 299 | |
| 300 | |
| 301 | Lisp_Object |
| 302 | ns_string_from_pasteboard (id pb) |
| 303 | { |
| 304 | NSString *type, *str; |
| 305 | const char *utfStr; |
| 306 | |
| 307 | type = [pb availableTypeFromArray: ns_return_types]; |
| 308 | if (type == nil) |
| 309 | { |
| 310 | Fsignal (Qquit, |
| 311 | Fcons (build_string ("empty or unsupported pasteboard type"), |
| 312 | Qnil)); |
| 313 | return Qnil; |
| 314 | } |
| 315 | |
| 316 | /* get the string */ |
| 317 | if (! (str = [pb stringForType: type])) |
| 318 | { |
| 319 | NSData *data = [pb dataForType: type]; |
| 320 | if (data != nil) |
| 321 | str = [[NSString alloc] initWithData: data |
| 322 | encoding: NSUTF8StringEncoding]; |
| 323 | if (str != nil) |
| 324 | { |
| 325 | [str autorelease]; |
| 326 | } |
| 327 | else |
| 328 | { |
| 329 | Fsignal (Qquit, |
| 330 | Fcons (build_string ("pasteboard doesn't contain valid data"), |
| 331 | Qnil)); |
| 332 | return Qnil; |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | /* assume UTF8 */ |
| 337 | NS_DURING |
| 338 | { |
| 339 | /* EOL conversion: PENDING- is this too simple? */ |
| 340 | NSMutableString *mstr = [[str mutableCopy] autorelease]; |
| 341 | [mstr replaceOccurrencesOfString: @"\r\n" withString: @"\n" |
| 342 | options: NSLiteralSearch range: NSMakeRange (0, [mstr length])]; |
| 343 | [mstr replaceOccurrencesOfString: @"\r" withString: @"\n" |
| 344 | options: NSLiteralSearch range: NSMakeRange (0, [mstr length])]; |
| 345 | |
| 346 | utfStr = [mstr UTF8String]; |
| 347 | if (!utfStr) |
| 348 | utfStr = [mstr cString]; |
| 349 | } |
| 350 | NS_HANDLER |
| 351 | { |
| 352 | message1 ("ns_string_from_pasteboard: UTF8String failed\n"); |
| 353 | utfStr = [str lossyCString]; |
| 354 | } |
| 355 | NS_ENDHANDLER |
| 356 | |
| 357 | return build_string (utfStr); |
| 358 | } |
| 359 | |
| 360 | |
| 361 | void |
| 362 | ns_string_to_pasteboard (id pb, Lisp_Object str) |
| 363 | { |
| 364 | ns_string_to_pasteboard_internal (pb, str, nil); |
| 365 | } |
| 366 | |
| 367 | |
| 368 | |
| 369 | /* ========================================================================== |
| 370 | |
| 371 | Lisp Defuns |
| 372 | |
| 373 | ========================================================================== */ |
| 374 | |
| 375 | |
| 376 | DEFUN ("ns-own-selection-internal", Fns_own_selection_internal, |
| 377 | Sns_own_selection_internal, 2, 2, 0, "Assert a selection.") |
| 378 | (selection_name, selection_value) |
| 379 | Lisp_Object selection_name, selection_value; |
| 380 | { |
| 381 | id pb; |
| 382 | Lisp_Object old_value, new_value; |
| 383 | |
| 384 | check_ns (); |
| 385 | CHECK_SYMBOL (selection_name); |
| 386 | if (NILP (selection_value)) |
| 387 | error ("selection-value may not be nil."); |
| 388 | pb =[NSPasteboard pasteboardWithName: symbol_to_nsstring (selection_name)]; |
| 389 | ns_declare_pasteboard (pb); |
| 390 | old_value = assq_no_quit (selection_name, Vselection_alist); |
| 391 | new_value = Fcons (selection_name, Fcons (selection_value, Qnil)); |
| 392 | if (NILP (old_value)) |
| 393 | Vselection_alist = Fcons (new_value, Vselection_alist); |
| 394 | else |
| 395 | Fsetcdr (old_value, Fcdr (new_value)); |
| 396 | /* XXX An evil hack, but a necessary one I fear XXX */ |
| 397 | { |
| 398 | struct input_event ev; |
| 399 | ev.kind = SELECTION_REQUEST_EVENT; |
| 400 | ev.modifiers = 0; |
| 401 | ev.code = 0; |
| 402 | *(EMACS_INT*)(&(ev.x)) = (EMACS_INT)pb; // FIXME: BIG UGLY HACK!! |
| 403 | *(EMACS_INT*)(&(ev.y)) = (EMACS_INT)NSStringPboardType; |
| 404 | ns_handle_selection_request (&ev); |
| 405 | } |
| 406 | return selection_value; |
| 407 | } |
| 408 | |
| 409 | |
| 410 | DEFUN ("ns-disown-selection-internal", Fns_disown_selection_internal, |
| 411 | Sns_disown_selection_internal, 1, 2, 0, |
| 412 | "If we own the selection SELECTION, disown it.") |
| 413 | (selection_name, time) |
| 414 | Lisp_Object selection_name, time; |
| 415 | { |
| 416 | id pb; |
| 417 | check_ns (); |
| 418 | CHECK_SYMBOL (selection_name); |
| 419 | if (NILP (assq_no_quit (selection_name, Vselection_alist))) return Qnil; |
| 420 | |
| 421 | pb =[NSPasteboard pasteboardWithName: symbol_to_nsstring (selection_name)]; |
| 422 | ns_undeclare_pasteboard (pb); |
| 423 | return Qt; |
| 424 | } |
| 425 | |
| 426 | |
| 427 | DEFUN ("ns-selection-exists-p", Fns_selection_exists_p, Sns_selection_exists_p, |
| 428 | 0, 1, 0, "Whether there is an owner for the given selection.\n\ |
| 429 | The arg should be the name of the selection in question, typically one of\n\ |
| 430 | the symbols `PRIMARY', `SECONDARY', or `CLIPBOARD'.\n\ |
| 431 | \(Those are literal upper-case symbol names.)\n\ |
| 432 | For convenience, the symbol nil is the same as `PRIMARY',\n\ |
| 433 | and t is the same as `SECONDARY'.)") |
| 434 | (selection) |
| 435 | Lisp_Object selection; |
| 436 | { |
| 437 | id pb; |
| 438 | NSArray *types; |
| 439 | |
| 440 | check_ns (); |
| 441 | CHECK_SYMBOL (selection); |
| 442 | if (EQ (selection, Qnil)) selection = QPRIMARY; |
| 443 | if (EQ (selection, Qt)) selection = QSECONDARY; |
| 444 | pb =[NSPasteboard pasteboardWithName: symbol_to_nsstring (selection)]; |
| 445 | types =[pb types]; |
| 446 | return ([types count] == 0) ? Qnil : Qt; |
| 447 | } |
| 448 | |
| 449 | |
| 450 | DEFUN ("ns-selection-owner-p", Fns_selection_owner_p, Sns_selection_owner_p, |
| 451 | 0, 1, 0, |
| 452 | "Whether the current Emacs process owns the given selection.\n\ |
| 453 | The arg should be the name of the selection in question, typically one of\n\ |
| 454 | the symbols `PRIMARY', `SECONDARY', or `CLIPBOARD'.\n\ |
| 455 | \(Those are literal upper-case symbol names.)\n\ |
| 456 | For convenience, the symbol nil is the same as `PRIMARY',\n\ |
| 457 | and t is the same as `SECONDARY'.)") |
| 458 | (selection) |
| 459 | Lisp_Object selection; |
| 460 | { |
| 461 | check_ns (); |
| 462 | CHECK_SYMBOL (selection); |
| 463 | if (EQ (selection, Qnil)) selection = QPRIMARY; |
| 464 | if (EQ (selection, Qt)) selection = QSECONDARY; |
| 465 | return (NILP (Fassq (selection, Vselection_alist))) ? Qnil : Qt; |
| 466 | } |
| 467 | |
| 468 | |
| 469 | DEFUN ("ns-get-selection-internal", Fns_get_selection_internal, |
| 470 | Sns_get_selection_internal, 2, 2, 0, |
| 471 | "Return text selected from some pasteboard.\n\ |
| 472 | SELECTION is a symbol, typically `PRIMARY', `SECONDARY', or `CLIPBOARD'.\n\ |
| 473 | \(Those are literal upper-case symbol names.)\n\ |
| 474 | TYPE is the type of data desired, typically `STRING'.") |
| 475 | (selection_name, target_type) |
| 476 | Lisp_Object selection_name, target_type; |
| 477 | { |
| 478 | Lisp_Object val; |
| 479 | |
| 480 | check_ns (); |
| 481 | CHECK_SYMBOL (selection_name); |
| 482 | CHECK_SYMBOL (target_type); |
| 483 | val = ns_get_local_selection (selection_name, target_type); |
| 484 | if (NILP (val)) |
| 485 | val = ns_get_foreign_selection (selection_name, target_type); |
| 486 | if (CONSP (val) && SYMBOLP (Fcar (val))) |
| 487 | { |
| 488 | val = Fcdr (val); |
| 489 | if (CONSP (val) && NILP (Fcdr (val))) |
| 490 | val = Fcar (val); |
| 491 | } |
| 492 | val = clean_local_selection_data (val); |
| 493 | return val; |
| 494 | } |
| 495 | |
| 496 | |
| 497 | #ifdef CUT_BUFFER_SUPPORT |
| 498 | DEFUN ("ns-get-cut-buffer-internal", Fns_get_cut_buffer_internal, |
| 499 | Sns_get_cut_buffer_internal, 1, 1, 0, |
| 500 | "Returns the value of the named cut buffer.") |
| 501 | (buffer) |
| 502 | Lisp_Object buffer; |
| 503 | { |
| 504 | id pb; |
| 505 | check_ns (); |
| 506 | pb =[NSPasteboard pasteboardWithName: symbol_to_nsstring (buffer)]; |
| 507 | return ns_string_from_pasteboard (pb); |
| 508 | } |
| 509 | |
| 510 | |
| 511 | DEFUN ("ns-rotate-cut-buffers-internal", Fns_rotate_cut_buffers_internal, |
| 512 | Sns_rotate_cut_buffers_internal, 1, 1, 0, |
| 513 | "Rotate the values of the cut buffers by the given number of steps;\n\ |
| 514 | positive means move values forward, negative means backward. CURRENTLY NOT IMPLEMENTED UNDER NeXTstep.") |
| 515 | (n) |
| 516 | Lisp_Object n; |
| 517 | { |
| 518 | /* XXX This function is unimplemented under NeXTstep XXX */ |
| 519 | Fsignal (Qquit, Fcons (build_string ( |
| 520 | "Warning: ns-rotate-cut-buffers-internal not implemented\n"), Qnil)); |
| 521 | return Qnil; |
| 522 | } |
| 523 | |
| 524 | |
| 525 | DEFUN ("ns-store-cut-buffer-internal", Fns_store_cut_buffer_internal, |
| 526 | Sns_store_cut_buffer_internal, 2, 2, 0, |
| 527 | "Sets the value of the named cut buffer (typically CUT_BUFFER0).") |
| 528 | (buffer, string) |
| 529 | Lisp_Object buffer, string; |
| 530 | { |
| 531 | id pb; |
| 532 | check_ns (); |
| 533 | pb =[NSPasteboard pasteboardWithName: symbol_to_nsstring (buffer)]; |
| 534 | ns_string_to_pasteboard (pb, string); |
| 535 | return Qnil; |
| 536 | } |
| 537 | #endif |
| 538 | |
| 539 | |
| 540 | void |
| 541 | nxatoms_of_nsselect (void) |
| 542 | { |
| 543 | NXSecondaryPboard = @"Selection"; |
| 544 | } |
| 545 | |
| 546 | void |
| 547 | syms_of_nsselect (void) |
| 548 | { |
| 549 | QPRIMARY = intern ("PRIMARY"); staticpro (&QPRIMARY); |
| 550 | QSECONDARY = intern ("SECONDARY"); staticpro (&QSECONDARY); |
| 551 | QTEXT = intern ("TEXT"); staticpro (&QTEXT); |
| 552 | QFILE_NAME = intern ("FILE_NAME"); staticpro (&QFILE_NAME); |
| 553 | |
| 554 | defsubr (&Sns_disown_selection_internal); |
| 555 | defsubr (&Sns_get_selection_internal); |
| 556 | defsubr (&Sns_own_selection_internal); |
| 557 | defsubr (&Sns_selection_exists_p); |
| 558 | defsubr (&Sns_selection_owner_p); |
| 559 | #ifdef CUT_BUFFER_SUPPORT |
| 560 | defsubr (&Sns_get_cut_buffer_internal); |
| 561 | defsubr (&Sns_rotate_cut_buffers_internal); |
| 562 | defsubr (&Sns_store_cut_buffer_internal); |
| 563 | #endif |
| 564 | |
| 565 | Vselection_alist = Qnil; |
| 566 | staticpro (&Vselection_alist); |
| 567 | |
| 568 | DEFVAR_LISP ("ns-sent-selection-hooks", &Vns_sent_selection_hooks, |
| 569 | "A list of functions to be called when Emacs answers a selection request.\n\ |
| 570 | The functions are called with four arguments:\n\ |
| 571 | - the selection name (typically `PRIMARY', `SECONDARY', or `CLIPBOARD');\n\ |
| 572 | - the selection-type which Emacs was asked to convert the\n\ |
| 573 | selection into before sending (for example, `STRING' or `LENGTH');\n\ |
| 574 | - a flag indicating success or failure for responding to the request.\n\ |
| 575 | We might have failed (and declined the request) for any number of reasons,\n\ |
| 576 | including being asked for a selection that we no longer own, or being asked\n\ |
| 577 | to convert into a type that we don't know about or that is inappropriate.\n\ |
| 578 | This hook doesn't let you change the behavior of Emacs's selection replies,\n\ |
| 579 | it merely informs you that they have happened."); |
| 580 | Vns_sent_selection_hooks = Qnil; |
| 581 | |
| 582 | DEFVAR_LISP ("selection-converter-alist", &Vselection_converter_alist, |
| 583 | "An alist associating X Windows selection-types with functions.\n\ |
| 584 | These functions are called to convert the selection, with three args:\n\ |
| 585 | the name of the selection (typically `PRIMARY', `SECONDARY', or `CLIPBOARD');\n\ |
| 586 | a desired type to which the selection should be converted;\n\ |
| 587 | and the local selection value (whatever was given to `x-own-selection').\n\ |
| 588 | \n\ |
| 589 | The function should return the value to send to the X server\n\ |
| 590 | \(typically a string). A return value of nil\n\ |
| 591 | means that the conversion could not be done.\n\ |
| 592 | A return value which is the symbol `NULL'\n\ |
| 593 | means that a side-effect was executed,\n\ |
| 594 | and there is no meaningful selection value."); |
| 595 | Vselection_converter_alist = Qnil; |
| 596 | |
| 597 | DEFVAR_LISP ("ns-lost-selection-hooks", &Vns_lost_selection_hooks, |
| 598 | "A list of functions to be called when Emacs loses an X selection.\n\ |
| 599 | \(This happens when some other X client makes its own selection\n\ |
| 600 | or when a Lisp program explicitly clears the selection.)\n\ |
| 601 | The functions are called with one argument, the selection type\n\ |
| 602 | \(a symbol, typically `PRIMARY', `SECONDARY', or `CLIPBOARD')."); |
| 603 | Vns_lost_selection_hooks = Qnil; |
| 604 | |
| 605 | /* 23: { */ |
| 606 | DEFVAR_LISP ("selection-coding-system", &Vselection_coding_system, |
| 607 | doc: /* Coding system for communicating with other programs. |
| 608 | When sending or receiving text via cut_buffer, selection, and clipboard, |
| 609 | the text is encoded or decoded by this coding system. |
| 610 | The default value is determined by the system script code. */); |
| 611 | Vselection_coding_system = Qnil; |
| 612 | |
| 613 | DEFVAR_LISP ("next-selection-coding-system", &Vnext_selection_coding_system, |
| 614 | doc: /* Coding system for the next communication with other programs. |
| 615 | Usually, `selection-coding-system' is used for communicating with |
| 616 | other programs. But, if this variable is set, it is used for the |
| 617 | next communication only. After the communication, this variable is |
| 618 | set to nil. */); |
| 619 | Vnext_selection_coding_system = Qnil; |
| 620 | |
| 621 | Qforeign_selection = intern ("foreign-selection"); |
| 622 | staticpro (&Qforeign_selection); |
| 623 | /* } */ |
| 624 | |
| 625 | } |
| 626 | |
| 627 | // arch-tag: 39d1dde7-06a6-49ff-95a7-0e7af12d2218 |