diff options
| author | Karl Heuer | 1997-09-30 07:15:28 +0000 |
|---|---|---|
| committer | Karl Heuer | 1997-09-30 07:15:28 +0000 |
| commit | b4f334f7976f8f7d18bacc1cdfb4b11154db8ae8 (patch) | |
| tree | ab87da1204caaf8a8df8ceceb5d49bc352a75b3e | |
| parent | 8e41a31c5d691dc844994f080ff21baa1863fcde (diff) | |
| download | emacs-b4f334f7976f8f7d18bacc1cdfb4b11154db8ae8.tar.gz emacs-b4f334f7976f8f7d18bacc1cdfb4b11154db8ae8.zip | |
(Qwidget_type): New variable.
(widget-plist-member, widget-put, widget-get, widget-apply): Move
here from lisp/wid-edit.el; translated into C for efficiency.
(syms_of_fns): Initialize Qwidget_type; defsubr new functions.
| -rw-r--r-- | src/fns.c | 128 |
1 files changed, 109 insertions, 19 deletions
| @@ -52,6 +52,7 @@ extern Lisp_Object minibuf_window; | |||
| 52 | Lisp_Object Qstring_lessp, Qprovide, Qrequire; | 52 | Lisp_Object Qstring_lessp, Qprovide, Qrequire; |
| 53 | Lisp_Object Qyes_or_no_p_history; | 53 | Lisp_Object Qyes_or_no_p_history; |
| 54 | Lisp_Object Qcursor_in_echo_area; | 54 | Lisp_Object Qcursor_in_echo_area; |
| 55 | Lisp_Object Qwidget_type; | ||
| 55 | 56 | ||
| 56 | static int internal_equal (); | 57 | static int internal_equal (); |
| 57 | 58 | ||
| @@ -155,7 +156,7 @@ DEFUN ("safe-length", Fsafe_length, Ssafe_length, 1, 1, 0, | |||
| 155 | This function never gets an error. If LIST is not really a list,\n\ | 156 | This function never gets an error. If LIST is not really a list,\n\ |
| 156 | it returns 0. If LIST is circular, it returns a finite value\n\ | 157 | it returns 0. If LIST is circular, it returns a finite value\n\ |
| 157 | which is at least the number of distinct elements.") | 158 | which is at least the number of distinct elements.") |
| 158 | (list) | 159 | (list) |
| 159 | Lisp_Object list; | 160 | Lisp_Object list; |
| 160 | { | 161 | { |
| 161 | Lisp_Object tail, halftail, length; | 162 | Lisp_Object tail, halftail, length; |
| @@ -543,7 +544,7 @@ concat (nargs, args, target_type, last_special) | |||
| 543 | if (!NILP (prev)) | 544 | if (!NILP (prev)) |
| 544 | XCONS (prev)->cdr = last_tail; | 545 | XCONS (prev)->cdr = last_tail; |
| 545 | 546 | ||
| 546 | return val; | 547 | return val; |
| 547 | } | 548 | } |
| 548 | 549 | ||
| 549 | DEFUN ("copy-alist", Fcopy_alist, Scopy_alist, 1, 1, 0, | 550 | DEFUN ("copy-alist", Fcopy_alist, Scopy_alist, 1, 1, 0, |
| @@ -618,7 +619,7 @@ This function allows vectors as well as strings.") | |||
| 618 | else | 619 | else |
| 619 | res = Fvector (XINT (to) - XINT (from), | 620 | res = Fvector (XINT (to) - XINT (from), |
| 620 | XVECTOR (string)->contents + XINT (from)); | 621 | XVECTOR (string)->contents + XINT (from)); |
| 621 | 622 | ||
| 622 | return res; | 623 | return res; |
| 623 | } | 624 | } |
| 624 | 625 | ||
| @@ -1042,9 +1043,9 @@ otherwise the new PROP VAL pair is added. The new plist is returned;\n\ | |||
| 1042 | use `(setq x (plist-put x prop val))' to be sure to use the new value.\n\ | 1043 | use `(setq x (plist-put x prop val))' to be sure to use the new value.\n\ |
| 1043 | The PLIST is modified by side effects.") | 1044 | The PLIST is modified by side effects.") |
| 1044 | (plist, prop, val) | 1045 | (plist, prop, val) |
| 1045 | Lisp_Object plist; | 1046 | Lisp_Object plist; |
| 1046 | register Lisp_Object prop; | 1047 | register Lisp_Object prop; |
| 1047 | Lisp_Object val; | 1048 | Lisp_Object val; |
| 1048 | { | 1049 | { |
| 1049 | register Lisp_Object tail, prev; | 1050 | register Lisp_Object tail, prev; |
| 1050 | Lisp_Object newcell; | 1051 | Lisp_Object newcell; |
| @@ -1256,7 +1257,7 @@ DEFUN ("char-table-subtype", Fchar_table_subtype, Schar_table_subtype, | |||
| 1256 | (char_table) | 1257 | (char_table) |
| 1257 | Lisp_Object char_table; | 1258 | Lisp_Object char_table; |
| 1258 | { | 1259 | { |
| 1259 | CHECK_CHAR_TABLE (char_table, 0); | 1260 | CHECK_CHAR_TABLE (char_table, 0); |
| 1260 | 1261 | ||
| 1261 | return XCHAR_TABLE (char_table)->purpose; | 1262 | return XCHAR_TABLE (char_table)->purpose; |
| 1262 | } | 1263 | } |
| @@ -1271,7 +1272,7 @@ then the actual applicable value is inherited from the parent char-table\n\ | |||
| 1271 | (char_table) | 1272 | (char_table) |
| 1272 | Lisp_Object char_table; | 1273 | Lisp_Object char_table; |
| 1273 | { | 1274 | { |
| 1274 | CHECK_CHAR_TABLE (char_table, 0); | 1275 | CHECK_CHAR_TABLE (char_table, 0); |
| 1275 | 1276 | ||
| 1276 | return XCHAR_TABLE (char_table)->parent; | 1277 | return XCHAR_TABLE (char_table)->parent; |
| 1277 | } | 1278 | } |
| @@ -1285,11 +1286,11 @@ PARENT must be either nil or another char-table.") | |||
| 1285 | { | 1286 | { |
| 1286 | Lisp_Object temp; | 1287 | Lisp_Object temp; |
| 1287 | 1288 | ||
| 1288 | CHECK_CHAR_TABLE (char_table, 0); | 1289 | CHECK_CHAR_TABLE (char_table, 0); |
| 1289 | 1290 | ||
| 1290 | if (!NILP (parent)) | 1291 | if (!NILP (parent)) |
| 1291 | { | 1292 | { |
| 1292 | CHECK_CHAR_TABLE (parent, 0); | 1293 | CHECK_CHAR_TABLE (parent, 0); |
| 1293 | 1294 | ||
| 1294 | for (temp = parent; !NILP (temp); temp = XCHAR_TABLE (temp)->parent) | 1295 | for (temp = parent; !NILP (temp); temp = XCHAR_TABLE (temp)->parent) |
| 1295 | if (EQ (temp, char_table)) | 1296 | if (EQ (temp, char_table)) |
| @@ -1344,7 +1345,7 @@ or a character code.") | |||
| 1344 | int i; | 1345 | int i; |
| 1345 | 1346 | ||
| 1346 | CHECK_CHAR_TABLE (char_table, 0); | 1347 | CHECK_CHAR_TABLE (char_table, 0); |
| 1347 | 1348 | ||
| 1348 | if (EQ (range, Qnil)) | 1349 | if (EQ (range, Qnil)) |
| 1349 | return XCHAR_TABLE (char_table)->defalt; | 1350 | return XCHAR_TABLE (char_table)->defalt; |
| 1350 | else if (INTEGERP (range)) | 1351 | else if (INTEGERP (range)) |
| @@ -1379,7 +1380,7 @@ or a character code.") | |||
| 1379 | int i; | 1380 | int i; |
| 1380 | 1381 | ||
| 1381 | CHECK_CHAR_TABLE (char_table, 0); | 1382 | CHECK_CHAR_TABLE (char_table, 0); |
| 1382 | 1383 | ||
| 1383 | if (EQ (range, Qt)) | 1384 | if (EQ (range, Qt)) |
| 1384 | for (i = 0; i < CHAR_TABLE_ORDINARY_SLOTS; i++) | 1385 | for (i = 0; i < CHAR_TABLE_ORDINARY_SLOTS; i++) |
| 1385 | XCHAR_TABLE (char_table)->contents[i] = value; | 1386 | XCHAR_TABLE (char_table)->contents[i] = value; |
| @@ -1515,7 +1516,7 @@ map_char_table (c_function, function, subtable, arg, depth, indices) | |||
| 1515 | else | 1516 | else |
| 1516 | call2 (function, make_number (c), elt); | 1517 | call2 (function, make_number (c), elt); |
| 1517 | } | 1518 | } |
| 1518 | } | 1519 | } |
| 1519 | } | 1520 | } |
| 1520 | } | 1521 | } |
| 1521 | 1522 | ||
| @@ -1674,7 +1675,7 @@ SEPARATOR results in spaces between the values returned by FUNCTION.") | |||
| 1674 | 1675 | ||
| 1675 | for (i = leni - 1; i >= 0; i--) | 1676 | for (i = leni - 1; i >= 0; i--) |
| 1676 | args[i + i] = args[i]; | 1677 | args[i + i] = args[i]; |
| 1677 | 1678 | ||
| 1678 | for (i = 1; i < nargs; i += 2) | 1679 | for (i = 1; i < nargs; i += 2) |
| 1679 | args[i] = separator; | 1680 | args[i] = separator; |
| 1680 | 1681 | ||
| @@ -1729,7 +1730,6 @@ Also accepts Space to mean yes, or Delete to mean no.") | |||
| 1729 | 1730 | ||
| 1730 | while (1) | 1731 | while (1) |
| 1731 | { | 1732 | { |
| 1732 | |||
| 1733 | 1733 | ||
| 1734 | #ifdef HAVE_MENUS | 1734 | #ifdef HAVE_MENUS |
| 1735 | if ((NILP (last_nonmenu_event) || CONSP (last_nonmenu_event)) | 1735 | if ((NILP (last_nonmenu_event) || CONSP (last_nonmenu_event)) |
| @@ -1851,7 +1851,7 @@ and can edit it until it has been confirmed.") | |||
| 1851 | CHECK_STRING (prompt, 0); | 1851 | CHECK_STRING (prompt, 0); |
| 1852 | 1852 | ||
| 1853 | #ifdef HAVE_MENUS | 1853 | #ifdef HAVE_MENUS |
| 1854 | if ((NILP (last_nonmenu_event) || CONSP (last_nonmenu_event)) | 1854 | if ((NILP (last_nonmenu_event) || CONSP (last_nonmenu_event)) |
| 1855 | && use_dialog_box | 1855 | && use_dialog_box |
| 1856 | && have_menus_p ()) | 1856 | && have_menus_p ()) |
| 1857 | { | 1857 | { |
| @@ -1927,7 +1927,7 @@ Use this to conditionalize execution of lisp code based on the presence or\n\ | |||
| 1927 | absence of emacs or environment extensions.\n\ | 1927 | absence of emacs or environment extensions.\n\ |
| 1928 | Use `provide' to declare that a feature is available.\n\ | 1928 | Use `provide' to declare that a feature is available.\n\ |
| 1929 | This function looks at the value of the variable `features'.") | 1929 | This function looks at the value of the variable `features'.") |
| 1930 | (feature) | 1930 | (feature) |
| 1931 | Lisp_Object feature; | 1931 | Lisp_Object feature; |
| 1932 | { | 1932 | { |
| 1933 | register Lisp_Object tem; | 1933 | register Lisp_Object tem; |
| @@ -1938,7 +1938,7 @@ This function looks at the value of the variable `features'.") | |||
| 1938 | 1938 | ||
| 1939 | DEFUN ("provide", Fprovide, Sprovide, 1, 1, 0, | 1939 | DEFUN ("provide", Fprovide, Sprovide, 1, 1, 0, |
| 1940 | "Announce that FEATURE is a feature of the current Emacs.") | 1940 | "Announce that FEATURE is a feature of the current Emacs.") |
| 1941 | (feature) | 1941 | (feature) |
| 1942 | Lisp_Object feature; | 1942 | Lisp_Object feature; |
| 1943 | { | 1943 | { |
| 1944 | register Lisp_Object tem; | 1944 | register Lisp_Object tem; |
| @@ -1957,7 +1957,7 @@ DEFUN ("require", Frequire, Srequire, 1, 2, 0, | |||
| 1957 | If FEATURE is not a member of the list `features', then the feature\n\ | 1957 | If FEATURE is not a member of the list `features', then the feature\n\ |
| 1958 | is not loaded; so load the file FILENAME.\n\ | 1958 | is not loaded; so load the file FILENAME.\n\ |
| 1959 | If FILENAME is omitted, the printname of FEATURE is used as the file name.") | 1959 | If FILENAME is omitted, the printname of FEATURE is used as the file name.") |
| 1960 | (feature, file_name) | 1960 | (feature, file_name) |
| 1961 | Lisp_Object feature, file_name; | 1961 | Lisp_Object feature, file_name; |
| 1962 | { | 1962 | { |
| 1963 | register Lisp_Object tem; | 1963 | register Lisp_Object tem; |
| @@ -1987,6 +1987,90 @@ If FILENAME is omitted, the printname of FEATURE is used as the file name.") | |||
| 1987 | return feature; | 1987 | return feature; |
| 1988 | } | 1988 | } |
| 1989 | 1989 | ||
| 1990 | /* Primitives for work of the "widget" library. | ||
| 1991 | In an ideal world, this section would not have been necessary. | ||
| 1992 | However, lisp function calls being as slow as they are, it turns | ||
| 1993 | out that some functions in the widget library (wid-edit.el) are the | ||
| 1994 | bottleneck of Widget operation. Here is their translation to C, | ||
| 1995 | for the sole reason of efficiency. */ | ||
| 1996 | |||
| 1997 | DEFUN ("widget-plist-member", Fwidget_plist_member, Swidget_plist_member, 2, 2, 0, | ||
| 1998 | "Return non-nil if PLIST has the property PROP.\n\ | ||
| 1999 | PLIST is a property list, which is a list of the form\n\ | ||
| 2000 | \(PROP1 VALUE1 PROP2 VALUE2 ...\). PROP is a symbol.\n\ | ||
| 2001 | Unlike `plist-get', this allows you to distinguish between a missing\n\ | ||
| 2002 | property and a property with the value nil.\n\ | ||
| 2003 | The value is actually the tail of PLIST whose car is PROP.") | ||
| 2004 | (plist, prop) | ||
| 2005 | Lisp_Object plist, prop; | ||
| 2006 | { | ||
| 2007 | while (CONSP (plist) && !EQ (XCAR (plist), prop)) | ||
| 2008 | { | ||
| 2009 | QUIT; | ||
| 2010 | plist = XCDR (plist); | ||
| 2011 | plist = CDR (plist); | ||
| 2012 | } | ||
| 2013 | return plist; | ||
| 2014 | } | ||
| 2015 | |||
| 2016 | DEFUN ("widget-put", Fwidget_put, Swidget_put, 3, 3, 0, | ||
| 2017 | "In WIDGET, set PROPERTY to VALUE.\n\ | ||
| 2018 | The value can later be retrieved with `widget-get'.") | ||
| 2019 | (widget, property, value) | ||
| 2020 | Lisp_Object widget, property, value; | ||
| 2021 | { | ||
| 2022 | CHECK_CONS (widget, 1); | ||
| 2023 | XCDR (widget) = Fplist_put (XCDR (widget), property, value); | ||
| 2024 | } | ||
| 2025 | |||
| 2026 | DEFUN ("widget-get", Fwidget_get, Swidget_get, 2, 2, 0, | ||
| 2027 | "In WIDGET, get the value of PROPERTY.\n\ | ||
| 2028 | The value could either be specified when the widget was created, or\n\ | ||
| 2029 | later with `widget-put'.") | ||
| 2030 | (widget, property) | ||
| 2031 | Lisp_Object widget, property; | ||
| 2032 | { | ||
| 2033 | Lisp_Object tmp; | ||
| 2034 | |||
| 2035 | while (1) | ||
| 2036 | { | ||
| 2037 | if (NILP (widget)) | ||
| 2038 | return Qnil; | ||
| 2039 | CHECK_CONS (widget, 1); | ||
| 2040 | tmp = Fwidget_plist_member (XCDR (widget), property); | ||
| 2041 | if (CONSP (tmp)) | ||
| 2042 | { | ||
| 2043 | tmp = XCDR (tmp); | ||
| 2044 | return CAR (tmp); | ||
| 2045 | } | ||
| 2046 | tmp = XCAR (widget); | ||
| 2047 | if (NILP (tmp)) | ||
| 2048 | return Qnil; | ||
| 2049 | widget = Fget (tmp, Qwidget_type); | ||
| 2050 | } | ||
| 2051 | } | ||
| 2052 | |||
| 2053 | DEFUN ("widget-apply", Fwidget_apply, Swidget_apply, 2, MANY, 0, | ||
| 2054 | "Apply the value of WIDGET's PROPERTY to the widget itself.\n\ | ||
| 2055 | ARGS are passed as extra arguments to the function.") | ||
| 2056 | (nargs, args) | ||
| 2057 | int nargs; | ||
| 2058 | Lisp_Object *args; | ||
| 2059 | { | ||
| 2060 | /* This function can GC. */ | ||
| 2061 | Lisp_Object newargs[3]; | ||
| 2062 | struct gcpro gcpro1, gcpro2; | ||
| 2063 | Lisp_Object result; | ||
| 2064 | |||
| 2065 | newargs[0] = Fwidget_get (args[0], args[1]); | ||
| 2066 | newargs[1] = args[0]; | ||
| 2067 | newargs[2] = Flist (nargs - 2, args + 2); | ||
| 2068 | GCPRO2 (newargs[0], newargs[2]); | ||
| 2069 | result = Fapply (3, newargs); | ||
| 2070 | UNGCPRO; | ||
| 2071 | return result; | ||
| 2072 | } | ||
| 2073 | |||
| 1990 | syms_of_fns () | 2074 | syms_of_fns () |
| 1991 | { | 2075 | { |
| 1992 | Qstring_lessp = intern ("string-lessp"); | 2076 | Qstring_lessp = intern ("string-lessp"); |
| @@ -1999,6 +2083,8 @@ syms_of_fns () | |||
| 1999 | staticpro (&Qyes_or_no_p_history); | 2083 | staticpro (&Qyes_or_no_p_history); |
| 2000 | Qcursor_in_echo_area = intern ("cursor-in-echo-area"); | 2084 | Qcursor_in_echo_area = intern ("cursor-in-echo-area"); |
| 2001 | staticpro (&Qcursor_in_echo_area); | 2085 | staticpro (&Qcursor_in_echo_area); |
| 2086 | Qwidget_type = intern ("widget-type"); | ||
| 2087 | staticpro (&Qwidget_type); | ||
| 2002 | 2088 | ||
| 2003 | Fset (Qyes_or_no_p_history, Qnil); | 2089 | Fset (Qyes_or_no_p_history, Qnil); |
| 2004 | 2090 | ||
| @@ -2063,4 +2149,8 @@ invoked by mouse clicks and mouse menu items."); | |||
| 2063 | defsubr (&Sfeaturep); | 2149 | defsubr (&Sfeaturep); |
| 2064 | defsubr (&Srequire); | 2150 | defsubr (&Srequire); |
| 2065 | defsubr (&Sprovide); | 2151 | defsubr (&Sprovide); |
| 2152 | defsubr (&Swidget_plist_member); | ||
| 2153 | defsubr (&Swidget_put); | ||
| 2154 | defsubr (&Swidget_get); | ||
| 2155 | defsubr (&Swidget_apply); | ||
| 2066 | } | 2156 | } |