aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJan Djärv2011-12-18 14:49:38 +0100
committerJan Djärv2011-12-18 14:49:38 +0100
commitc803b2b767f8ed06beb28106a03f23bc577cfdae (patch)
tree605daf67747b4ec447f5e133d9dce821e0efc53f /src
parente1b01a3a530809a1e84ecddff31faf85b94e79e7 (diff)
downloademacs-c803b2b767f8ed06beb28106a03f23bc577cfdae.tar.gz
emacs-c803b2b767f8ed06beb28106a03f23bc577cfdae.zip
NS selection bug fix and cleanup, see thread C-g crash in C-x C-f (OSX Lion).
Thread is on emacs-devel. * lisp/term/ns-win.el (ns-get-selection-internal) (ns-store-selection-internal): Declare. (ns-store-cut-buffer-internal, ns-get-cut-buffer-internal): Declare as obsolete. (ns-get-pasteboard, ns-paste-secondary): Use ns-get-selection-internal. (ns-set-pasteboard, ns-copy-including-secondary): Use ns-store-selection-internal. * src/nsselect.m (CUT_BUFFER_SUPPORT): Remove define. (symbol_to_nsstring): Fix indentation. (ns_symbol_to_pb): New function. (Fns_get_selection_internal): Renamed from Fns_get_cut_buffer_internal. (Fns_rotate_cut_buffers_internal): Removed. (Fns_store_selection_internal): Renamed from Fns_store_cut_buffer_internal. (ns_get_foreign_selection, Fx_own_selection_internal) (Fx_disown_selection_internal, Fx_selection_exists_p) (Fns_get_selection_internal, Fns_store_selection_internal): Use ns_symbol_to_pb and check if return value is nil. (syms_of_nsselect): Remove ifdef CUT_BUFFER_SUPPORT. Remove defsubr Sns_rotate_cut_buffers_internal. Sns_get_cut_buffer_internal renamed to Sns_get_selection_internal, Sns_store_cut_buffer_internal renamed to Sns_store_selection_internal. (ns_handle_selection_request): Move code to Fx_own_selection_internal and remove this function. (ns_handle_selection_clear): Remove, never used. (Fx_own_selection_internal): Move code from ns_handle_selection_request here.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog23
-rw-r--r--src/nsselect.m168
2 files changed, 79 insertions, 112 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index e25f0c68ce0..610079fe321 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,26 @@
12011-12-18 Jan Djärv <jan.h.d@swipnet.se>
2
3 * nsselect.m (CUT_BUFFER_SUPPORT): Remove define.
4 (symbol_to_nsstring): Fix indentation.
5 (ns_symbol_to_pb): New function.
6 (Fns_get_selection_internal): Renamed from Fns_get_cut_buffer_internal.
7 (Fns_rotate_cut_buffers_internal): Removed.
8 (Fns_store_selection_internal): Renamed from
9 Fns_store_cut_buffer_internal.
10 (ns_get_foreign_selection, Fx_own_selection_internal)
11 (Fx_disown_selection_internal, Fx_selection_exists_p)
12 (Fns_get_selection_internal, Fns_store_selection_internal): Use
13 ns_symbol_to_pb and check if return value is nil.
14 (syms_of_nsselect): Remove ifdef CUT_BUFFER_SUPPORT. Remove
15 defsubr Sns_rotate_cut_buffers_internal. Sns_get_cut_buffer_internal
16 renamed to Sns_get_selection_internal, Sns_store_cut_buffer_internal
17 renamed to Sns_store_selection_internal.
18 (ns_handle_selection_request): Move code to Fx_own_selection_internal
19 and remove this function.
20 (ns_handle_selection_clear): Remove, never used.
21 (Fx_own_selection_internal): Move code from ns_handle_selection_request
22 here.
23
12011-12-17 Ken Brown <kbrown@cornell.edu> 242011-12-17 Ken Brown <kbrown@cornell.edu>
2 25
3 * fileio.c (check_writable) [CYGWIN]: Return non-zero if UID or 26 * fileio.c (check_writable) [CYGWIN]: Return non-zero if UID or
diff --git a/src/nsselect.m b/src/nsselect.m
index 867cf3252e5..928eb8652dc 100644
--- a/src/nsselect.m
+++ b/src/nsselect.m
@@ -35,8 +35,6 @@ GNUstep port and post-20 update by Adrian Robert (arobert@cogsci.ucsd.edu)
35#include "termhooks.h" 35#include "termhooks.h"
36#include "keyboard.h" 36#include "keyboard.h"
37 37
38#define CUT_BUFFER_SUPPORT
39
40Lisp_Object QCLIPBOARD, QSECONDARY, QTEXT, QFILE_NAME; 38Lisp_Object QCLIPBOARD, QSECONDARY, QTEXT, QFILE_NAME;
41 39
42static Lisp_Object Vselection_alist; 40static Lisp_Object Vselection_alist;
@@ -60,13 +58,18 @@ static NSString *
60symbol_to_nsstring (Lisp_Object sym) 58symbol_to_nsstring (Lisp_Object sym)
61{ 59{
62 CHECK_SYMBOL (sym); 60 CHECK_SYMBOL (sym);
63 if (EQ (sym, QCLIPBOARD)) return NSGeneralPboard; 61 if (EQ (sym, QCLIPBOARD)) return NSGeneralPboard;
64 if (EQ (sym, QPRIMARY)) return NXPrimaryPboard; 62 if (EQ (sym, QPRIMARY)) return NXPrimaryPboard;
65 if (EQ (sym, QSECONDARY)) return NXSecondaryPboard; 63 if (EQ (sym, QSECONDARY)) return NXSecondaryPboard;
66 if (EQ (sym, QTEXT)) return NSStringPboardType; 64 if (EQ (sym, QTEXT)) return NSStringPboardType;
67 return [NSString stringWithUTF8String: SDATA (XSYMBOL (sym)->xname)]; 65 return [NSString stringWithUTF8String: SDATA (XSYMBOL (sym)->xname)];
68} 66}
69 67
68static NSPasteboard *
69ns_symbol_to_pb (Lisp_Object symbol)
70{
71 return [NSPasteboard pasteboardWithName: symbol_to_nsstring (symbol)];
72}
70 73
71static Lisp_Object 74static Lisp_Object
72ns_string_to_symbol (NSString *t) 75ns_string_to_symbol (NSString *t)
@@ -230,70 +233,11 @@ static Lisp_Object
230ns_get_foreign_selection (Lisp_Object symbol, Lisp_Object target) 233ns_get_foreign_selection (Lisp_Object symbol, Lisp_Object target)
231{ 234{
232 id pb; 235 id pb;
233 pb =[NSPasteboard pasteboardWithName: symbol_to_nsstring (symbol)]; 236 pb = ns_symbol_to_pb (symbol);
234 return ns_string_from_pasteboard (pb); 237 return pb != nil ? ns_string_from_pasteboard (pb) : Qnil;
235}
236
237
238static void
239ns_handle_selection_request (struct input_event *event)
240{
241 // FIXME: BIG UGLY HACK!!!
242 id pb = (id)*(EMACS_INT*)&(event->x);
243 NSString *type = (NSString *)*(EMACS_INT*)&(event->y);
244 Lisp_Object selection_name, selection_data, target_symbol, data;
245 Lisp_Object successful_p, rest;
246
247 selection_name = ns_string_to_symbol ([(NSPasteboard *)pb name]);
248 target_symbol = ns_string_to_symbol (type);
249 selection_data = assq_no_quit (selection_name, Vselection_alist);
250 successful_p = Qnil;
251
252 if (!NILP (selection_data))
253 {
254 data = ns_get_local_selection (selection_name, target_symbol);
255 if (!NILP (data))
256 {
257 if (STRINGP (data))
258 ns_string_to_pasteboard_internal (pb, data, type);
259 successful_p = Qt;
260 }
261 }
262
263 if (!EQ (Vns_sent_selection_hooks, Qunbound))
264 {
265 for (rest = Vns_sent_selection_hooks; CONSP (rest); rest = Fcdr (rest))
266 call3 (Fcar (rest), selection_name, target_symbol, successful_p);
267 }
268} 238}
269 239
270 240
271static void
272ns_handle_selection_clear (struct input_event *event)
273{
274 id pb = (id)*(EMACS_INT*)&(event->x);
275 Lisp_Object selection_name, selection_data, rest;
276
277 selection_name = ns_string_to_symbol ([(NSPasteboard *)pb name]);
278 selection_data = assq_no_quit (selection_name, Vselection_alist);
279 if (NILP (selection_data)) return;
280
281 if (EQ (selection_data, Fcar (Vselection_alist)))
282 Vselection_alist = Fcdr (Vselection_alist);
283 else
284 {
285 for (rest = Vselection_alist; !NILP (rest); rest = Fcdr (rest))
286 if (EQ (selection_data, Fcar (Fcdr (rest))))
287 Fsetcdr (rest, Fcdr (Fcdr (rest)));
288 }
289
290 if (!EQ (Vns_lost_selection_hooks, Qunbound))
291 {
292 for (rest = Vns_lost_selection_hooks;CONSP (rest); rest = Fcdr (rest))
293 call1 (Fcar (rest), selection_name);
294 }
295}
296
297 241
298 242
299/* ========================================================================== 243/* ==========================================================================
@@ -401,29 +345,44 @@ anything that the functions on `selection-converter-alist' know about. */)
401{ 345{
402 id pb; 346 id pb;
403 Lisp_Object old_value, new_value; 347 Lisp_Object old_value, new_value;
348 NSString *type;
349 Lisp_Object successful_p = Qnil, rest;
350 Lisp_Object target_symbol, data;
351
404 352
405 check_ns (); 353 check_ns ();
406 CHECK_SYMBOL (selection_name); 354 CHECK_SYMBOL (selection_name);
407 if (NILP (selection_value)) 355 if (NILP (selection_value))
408 error ("selection-value may not be nil."); 356 error ("selection-value may not be nil.");
409 pb =[NSPasteboard pasteboardWithName: symbol_to_nsstring (selection_name)]; 357 pb = ns_symbol_to_pb (selection_name);
358 if (pb == nil) return Qnil;
359
410 ns_declare_pasteboard (pb); 360 ns_declare_pasteboard (pb);
411 old_value = assq_no_quit (selection_name, Vselection_alist); 361 old_value = assq_no_quit (selection_name, Vselection_alist);
412 new_value = Fcons (selection_name, Fcons (selection_value, Qnil)); 362 new_value = Fcons (selection_name, Fcons (selection_value, Qnil));
363
413 if (NILP (old_value)) 364 if (NILP (old_value))
414 Vselection_alist = Fcons (new_value, Vselection_alist); 365 Vselection_alist = Fcons (new_value, Vselection_alist);
415 else 366 else
416 Fsetcdr (old_value, Fcdr (new_value)); 367 Fsetcdr (old_value, Fcdr (new_value));
417 /* XXX An evil hack, but a necessary one I fear XXX */ 368
418 { 369 /* We only support copy of text. */
419 struct input_event ev; 370 type = NSStringPboardType;
420 ev.kind = SELECTION_REQUEST_EVENT; 371 target_symbol = ns_string_to_symbol (type);
421 ev.modifiers = 0; 372 data = ns_get_local_selection (selection_name, target_symbol);
422 ev.code = 0; 373 if (!NILP (data))
423 *(EMACS_INT*)(&(ev.x)) = (EMACS_INT)pb; // FIXME: BIG UGLY HACK!! 374 {
424 *(EMACS_INT*)(&(ev.y)) = (EMACS_INT)NSStringPboardType; 375 if (STRINGP (data))
425 ns_handle_selection_request (&ev); 376 ns_string_to_pasteboard_internal (pb, data, type);
426 } 377 successful_p = Qt;
378 }
379
380 if (!EQ (Vns_sent_selection_hooks, Qunbound))
381 {
382 for (rest = Vns_sent_selection_hooks; CONSP (rest); rest = Fcdr (rest))
383 call3 (Fcar (rest), selection_name, target_symbol, successful_p);
384 }
385
427 return selection_value; 386 return selection_value;
428} 387}
429 388
@@ -438,8 +397,8 @@ DEFUN ("x-disown-selection-internal", Fx_disown_selection_internal,
438 CHECK_SYMBOL (selection_name); 397 CHECK_SYMBOL (selection_name);
439 if (NILP (assq_no_quit (selection_name, Vselection_alist))) return Qnil; 398 if (NILP (assq_no_quit (selection_name, Vselection_alist))) return Qnil;
440 399
441 pb =[NSPasteboard pasteboardWithName: symbol_to_nsstring (selection_name)]; 400 pb = ns_symbol_to_pb (selection_name);
442 ns_undeclare_pasteboard (pb); 401 if (pb != nil) ns_undeclare_pasteboard (pb);
443 return Qt; 402 return Qt;
444} 403}
445 404
@@ -460,8 +419,10 @@ and t is the same as `SECONDARY'.) */)
460 CHECK_SYMBOL (selection); 419 CHECK_SYMBOL (selection);
461 if (EQ (selection, Qnil)) selection = QPRIMARY; 420 if (EQ (selection, Qnil)) selection = QPRIMARY;
462 if (EQ (selection, Qt)) selection = QSECONDARY; 421 if (EQ (selection, Qt)) selection = QSECONDARY;
463 pb =[NSPasteboard pasteboardWithName: symbol_to_nsstring (selection)]; 422 pb = ns_symbol_to_pb (selection);
464 types =[pb types]; 423 if (pb == nil) return Qnil;
424
425 types = [pb types];
465 return ([types count] == 0) ? Qnil : Qt; 426 return ([types count] == 0) ? Qnil : Qt;
466} 427}
467 428
@@ -511,45 +472,31 @@ TYPE is the type of data desired, typically `STRING'. */)
511} 472}
512 473
513 474
514#ifdef CUT_BUFFER_SUPPORT 475DEFUN ("ns-get-selection-internal", Fns_get_selection_internal,
515DEFUN ("ns-get-cut-buffer-internal", Fns_get_cut_buffer_internal, 476 Sns_get_selection_internal, 1, 1, 0,
516 Sns_get_cut_buffer_internal, 1, 1, 0, 477 doc: /* Returns the value of SELECTION as a string.
517 doc: /* Returns the value of the named cut buffer. */) 478SELECTION is a symbol, typically `PRIMARY', `SECONDARY', or `CLIPBOARD'. */)
518 (Lisp_Object buffer) 479 (Lisp_Object selection)
519{ 480{
520 id pb; 481 id pb;
521 check_ns (); 482 check_ns ();
522 pb =[NSPasteboard pasteboardWithName: symbol_to_nsstring (buffer)]; 483 pb = ns_symbol_to_pb (selection);
523 return ns_string_from_pasteboard (pb); 484 return pb != nil ? ns_string_from_pasteboard (pb) : Qnil;
524} 485}
525 486
526 487
527DEFUN ("ns-rotate-cut-buffers-internal", Fns_rotate_cut_buffers_internal, 488DEFUN ("ns-store-selection-internal", Fns_store_selection_internal,
528 Sns_rotate_cut_buffers_internal, 1, 1, 0, 489 Sns_store_selection_internal, 2, 2, 0,
529 doc: /* Rotate the values of the cut buffers by N steps. 490 doc: /* Sets the string value of SELECTION.
530Positive N means move values forward, negative means 491SELECTION is a symbol, typically `PRIMARY', `SECONDARY', or `CLIPBOARD'. */)
531backward. CURRENTLY NOT IMPLEMENTED UNDER NEXTSTEP. */ ) 492 (Lisp_Object selection, Lisp_Object string)
532 (Lisp_Object n)
533{
534 /* XXX This function is unimplemented under NeXTstep XXX */
535 Fsignal (Qquit, Fcons (build_string (
536 "Warning: ns-rotate-cut-buffers-internal not implemented\n"), Qnil));
537 return Qnil;
538}
539
540
541DEFUN ("ns-store-cut-buffer-internal", Fns_store_cut_buffer_internal,
542 Sns_store_cut_buffer_internal, 2, 2, 0,
543 doc: /* Sets the value of the named cut buffer (typically CUT_BUFFER0). */)
544 (Lisp_Object buffer, Lisp_Object string)
545{ 493{
546 id pb; 494 id pb;
547 check_ns (); 495 check_ns ();
548 pb =[NSPasteboard pasteboardWithName: symbol_to_nsstring (buffer)]; 496 pb = ns_symbol_to_pb (selection);
549 ns_string_to_pasteboard (pb, string); 497 if (pb != nil) ns_string_to_pasteboard (pb, string);
550 return Qnil; 498 return Qnil;
551} 499}
552#endif
553 500
554 501
555void 502void
@@ -572,11 +519,8 @@ syms_of_nsselect (void)
572 defsubr (&Sx_own_selection_internal); 519 defsubr (&Sx_own_selection_internal);
573 defsubr (&Sx_selection_exists_p); 520 defsubr (&Sx_selection_exists_p);
574 defsubr (&Sx_selection_owner_p); 521 defsubr (&Sx_selection_owner_p);
575#ifdef CUT_BUFFER_SUPPORT 522 defsubr (&Sns_get_selection_internal);
576 defsubr (&Sns_get_cut_buffer_internal); 523 defsubr (&Sns_store_selection_internal);
577 defsubr (&Sns_rotate_cut_buffers_internal);
578 defsubr (&Sns_store_cut_buffer_internal);
579#endif
580 524
581 Vselection_alist = Qnil; 525 Vselection_alist = Qnil;
582 staticpro (&Vselection_alist); 526 staticpro (&Vselection_alist);