diff src/eval.c @ 4744:17f7e9191c0b

Rationalise duplicated functionality, #'custom-quote, #'quote-maybe. src/ChangeLog addition: 2009-11-15 Aidan Kehoe <kehoea@parhasard.net> * eval.c (Fquote_maybe): Move this function here from callint.c; make it more comprehensive about which types are self-quoting. * lisp.h: Declare Fquote_maybe here, since it's now used in callint.c and defined in eval.c * callint.c (Fquote_maybe): Remove this function from this file. lisp/ChangeLog addition: 2009-11-15 Aidan Kehoe <kehoea@parhasard.net> * custom.el (custom-quote): Define this as an alias for `quote-maybe', which is in C and more comprehensive; packages still use this name in places. (customize-mark-to-save, customize-mark-as-set): Use `quote-maybe', not `custom-quote'. * cus-edit.el (customize-set-variable, customize-save-variable) (custom-variable-value-create, custom-variable-set) (custom-variable-pre-save): Remove a version of `custom-quote' specific to this file; use `quote-maybe' universally instead.
author Aidan Kehoe <kehoea@parhasard.net>
date Sun, 15 Nov 2009 14:59:53 +0000
parents 80cd90837ac5
children 084056f46755 e0db3c197671
line wrap: on
line diff
--- a/src/eval.c	Sat Nov 14 13:33:52 2009 +0000
+++ b/src/eval.c	Sun Nov 15 14:59:53 2009 +0000
@@ -1254,6 +1254,56 @@
   return XCAR (args);
 }
 
+/* Originally, this was just a function -- but `custom' used a garden-
+   variety version, so why not make it a subr?  */
+DEFUN ("quote-maybe", Fquote_maybe, 1, 1, 0, /*
+Quote EXPR if it is not self quoting.
+
+In contrast with `quote', this is a function, not a special form; its
+argument is evaluated before `quote-maybe' is called.  It returns either
+EXPR (if it is self-quoting) or a list `(quote EXPR)' if it is not
+self-quoting.  Lists starting with the symbol `lambda' are regarded as
+self-quoting.
+*/
+       (expr))
+{
+  if ((XTYPE (expr)) == Lisp_Type_Record)
+    {
+      switch (XRECORD_LHEADER (expr)->type)
+        {
+        case lrecord_type_symbol:
+          if (NILP (expr) || (EQ (expr, Qt)) || SYMBOL_IS_KEYWORD (expr))
+            {
+              return expr;
+            }
+          break;
+        case lrecord_type_cons: 
+          if (EQ (XCAR (expr), Qlambda))
+            {
+              return expr;
+            }
+          break;
+
+        case lrecord_type_vector:
+        case lrecord_type_string:
+        case lrecord_type_compiled_function:
+        case lrecord_type_bit_vector:
+        case lrecord_type_float:
+        case lrecord_type_hash_table:
+        case lrecord_type_char_table:
+        case lrecord_type_range_table:
+        case lrecord_type_bignum:
+        case lrecord_type_ratio:
+        case lrecord_type_bigfloat:
+          return expr;
+        }
+      return list2 (Qquote, expr);
+    }
+
+  /* Fixnums and characters are self-quoting: */
+  return expr;
+}
+
 DEFUN ("function", Ffunction, 1, UNEVALLED, 0, /*
 Return the argument, without evaluating it.  `(function x)' yields `x'.
 
@@ -7260,6 +7310,7 @@
   DEFSUBR (Fprog2);
   DEFSUBR (Fsetq);
   DEFSUBR (Fquote);
+  DEFSUBR (Fquote_maybe);
   DEFSUBR (Ffunction);
   DEFSUBR (Fdefun);
   DEFSUBR (Fdefmacro);