]> code.delx.au - gnu-emacs/blobdiff - src/nsselect.m
(copy_text): To convert a non-ASCII char to unibyte,
[gnu-emacs] / src / nsselect.m
index b661b3f7675ac44d2b200d541b019917725904a3..fbbe86ecf5137bb89e5df4fce03b12d91935c3aa 100644 (file)
@@ -1,13 +1,13 @@
 /* NeXT/Open/GNUstep / MacOSX Cocoa selection processing for emacs.
-   Copyright (C) 1993, 1994, 2005, 2006, 2008,
-   Free Software Foundation, Inc.
+   Copyright (C) 1993, 1994, 2005, 2006, 2008
+     Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
-GNU Emacs is free software; you can redistribute it and/or modify
+GNU Emacs is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 3, or (at your option)
-any later version.
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
 
 GNU Emacs is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -15,19 +15,20 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 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., 51 Franklin Street, Fifth Floor,
-Boston, MA 02110-1301, USA.
+along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 
+/*
 Originally by Carl Edman
 Updated by Christian Limpach (chris@nice.ch)
 OpenStep/Rhapsody port by Scott Bender (sbender@harmony-ds.com)
 MacOSX/Aqua port by Christophe de Dinechin (descubes@earthlink.net)
 GNUstep port and post-20 update by Adrian Robert (arobert@cogsci.ucsd.edu)
-
 */
 
+/* This should be the first include, as it may set up #defines affecting
+   interpretation of even the system includes. */
 #include "config.h"
+
 #include "lisp.h"
 #include "nsterm.h"
 #include "termhooks.h"
@@ -42,10 +43,6 @@ static Lisp_Object Vselection_alist;
 static Lisp_Object Vselection_converter_alist;
 
 /* 23: new */
-/* Coding system for communicating with other programs. */
-static Lisp_Object Vselection_coding_system;
-/* Coding system for the next communicating with other programs. */
-static Lisp_Object Vnext_selection_coding_system;
 static Lisp_Object Qforeign_selection;
 
 NSString *NXSecondaryPboard;
@@ -110,15 +107,14 @@ clean_local_selection_data (Lisp_Object obj)
   if (VECTORP (obj))
     {
       int i;
-      int size = XVECTOR (obj)->size;
+      int size = ASIZE (obj);
       Lisp_Object copy;
 
       if (size == 1)
-        return clean_local_selection_data (XVECTOR (obj)->contents [0]);
-      copy = Fmake_vector (size, Qnil);
+        return clean_local_selection_data (AREF (obj, 0));
+      copy = Fmake_vector (make_number (size), Qnil);
       for (i = 0; i < size; i++)
-        XVECTOR (copy)->contents [i]
-          = clean_local_selection_data (XVECTOR (obj)->contents [i]);
+        AREF (copy, i) = clean_local_selection_data (AREF (obj, i));
       return copy;
     }
 
@@ -190,13 +186,13 @@ ns_get_local_selection (Lisp_Object selection_name,
   CHECK_SYMBOL (target_type);
   handler_fn = Fcdr (Fassq (target_type, Vselection_converter_alist));
   if (!NILP (handler_fn))
-    value =call3 (handler_fn, selection_name, target_type,
+    value = call3 (handler_fn, selection_name, target_type,
                 XCAR (XCDR (local_value)));
   else
-    value =Qnil;
+    value = Qnil;
   unbind_to (count, Qnil);
 
-  check =value;
+  check = value;
   if (CONSP (value) && SYMBOLP (XCAR (value)))
     {
       type = XCAR (value);
@@ -215,9 +211,12 @@ ns_get_local_selection (Lisp_Object selection_name,
            && NILP (XCDR (XCDR (check))))))
     return value;
 
+  // FIXME: Why `quit' rather than `error'?
   Fsignal (Qquit, Fcons (build_string (
       "invalid data returned by selection-conversion function"),
                         Fcons (handler_fn, Fcons (value, Qnil))));
+  // FIXME: Beware, `quit' can return!!
+  return Qnil;
 }
 
 
@@ -233,15 +232,16 @@ ns_get_foreign_selection (Lisp_Object symbol, Lisp_Object target)
 static void
 ns_handle_selection_request (struct input_event *event)
 {
-  id pb =(id)event->x;
-  NSString *type =(NSString *)event->y;
+  // FIXME: BIG UGLY HACK!!!
+  id pb = (id)*(EMACS_INT*)&(event->x);
+  NSString *type = (NSString *)*(EMACS_INT*)&(event->y);
   Lisp_Object selection_name, selection_data, target_symbol, data;
   Lisp_Object successful_p, rest;
 
-  selection_name =ns_string_to_symbol ([(NSPasteboard *)pb name]);
-  target_symbol =ns_string_to_symbol (type);
+  selection_name = ns_string_to_symbol ([(NSPasteboard *)pb name]);
+  target_symbol = ns_string_to_symbol (type);
   selection_data = assq_no_quit (selection_name, Vselection_alist);
-  successful_p =Qnil;
+  successful_p = Qnil;
 
   if (!NILP (selection_data))
     {
@@ -250,13 +250,13 @@ ns_handle_selection_request (struct input_event *event)
         {
           if (STRINGP (data))
             ns_string_to_pasteboard_internal (pb, data, type);
-          successful_p =Qt;
+          successful_p = Qt;
         }
     }
 
   if (!EQ (Vns_sent_selection_hooks, Qunbound))
     {
-      for (rest =Vns_sent_selection_hooks;CONSP (rest); rest =Fcdr (rest))
+      for (rest = Vns_sent_selection_hooks; CONSP (rest); rest = Fcdr (rest))
         call3 (Fcar (rest), selection_name, target_symbol, successful_p);
     }
 }
@@ -265,11 +265,11 @@ ns_handle_selection_request (struct input_event *event)
 static void
 ns_handle_selection_clear (struct input_event *event)
 {
-  id pb = (id)event->x;
+  id pb = (id)*(EMACS_INT*)&(event->x);
   Lisp_Object selection_name, selection_data, rest;
 
-  selection_name =ns_string_to_symbol ([(NSPasteboard *)pb name]);
-  selection_data =assq_no_quit (selection_name, Vselection_alist);
+  selection_name = ns_string_to_symbol ([(NSPasteboard *)pb name]);
+  selection_data = assq_no_quit (selection_name, Vselection_alist);
   if (NILP (selection_data)) return;
 
   if (EQ (selection_data, Fcar (Vselection_alist)))
@@ -283,7 +283,7 @@ ns_handle_selection_clear (struct input_event *event)
 
   if (!EQ (Vns_lost_selection_hooks, Qunbound))
     {
-      for (rest =Vns_lost_selection_hooks;CONSP (rest); rest =Fcdr (rest))
+      for (rest = Vns_lost_selection_hooks;CONSP (rest); rest = Fcdr (rest))
         call1 (Fcar (rest), selection_name);
     }
 }
@@ -373,7 +373,11 @@ ns_string_to_pasteboard (id pb, Lisp_Object str)
 
 
 DEFUN ("ns-own-selection-internal", Fns_own_selection_internal,
-       Sns_own_selection_internal, 2, 2, 0, "Assert a selection.")
+       Sns_own_selection_internal, 2, 2, 0,
+       doc: /* Assert a selection.
+SELECTION-NAME is a symbol, typically `PRIMARY', `SECONDARY', or `CLIPBOARD'.
+VALUE is typically a string, or a cons of two markers, but may be
+anything that the functions on `selection-converter-alist' know about.  */)
      (selection_name, selection_value)
      Lisp_Object selection_name, selection_value;
 {
@@ -386,10 +390,10 @@ DEFUN ("ns-own-selection-internal", Fns_own_selection_internal,
       error ("selection-value may not be nil.");
   pb =[NSPasteboard pasteboardWithName: symbol_to_nsstring (selection_name)];
   ns_declare_pasteboard (pb);
-  old_value =assq_no_quit (selection_name, Vselection_alist);
+  old_value = assq_no_quit (selection_name, Vselection_alist);
   new_value = Fcons (selection_name, Fcons (selection_value, Qnil));
   if (NILP (old_value))
-    Vselection_alist =Fcons (new_value, Vselection_alist);
+    Vselection_alist = Fcons (new_value, Vselection_alist);
   else
     Fsetcdr (old_value, Fcdr (new_value));
   /* XXX An evil hack, but a necessary one I fear XXX */
@@ -398,17 +402,17 @@ DEFUN ("ns-own-selection-internal", Fns_own_selection_internal,
     ev.kind = SELECTION_REQUEST_EVENT;
     ev.modifiers = 0;
     ev.code = 0;
-    ev.x = (int)pb;
-    ev.y = (int)NSStringPboardType;
+    *(EMACS_INT*)(&(ev.x)) = (EMACS_INT)pb; // FIXME: BIG UGLY HACK!!
+    *(EMACS_INT*)(&(ev.y)) = (EMACS_INT)NSStringPboardType;
     ns_handle_selection_request (&ev);
   }
   return selection_value;
 }
 
 
-DEFUN ("ns-disown-selection-internal", Fns_disown_selection_internal,
-       Sns_disown_selection_internal, 1, 2, 0,
-       "If we own the selection SELECTION, disown it.")
+DEFUN ("x-disown-selection-internal", Fx_disown_selection_internal,
+       Sx_disown_selection_internal, 1, 2, 0,
+       doc: /* If we own the selection SELECTION, disown it.  */)
      (selection_name, time)
      Lisp_Object selection_name, time;
 {
@@ -424,12 +428,12 @@ DEFUN ("ns-disown-selection-internal", Fns_disown_selection_internal,
 
 
 DEFUN ("ns-selection-exists-p", Fns_selection_exists_p, Sns_selection_exists_p,
-       0, 1, 0, "Whether there is an owner for the given selection.\n\
-The arg should be the name of the selection in question, typically one of\n\
-the symbols `PRIMARY', `SECONDARY', or `CLIPBOARD'.\n\
-\(Those are literal upper-case symbol names.)\n\
-For convenience, the symbol nil is the same as `PRIMARY',\n\
-and t is the same as `SECONDARY'.)")
+       0, 1, 0, doc: /* Whether there is an owner for the given selection.
+The arg should be the name of the selection in question, typically one of
+the symbols `PRIMARY', `SECONDARY', or `CLIPBOARD'.
+\(Those are literal upper-case symbol names.)
+For convenience, the symbol nil is the same as `PRIMARY',
+and t is the same as `SECONDARY'.)  */)
      (selection)
      Lisp_Object selection;
 {
@@ -448,12 +452,12 @@ and t is the same as `SECONDARY'.)")
 
 DEFUN ("ns-selection-owner-p", Fns_selection_owner_p, Sns_selection_owner_p,
        0, 1, 0,
-       "Whether the current Emacs process owns the given selection.\n\
-The arg should be the name of the selection in question, typically one of\n\
-the symbols `PRIMARY', `SECONDARY', or `CLIPBOARD'.\n\
-\(Those are literal upper-case symbol names.)\n\
-For convenience, the symbol nil is the same as `PRIMARY',\n\
-and t is the same as `SECONDARY'.)")
+       doc: /* Whether the current Emacs process owns the given selection.
+The arg should be the name of the selection in question, typically one of
+the symbols `PRIMARY', `SECONDARY', or `CLIPBOARD'.
+\(Those are literal upper-case symbol names.)
+For convenience, the symbol nil is the same as `PRIMARY',
+and t is the same as `SECONDARY'.)  */)
      (selection)
      Lisp_Object selection;
 {
@@ -465,12 +469,12 @@ and t is the same as `SECONDARY'.)")
 }
 
 
-DEFUN ("ns-get-selection-internal", Fns_get_selection_internal,
-       Sns_get_selection_internal, 2, 2, 0,
-       "Return text selected from some pasteboard.\n\
-SELECTION is a symbol, typically `PRIMARY', `SECONDARY', or `CLIPBOARD'.\n\
-\(Those are literal upper-case symbol names.)\n\
-TYPE is the type of data desired, typically `STRING'.")
+DEFUN ("x-get-selection-internal", Fx_get_selection_internal,
+       Sx_get_selection_internal, 2, 2, 0,
+       doc: /* Return text selected from some pasteboard.
+SELECTION is a symbol, typically `PRIMARY', `SECONDARY', or `CLIPBOARD'.
+\(Those are literal upper-case symbol names.)
+TYPE is the type of data desired, typically `STRING'.  */)
      (selection_name, target_type)
      Lisp_Object selection_name, target_type;
 {
@@ -496,7 +500,7 @@ TYPE is the type of data desired, typically `STRING'.")
 #ifdef CUT_BUFFER_SUPPORT
 DEFUN ("ns-get-cut-buffer-internal", Fns_get_cut_buffer_internal,
        Sns_get_cut_buffer_internal, 1, 1, 0,
-       "Returns the value of the named cut buffer.")
+       doc: /* Returns the value of the named cut buffer.  */)
      (buffer)
      Lisp_Object buffer;
 {
@@ -509,8 +513,9 @@ DEFUN ("ns-get-cut-buffer-internal", Fns_get_cut_buffer_internal,
 
 DEFUN ("ns-rotate-cut-buffers-internal", Fns_rotate_cut_buffers_internal,
        Sns_rotate_cut_buffers_internal, 1, 1, 0,
-       "Rotate the values of the cut buffers by the given number of steps;\n\
- positive means move values forward, negative means backward. CURRENTLY NOT IMPLEMENTED UNDER NeXTstep.")
+       doc: /* Rotate the values of the cut buffers by N steps.
+Positive N means move values forward, negative means
+backward. CURRENTLY NOT IMPLEMENTED UNDER NEXTSTEP. */ )
      (n)
      Lisp_Object n;
 {
@@ -523,7 +528,7 @@ DEFUN ("ns-rotate-cut-buffers-internal", Fns_rotate_cut_buffers_internal,
 
 DEFUN ("ns-store-cut-buffer-internal", Fns_store_cut_buffer_internal,
        Sns_store_cut_buffer_internal, 2, 2, 0,
-       "Sets the value of the named cut buffer (typically CUT_BUFFER0).")
+       doc: /* Sets the value of the named cut buffer (typically CUT_BUFFER0).  */)
      (buffer, string)
      Lisp_Object buffer, string;
 {
@@ -550,8 +555,8 @@ syms_of_nsselect (void)
   QTEXT      = intern ("TEXT");        staticpro (&QTEXT);
   QFILE_NAME = intern ("FILE_NAME");   staticpro (&QFILE_NAME);
 
-  defsubr (&Sns_disown_selection_internal);
-  defsubr (&Sns_get_selection_internal);
+  defsubr (&Sx_disown_selection_internal);
+  defsubr (&Sx_get_selection_internal);
   defsubr (&Sns_own_selection_internal);
   defsubr (&Sns_selection_exists_p);
   defsubr (&Sns_selection_owner_p);
@@ -602,26 +607,10 @@ The functions are called with one argument, the selection type\n\
   Vns_lost_selection_hooks = Qnil;
 
 /* 23: { */
-  DEFVAR_LISP ("selection-coding-system", &Vselection_coding_system,
-              doc: /* Coding system for communicating with other programs.
-When sending or receiving text via cut_buffer, selection, and clipboard,
-the text is encoded or decoded by this coding system.
-The default value is determined by the system script code.  */);
-  Vselection_coding_system = Qnil;
-
-  DEFVAR_LISP ("next-selection-coding-system", &Vnext_selection_coding_system,
-              doc: /* Coding system for the next communication with other programs.
-Usually, `selection-coding-system' is used for communicating with
-other programs.  But, if this variable is set, it is used for the
-next communication only.  After the communication, this variable is
-set to nil.  */);
-  Vnext_selection_coding_system = Qnil;
-
   Qforeign_selection = intern ("foreign-selection");
   staticpro (&Qforeign_selection);
 /* } */
 
 }
 
-/* arch-tag: 39d1dde7-06a6-49ff-95a7-0e7af12d2218
-   (do not change this comment) */
+// arch-tag: 39d1dde7-06a6-49ff-95a7-0e7af12d2218