Make read-symbol-positions-list more accurate
[bpt/emacs.git] / src / lread.c
index f937fa3..ef1b1a8 100644 (file)
@@ -2327,8 +2327,7 @@ read_integer (Lisp_Object readcharfun, EMACS_INT radix)
          c = READCHAR;
        }
 
-      if (c >= 0)
-       UNREAD (c);
+      UNREAD (c);
       *p = '\0';
     }
 
@@ -2583,8 +2582,7 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
              nskip *= 10;
              nskip += c - '0';
            }
-         if (c >= 0)
-           UNREAD (c);
+         UNREAD (c);
 
          if (load_force_doc_strings
              && (EQ (readcharfun, Qget_file_char)
@@ -2660,7 +2658,17 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
        {
          uninterned_symbol = 1;
          c = READCHAR;
-         goto default_label;
+         if (!(c > 040
+               && c != 0x8a0
+               && (c >= 0200
+                   || strchr ("\"';()[]#`,", c) == NULL)))
+           {
+             /* No symbol character follows, this is the empty
+                symbol.  */
+             UNREAD (c);
+             return Fmake_symbol (build_string (""));
+           }
+         goto read_symbol;
        }
       /* Reader forms that can reuse previously read objects.  */
       if (c >= '0' && c <= '9')
@@ -2841,7 +2849,7 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
        next_char = READCHAR;
        ok = (next_char <= 040
              || (next_char < 0200
-                 && (strchr ("\"';()[]#?`,.", next_char))));
+                 && strchr ("\"';()[]#?`,.", next_char) != NULL));
        UNREAD (next_char);
        if (ok)
          return make_number (c);
@@ -2966,11 +2974,6 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
            /* Otherwise, READ_BUFFER contains only ASCII.  */
          }
 
-       /* We want readchar_count to be the number of characters, not
-          bytes.  Hence we adjust for multibyte characters in the
-          string.  ... But it doesn't seem to be necessary, because
-          READCHAR *does* read multibyte characters from buffers. */
-       /* readchar_count -= (p - read_buffer) - nchars; */
        if (read_pure)
          return make_pure_string (read_buffer, nchars, p - read_buffer,
                                   (force_multibyte
@@ -2987,7 +2990,7 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
 
        if (next_char <= 040
            || (next_char < 0200
-               && (strchr ("\"';([#?`,", next_char))))
+               && strchr ("\"';([#?`,", next_char) != NULL))
          {
            *pch = c;
            return Qnil;
@@ -3002,9 +3005,12 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
       if (c <= 040) goto retry;
       if (c == 0x8a0) /* NBSP */
        goto retry;
+
+    read_symbol:
       {
        char *p = read_buffer;
        int quoted = 0;
+       int start_position = readchar_count - 1;
 
        {
          char *end = read_buffer + read_buffer_size;
@@ -3035,10 +3041,11 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
              else
                *p++ = c;
              c = READCHAR;
-           } while (c > 040
-                    && c != 0x8a0 /* NBSP */
-                    && (c >= 0200
-                        || !(strchr ("\"';()[]#`,", c))));
+           }
+         while (c > 040
+                && c != 0x8a0 /* NBSP */
+                && (c >= 0200
+                    || strchr ("\"';()[]#`,", c) == NULL));
 
          if (p == end)
            {
@@ -3051,8 +3058,7 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
              end = read_buffer + read_buffer_size;
            }
          *p = 0;
-         if (c >= 0)
-           UNREAD (c);
+         UNREAD (c);
        }
 
        if (!quoted && !uninterned_symbol)
@@ -3080,12 +3086,7 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
          if (EQ (Vread_with_symbol_positions, Qt)
              || EQ (Vread_with_symbol_positions, readcharfun))
            Vread_symbol_positions_list =
-             /* Kind of a hack; this will probably fail if characters
-                in the symbol name were escaped.  Not really a big
-                deal, though.  */
-             Fcons (Fcons (result,
-                           make_number (readchar_count
-                                        - XFASTINT (Flength (Fsymbol_name (result))))),
+             Fcons (Fcons (result, make_number (start_position)),
                     Vread_symbol_positions_list);
          return result;
        }
@@ -4000,9 +4001,7 @@ defsubr (struct Lisp_Subr *sname)
 
 #ifdef NOTDEF /* use fset in subr.el now */
 void
-defalias (sname, string)
-     struct Lisp_Subr *sname;
-     char *string;
+defalias (struct Lisp_Subr *sname, char *string)
 {
   Lisp_Object sym;
   sym = intern (string);
@@ -4420,9 +4419,11 @@ The remaining ENTRIES in the alist element describe the functions and
 variables defined in that file, the features provided, and the
 features required.  Each entry has the form `(provide . FEATURE)',
 `(require . FEATURE)', `(defun . FUNCTION)', `(autoload . SYMBOL)',
-`(defface . SYMBOL)', or `(t . SYMBOL)'.  In addition, an entry `(t
-. SYMBOL)' may precede an entry `(defun . FUNCTION)', and means that
-SYMBOL was an autoload before this file redefined it as a function.
+`(defface . SYMBOL)', or `(t . SYMBOL)'.  Entries like `(t . SYMBOL)'
+may precede a `(defun . FUNCTION)' entry, and means that SYMBOL was an
+autoload before this file redefined it as a function.  In addition,
+entries may also be single symbols, which means that SYMBOL was
+defined by `defvar' or `defconst'.
 
 During preloading, the file name recorded is relative to the main Lisp
 directory.  These file names are converted to absolute at startup.  */);
@@ -4510,9 +4511,11 @@ to load.  See also `load-dangerous-libraries'.  */);
   staticpro (&Qlexical_binding);
   DEFVAR_LISP ("lexical-binding", Vlexical_binding,
               doc: /* If non-nil, use lexical binding when evaluating code.
-This only applies to code evaluated by `eval-buffer' and `eval-region'.
-This variable is automatically set from the file variables of an interpreted
-  Lisp file read using `load'.  */);
+This applies to code evaluated by `eval-buffer' and `eval-region' and
+other commands that call these functions, like `eval-defun' and
+the like.
+This variable is automatically set from the file variables of an
+interpreted Lisp file read using `load'.  */);
   Fmake_variable_buffer_local (Qlexical_binding);
 
   DEFVAR_LISP ("eval-buffer-list", Veval_buffer_list,