[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Alternative to substring-no-properties
From: |
Tak Ota |
Subject: |
Re: Alternative to substring-no-properties |
Date: |
Tue, 26 Mar 2002 15:19:57 -0800 (PST) |
Mon, 28 Jan 2002 08:36:15 -0700 (MST): Richard Stallman <address@hidden> wrote:
> It would be cleaner to make it a separate C function
> rather than add a new arg to substring.
I saw the following implementation and it made me wonder why it was
cleaner to have separate C function instead of adding one optional
argument to `substring'.
2002-03-26 Richard M. Stallman <address@hidden>
* fns.c (Fsubstring_no_properties): New function.
The implementation of Fsubstring_no_properties is slightly different
from the implementation of Fsubstring since Fsubstring can accept a
vector in place of a string.
Even if the difference was corrected, it is definitely forking the
very similar implementation into two different ones and to maintain
both.
IMHO the following patch Juanma Barranquero provided before looks
much cleaner.
-Tak
Index: fns.c
===================================================================
RCS file: /cvsroot/emacs/emacs/src/fns.c,v
retrieving revision 1.303
diff -u -r1.303 fns.c
--- fns.c 13 Nov 2001 11:55:47 -0000 1.303
+++ fns.c 28 Jan 2002 10:26:24 -0000
@@ -1165,15 +1165,16 @@
return alist;
}
-DEFUN ("substring", Fsubstring, Ssubstring, 2, 3, 0,
+DEFUN ("substring", Fsubstring, Ssubstring, 2, 4, 0,
doc: /* Return a substring of STRING, starting at index FROM and ending
before TO.
TO may be nil or omitted; then the substring runs to the end of STRING.
If FROM or TO is negative, it counts from the end.
+Properties are copied unless NO-PROPERTIES is non-nil.
This function allows vectors as well as strings. */)
- (string, from, to)
+ (string, from, to, no_properties)
Lisp_Object string;
- register Lisp_Object from, to;
+ register Lisp_Object from, to, no_properties;
{
Lisp_Object res;
int size;
@@ -1226,8 +1227,9 @@
res = make_specified_string (XSTRING (string)->data + from_byte,
to_char - from_char, to_byte - from_byte,
STRING_MULTIBYTE (string));
- copy_text_properties (make_number (from_char), make_number (to_char),
- string, make_number (0), res, Qnil);
+ if (NILP (no_properties))
+ copy_text_properties (make_number (from_char), make_number (to_char),
+ string, make_number (0), res, Qnil);
}
else
res = Fvector (to_char - from_char,
- Re: Alternative to substring-no-properties,
Tak Ota <=