changeset 5089:99f8ebc082d9

Make #'substring an alias of #'subseq; give the latter the byte code. src/ChangeLog addition: 2010-03-03 Aidan Kehoe <kehoea@parhasard.net> * fns.c (Fsubstring): Removed. * search.c (Freplace_match): * minibuf.c (Ftry_completion): * lisp.h: * keymap.c (ensure_meta_prefix_char_keymapp): * dired.c (user_name_completion, file_name_completion): * console-x.c (x_canonicalize_console_connection): * bytecode.c (Bsubseq): * bytecode-ops.h (subseq): Move #'substring to Lisp, as an alias for #'subseq; change all C Fsubstring() calls to Fsubseq(), change the Bsubstring bytecode to Bsubseq. Motivation; not accepting vectors in #'substring is incompatible with GNU, and Common Lisp prefers #'subseq, it has no #'substring. lisp/ChangeLog addition: 2010-03-03 Aidan Kehoe <kehoea@parhasard.net> Move byte code #o117 to #'subseq, not #'substring. Make #'substring available as an alias for #'subseq in Lisp. * bytecomp.el (79, subseq, substring): * bytecomp.el (byte-compile-subseq): New. * update-elc.el (update-elc-chop-extension): Use #'subseq, not #'substring, the latter is not yet available. * subr.el (substring): New alias, to #'subseq. man/ChangeLog addition: 2010-03-03 Aidan Kehoe <kehoea@parhasard.net> * lispref/tips.texi (Comment Tips): * lispref/text.texi (Text Properties): * lispref/strings.texi (Creating Strings): * lispref/processes.texi (Input to Processes): * lispref/functions.texi (Argument List): * lispref/extents.texi (Duplicable Extents): Move examples that used substring to using subseq; in strings.texi, do not change the examples, but document that in this XEmacs, it is an alias for subseq, and that there may be some incompatibilities if you depend on that.
author Aidan Kehoe <kehoea@parhasard.net>
date Wed, 03 Mar 2010 18:40:12 +0000
parents 207dad9e74f7
children 4a6b680a9577
files lisp/ChangeLog lisp/bytecomp.el lisp/subr.el lisp/update-elc.el man/ChangeLog man/lispref/extents.texi man/lispref/functions.texi man/lispref/processes.texi man/lispref/strings.texi man/lispref/text.texi man/lispref/tips.texi src/ChangeLog src/bytecode-ops.h src/bytecode.c src/console-x.c src/dired.c src/fns.c src/keymap.c src/lisp.h src/minibuf.c src/search.c
diffstat 21 files changed, 104 insertions(+), 61 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Tue Mar 02 13:42:37 2010 -0700
+++ b/lisp/ChangeLog	Wed Mar 03 18:40:12 2010 +0000
@@ -1,3 +1,13 @@
+2010-03-03  Aidan Kehoe  <kehoea@parhasard.net>
+
+	Move byte code #o117 to #'subseq, not #'substring.
+	Make #'substring available as an alias for #'subseq in Lisp.
+	* bytecomp.el (79, subseq, substring):
+	* bytecomp.el (byte-compile-subseq): New.
+	* update-elc.el (update-elc-chop-extension): Use #'subseq, not
+	#'substring, the latter is not yet available.
+	* subr.el (substring): New alias, to #'subseq.
+
 2010-03-02  Aidan Kehoe  <kehoea@parhasard.net>
 
 	* cl-macs.el (delete-dups): New compiler macro for this function,
--- a/lisp/bytecomp.el	Tue Mar 02 13:42:37 2010 -0700
+++ b/lisp/bytecomp.el	Wed Mar 03 18:40:12 2010 +0000
@@ -609,7 +609,7 @@
 (byte-defop  76 -1 byte-set)
 (byte-defop  77 -1 byte-fset) ; this was commented out
 (byte-defop  78 -1 byte-get)
-(byte-defop  79 -2 byte-substring)
+(byte-defop  79 -2 byte-subseq)
 (byte-defop  80 -1 byte-concat2)
 (byte-defop  81 -2 byte-concat3)
 (byte-defop  82 -3 byte-concat4)
@@ -3111,7 +3111,8 @@
 (byte-defop-compiler aref		2)
 (byte-defop-compiler get		2+1)
 (byte-defop-compiler nth		2)
-(byte-defop-compiler substring		2-3)
+(byte-defop-compiler subseq byte-compile-subseq)
+(byte-defop-compiler (substring byte-subseq) 2-3)
 (byte-defop-compiler (move-marker byte-set-marker) 2-3)
 (byte-defop-compiler set-marker		2-3)
 (byte-defop-compiler match-beginning	1)
@@ -3524,6 +3525,12 @@
      the syntax (function (lambda (...) ...)) instead."))))
   (byte-compile-two-args form))
 
+(defun byte-compile-subseq (form)
+  (byte-compile-two-or-three-args form)
+  ;; Check that XEmacs supports the substring-subseq equivalence.
+  (pushnew '(eq 'subseq (symbol-function 'substring))
+           byte-compile-checks-on-load :test #'equal))
+
 (defmacro byte-compile-funarg-n (&rest n)
   `#'(lambda (form)
        ,@(loop
--- a/lisp/subr.el	Tue Mar 02 13:42:37 2010 -0700
+++ b/lisp/subr.el	Wed Mar 03 18:40:12 2010 +0000
@@ -220,6 +220,9 @@
 (define-function 'send-string-to-terminal 'external-debugging-output)
 (define-function 'special-form-p 'special-operator-p)
 
+;; XEmacs; this is in Lisp, its bytecode now taken by subseq.
+(define-function 'substring 'subseq)
+  
 ;; XEmacs:
 (defun local-variable-if-set-p (sym buffer)
   "Return t if SYM would be local to BUFFER after it is set.
--- a/lisp/update-elc.el	Tue Mar 02 13:42:37 2010 -0700
+++ b/lisp/update-elc.el	Wed Mar 03 18:40:12 2010 +0000
@@ -137,7 +137,7 @@
 
 (defun update-elc-chop-extension (file)
   (if (string-match "\\.elc?$" file)
-      (substring file 0 (match-beginning 0))
+      (subseq file 0 (match-beginning 0))
     file))
 
 ;; we used to call packages-list-autoloads here, but it's false generality.
--- a/man/ChangeLog	Tue Mar 02 13:42:37 2010 -0700
+++ b/man/ChangeLog	Wed Mar 03 18:40:12 2010 +0000
@@ -4,6 +4,19 @@
 	lispref/customize.texi.
 	* Makefile: Remove all rules relating to custom.texi.
 
+2010-03-03  Aidan Kehoe  <kehoea@parhasard.net>
+
+	* lispref/tips.texi (Comment Tips):
+	* lispref/text.texi (Text Properties):
+	* lispref/strings.texi (Creating Strings):
+	* lispref/processes.texi (Input to Processes):
+	* lispref/functions.texi (Argument List):
+	* lispref/extents.texi (Duplicable Extents):
+	Move examples that used substring to using subseq; in
+	strings.texi, do not change the examples, but document that in
+	this XEmacs, it is an alias for subseq, and that there may be some
+	incompatibilities if you depend on that.
+
 2010-02-25  Didier Verna  <didier@xemacs.org>
 
 	The background-placement face property.
--- a/man/lispref/extents.texi	Tue Mar 02 13:42:37 2010 -0700
+++ b/man/lispref/extents.texi	Wed Mar 03 18:40:12 2010 +0000
@@ -850,8 +850,8 @@
 copied into the resulting string.
 
 @item
-When @code{substring} is called on a string, the relevant extents
-are copied into the resulting string.
+When @code{subseq} (or its alias, @code{substring}) is called on a
+string, the relevant extents are copied into the resulting string.
 
 @item
 When a duplicable extent is detached by @code{detach-extent} or string
--- a/man/lispref/functions.texi	Tue Mar 02 13:42:37 2010 -0700
+++ b/man/lispref/functions.texi	Wed Mar 03 18:40:12 2010 +0000
@@ -290,10 +290,10 @@
 arguments, you get a @code{wrong-number-of-arguments} error.
 
   It is often convenient to write a function that allows certain
-arguments to be omitted.  For example, the function @code{substring}
-accepts three arguments---a string, the start index and the end
+arguments to be omitted.  For example, the function @code{subseq}
+accepts three arguments---a sequence, the start index and the end
 index---but the third argument defaults to the @var{length} of the
-string if you omit it.  It is also convenient for certain functions to
+sequence if you omit it.  It is also convenient for certain functions to
 accept an indefinite number of arguments, as the functions @code{list}
 and @code{+} do.
 
@@ -331,8 +331,8 @@
 function to distinguish between an explicit argument of @code{nil} and
 an omitted argument.  However, the body of the function is free to
 consider @code{nil} an abbreviation for some other meaningful value.
-This is what @code{substring} does; @code{nil} as the third argument to
-@code{substring} means to use the length of the string supplied.
+This is what @code{subseq} does; @code{nil} as the third argument to
+@code{subseq} means to use the length of the sequence supplied.
 
 @cindex CL note---default optional arg
 @quotation
--- a/man/lispref/processes.texi	Tue Mar 02 13:42:37 2010 -0700
+++ b/man/lispref/processes.texi	Wed Mar 03 18:40:12 2010 +0000
@@ -650,7 +650,7 @@
 used.  If it is @code{nil}, the current buffer's process is used.
 
 Optional arguments @var{start} and @var{end} specify part of @var{string};
-see @code{substring}.
+see @code{subseq}.
 
   The function returns @code{nil}.
 
--- a/man/lispref/strings.texi	Tue Mar 02 13:42:37 2010 -0700
+++ b/man/lispref/strings.texi	Wed Mar 03 18:40:12 2010 +0000
@@ -165,6 +165,10 @@
 index @var{start} up to (but excluding) the character at the index
 @var{end}.  The first character is at index zero.
 
+In this implementation, @code{substring} is an alias for @code{subseq},
+so @var{string} can be any sequence.  In GNU Emacs, @var{string} can be
+a string or a vector, and in older XEmacs it can only be a string.
+
 @example
 @group
 (substring "abcdefg" 0 3)
--- a/man/lispref/text.texi	Tue Mar 02 13:42:37 2010 -0700
+++ b/man/lispref/text.texi	Wed Mar 03 18:40:12 2010 +0000
@@ -2118,7 +2118,7 @@
 
   Copying text between strings and buffers preserves the properties
 along with the characters; this includes such diverse functions as
-@code{substring}, @code{insert}, and @code{buffer-substring}.
+@code{subseq}, @code{insert}, and @code{buffer-substring}.
 
 @menu
 * Examining Properties::	Looking at the properties of one character.
--- a/man/lispref/tips.texi	Tue Mar 02 13:42:37 2010 -0700
+++ b/man/lispref/tips.texi	Wed Mar 03 18:40:12 2010 +0000
@@ -466,7 +466,7 @@
 @smallexample
 @group
 (setq base-version-list                 ; there was a base
-      (assoc (substring fn 0 start-vn)  ; version to which
+      (assoc (subseq fn 0 start-vn)     ; version to which
              file-version-assoc-list))  ; this looks like
                                         ; a subversion
 @end group
--- a/src/ChangeLog	Tue Mar 02 13:42:37 2010 -0700
+++ b/src/ChangeLog	Wed Mar 03 18:40:12 2010 +0000
@@ -3,6 +3,24 @@
 	* lread.c (read_atom): Signal a read error upon encountering a
 	ratio constant with a zero denominator.
 
+2010-03-03  Aidan Kehoe  <kehoea@parhasard.net>
+
+	* fns.c (Fsubstring): Removed.
+	* search.c (Freplace_match):
+	* minibuf.c (Ftry_completion):
+	* lisp.h:
+	* keymap.c (ensure_meta_prefix_char_keymapp):
+	* dired.c (user_name_completion, file_name_completion):
+	* console-x.c (x_canonicalize_console_connection):
+	* bytecode.c (Bsubseq):
+	* bytecode-ops.h (subseq):
+	Move #'substring to Lisp, as an alias for #'subseq; change all
+	C Fsubstring() calls to Fsubseq(), change the Bsubstring bytecode
+	to Bsubseq.
+
+	Motivation; not accepting vectors in #'substring is incompatible
+	with GNU, and Common Lisp prefers #'subseq, it has no #'substring.
+
 2010-03-02  Aidan Kehoe  <kehoea@parhasard.net>
 
 	* eval.c (print_multiple_value):
--- a/src/bytecode-ops.h	Tue Mar 02 13:42:37 2010 -0700
+++ b/src/bytecode-ops.h	Wed Mar 03 18:40:12 2010 +0000
@@ -57,7 +57,7 @@
   OPCODE (set,    			0114)
   OPCODE (fset,   			0115)
   OPCODE (get,    			0116)
-  OPCODE (substring, 			0117)
+  OPCODE (subseq, 			0117)
   OPCODE (concat2, 			0120)
   OPCODE (concat3, 			0121)
   OPCODE (concat4, 			0122)
--- a/src/bytecode.c	Tue Mar 02 13:42:37 2010 -0700
+++ b/src/bytecode.c	Wed Mar 03 18:40:12 2010 +0000
@@ -1573,11 +1573,11 @@
 	break;
       }
 
-    case Bsubstring:
+    case Bsubseq:
       {
 	Lisp_Object arg2 = POP;
 	Lisp_Object arg1 = POP;
-	TOP_LVALUE = Fsubstring (TOP, arg1, arg2);
+	TOP_LVALUE = Fsubseq (TOP, arg1, arg2);
 	break;
       }
 
--- a/src/console-x.c	Tue Mar 02 13:42:37 2010 -0700
+++ b/src/console-x.c	Wed Mar 03 18:40:12 2010 +0000
@@ -240,7 +240,7 @@
 
     split_up_display_spec (connection, &hostname_length, &display_length,
 			   &screen_length);
-    hostname = Fsubstring (connection, Qzero, make_int (hostname_length));
+    hostname = Fsubseq (connection, Qzero, make_int (hostname_length));
     hostname = canonicalize_host_name (hostname);
     connection = concat2 (hostname,
 			  make_string (XSTRING_DATA (connection)
--- a/src/dired.c	Tue Mar 02 13:42:37 2010 -0700
+++ b/src/dired.c	Wed Mar 03 18:40:12 2010 +0000
@@ -508,7 +508,7 @@
     return bestmatch;
   if (matchcount == 1 && bestmatchsize == file_name_length)
     return Qt;
-  return Fsubstring (bestmatch, Qzero, make_int (bestmatchsize));
+  return Fsubseq (bestmatch, Qzero, make_int (bestmatchsize));
 }
 
 
@@ -772,7 +772,7 @@
     return bestmatch;
   if (matchcount == 1 && bestmatchsize == user_name_length)
     return Qt;
-  return Fsubstring (bestmatch, Qzero, make_int (bestmatchsize));
+  return Fsubseq (bestmatch, Qzero, make_int (bestmatchsize));
 }
 
 
--- a/src/fns.c	Tue Mar 02 13:42:37 2010 -0700
+++ b/src/fns.c	Wed Mar 03 18:40:12 2010 +0000
@@ -947,30 +947,6 @@
   return arg;
 }
 
-DEFUN ("substring", Fsubstring, 2, 3, 0, /*
-Return the substring of STRING starting at START and ending before END.
-END may be nil or omitted; then the substring runs to the end of STRING.
-If START or END is negative, it counts from the end.
-Relevant parts of the string-extent-data are copied to the new string.
-*/
-       (string, start, end))
-{
-  Charcount ccstart, ccend;
-  Bytecount bstart, blen;
-  Lisp_Object val;
-
-  CHECK_STRING (string);
-  CHECK_INT (start);
-  get_string_range_char (string, start, end, &ccstart, &ccend,
-			 GB_HISTORICAL_STRING_BEHAVIOR);
-  bstart = string_index_char_to_byte (string, ccstart);
-  blen = string_offset_char_to_byte_len (string, bstart, ccend - ccstart);
-  val = make_string (XSTRING_DATA (string) + bstart, blen);
-  /* Copy any applicable extent information into the new string. */
-  copy_string_extents (val, string, 0, bstart, blen);
-  return val;
-}
-
 DEFUN ("subseq", Fsubseq, 2, 3, 0, /*
 Return the subsequence of SEQUENCE starting at START and ending before END.
 END may be omitted; then the subsequence runs to the end of SEQUENCE.
@@ -983,11 +959,25 @@
 {
   EMACS_INT len, s, e;
 
+  if (STRINGP (sequence))
+    {
+      Charcount ccstart, ccend;
+      Bytecount bstart, blen;
+      Lisp_Object val;
+
+      CHECK_INT (start);
+      get_string_range_char (sequence, start, end, &ccstart, &ccend,
+                             GB_HISTORICAL_STRING_BEHAVIOR);
+      bstart = string_index_char_to_byte (sequence, ccstart);
+      blen = string_offset_char_to_byte_len (sequence, bstart, ccend - ccstart);
+      val = make_string (XSTRING_DATA (sequence) + bstart, blen);
+      /* Copy any applicable extent information into the new string. */
+      copy_string_extents (val, sequence, 0, bstart, blen);
+      return val;
+    }
+
   CHECK_SEQUENCE (sequence);
 
-  if (STRINGP (sequence))
-    return Fsubstring (sequence, start, end);
-
   len = XINT (Flength (sequence));
 
   CHECK_INT (start);
@@ -4796,7 +4786,6 @@
   DEFSUBR (Fcopy_sequence);
   DEFSUBR (Fcopy_alist);
   DEFSUBR (Fcopy_tree);
-  DEFSUBR (Fsubstring);
   DEFSUBR (Fsubseq);
   DEFSUBR (Fnthcdr);
   DEFSUBR (Fnth);
--- a/src/keymap.c	Tue Mar 02 13:42:37 2010 -0700
+++ b/src/keymap.c	Wed Mar 03 18:40:12 2010 +0000
@@ -1731,7 +1731,7 @@
   if (indx == 0)
     new_keys = keys;
   else if (STRINGP (keys))
-    new_keys = Fsubstring (keys, Qzero, make_int (indx));
+    new_keys = Fsubseq (keys, Qzero, make_int (indx));
   else if (VECTORP (keys))
     {
       new_keys = make_vector (indx, Qnil);
--- a/src/lisp.h	Tue Mar 02 13:42:37 2010 -0700
+++ b/src/lisp.h	Wed Mar 03 18:40:12 2010 +0000
@@ -5652,7 +5652,7 @@
 EXFUN (Fsort, 2);
 EXFUN (Fstring_equal, 2);
 EXFUN (Fstring_lessp, 2);
-EXFUN (Fsubstring, 3);
+EXFUN (Fsubseq, 3);
 EXFUN (Fvalid_plist_p, 1);
 
 Lisp_Object list_sort (Lisp_Object, Lisp_Object,
--- a/src/minibuf.c	Tue Mar 02 13:42:37 2010 -0700
+++ b/src/minibuf.c	Wed Mar 03 18:40:12 2010 +0000
@@ -513,7 +513,7 @@
     return Qt;
 
   /* Else extract the part in which all completions agree */
-  return Fsubstring (bestmatch, Qzero, make_int (bestmatchsize));
+  return Fsubseq (bestmatch, Qzero, make_int (bestmatchsize));
 }
 
 
--- a/src/search.c	Tue Mar 02 13:42:37 2010 -0700
+++ b/src/search.c	Wed Mar 03 18:40:12 2010 +0000
@@ -2801,8 +2801,8 @@
       Lisp_Object before, after;
 
       speccount = specpdl_depth ();
-      before = Fsubstring (string, Qzero, make_int (search_regs.start[sub]));
-      after = Fsubstring (string, make_int (search_regs.end[sub]), Qnil);
+      before = Fsubseq (string, Qzero, make_int (search_regs.start[sub]));
+      after = Fsubseq (string, make_int (search_regs.end[sub]), Qnil);
 
       /* Do case substitution into REPLACEMENT if desired.  */
       if (NILP (literal))
@@ -2888,13 +2888,12 @@
 		  Lisp_Object literal_text = Qnil;
 		  Lisp_Object substring = Qnil;
 		  if (literal_end != literal_start)
-		    literal_text = Fsubstring (replacement,
-					       make_int (literal_start),
-					       make_int (literal_end));
+		    literal_text = Fsubseq (replacement,
+                                            make_int (literal_start),
+                                            make_int (literal_end));
 		  if (substart >= 0 && subend != substart)
-		    substring = Fsubstring (string,
-					    make_int (substart),
-					    make_int (subend));
+		    substring = Fsubseq (string, make_int (substart),
+                                         make_int (subend));
 		  if (!NILP (literal_text) || !NILP (substring))
 		    accum = concat3 (accum, literal_text, substring);
 		  literal_start = strpos + 1;
@@ -2903,9 +2902,9 @@
 
 	  if (strpos != literal_start)
 	    /* some literal text at end to be inserted */
-	    replacement = concat2 (accum, Fsubstring (replacement,
-						      make_int (literal_start),
-						      make_int (strpos)));
+	    replacement = concat2 (accum, Fsubseq (replacement,
+                                                   make_int (literal_start),
+                                                   make_int (strpos)));
 	  else
 	    replacement = accum;
 	}