From xemacs-m  Fri Mar 21 02:08:34 1997
Received: from venus.Sun.COM (venus.Sun.COM [192.9.25.5])
	by xemacs.org (8.8.5/8.8.5) with SMTP id CAA00809
	for <xemacs-beta@xemacs.org>; Fri, 21 Mar 1997 02:08:33 -0600 (CST)
Received: from Eng.Sun.COM ([129.146.1.25]) by venus.Sun.COM (SMI-8.6/mail.byaddr) with SMTP id AAA03677; Fri, 21 Mar 1997 00:08:02 -0800
Received: from kindra.eng.sun.com by Eng.Sun.COM (SMI-8.6/SMI-5.3)
	id AAA07934; Fri, 21 Mar 1997 00:08:01 -0800
Received: from xemacs.eng.sun.com by kindra.eng.sun.com (SMI-8.6/SMI-SVR4)
	id AAA19167; Fri, 21 Mar 1997 00:08:00 -0800
Received: by xemacs.eng.sun.com (SMI-8.6/SMI-SVR4)
	id AAA07719; Fri, 21 Mar 1997 00:07:59 -0800
Date: Fri, 21 Mar 1997 00:07:59 -0800
Message-Id: <199703210807.AAA07719@xemacs.eng.sun.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
From: Martin Buchholz <mrb@Eng.Sun.COM>
To: Steven L Baur <steve@miranova.com>
Cc: xemacs-beta@xemacs.org
Subject: PATCH: Re: char-before (Re: XEmacs 19.15-b102 is released)
In-Reply-To: <m2lo7hlnqi.fsf@altair.xemacs.org>
References: <199703210649.PAA08954@mikan.jaist.ac.jp>
	<m2lo7hlnqi.fsf@altair.xemacs.org>
Reply-To: Martin Buchholz <mrb@Eng.Sun.COM>

>>>>> "sb" == Steven L Baur <steve@miranova.com> writes:

sb> MORIOKA Tomohiko writes:
>> char-before: a built-in function.

>> Return character in current buffer preceding position POS.
>> POS is an integer or a buffer pointer.
>> If POS is out of range, the value is nil.
>> If `enable-multibyte-characters' is nil or POS is not at character boundary,
>> multi-byte form is ignored, and only one byte preceding POS
>> is returned as a character.

>> (char-before POS)

sb> O.K.  Do I need to make a dummy definition of
sb> enable-multibyte-characters for compatibility?  It sounds too
sb> dangerous to actually implement.

I don't grok this enable-multibyte-character stuff, but it seems to me
that char-before and char-after should be primitive functions, for
symmettry, and that the POS argument be optional, defaulting to point.

In other words, this patch makes char-after and char-before what
preceding-char and following-char should have been all along.

The best thing Ben did in his massive Mule rewrite was to make byte
positions completely inaccessible from the lisp level.  It is
impossible to end up in the middle of a character.  All lisp
operations are character, not byte, oriented.

Steven, I'd like this patch applied.  (But I haven't looked at the
gnumule implementation).

Martin

--- src/editfns.c.old
+++ src/editfns.c
@@ -631,20 +629,42 @@
   return Qnil;
 }
 
-DEFUN ("char-after", Fchar_after, 1, 2, 0, /*
+DEFUN ("char-after", Fchar_after, 0, 2, 0, /*
 Return character in BUFFER at position POS.
 POS is an integer or a buffer pointer.
 If POS is out of range, the value is nil.
 If BUFFER is nil, the current buffer is assumed.
+if POS is nil, the value of point is assumed.
 */
        (pos, buffer))
 {
   struct buffer *b = decode_buffer (buffer, 1);
-  Bufpos n = get_buffer_pos_char (b, pos, GB_NO_ERROR_IF_BAD);
+  Bufpos n = (NILP (pos) ? BUF_PT (b) :
+	      get_buffer_pos_char (b, pos, GB_NO_ERROR_IF_BAD));
 
   if (n < 0 || n == BUF_ZV (b))
     return Qnil;
-  return (make_char (BUF_FETCH_CHAR (b, n)));
+  return make_char (BUF_FETCH_CHAR (b, n));
+}
+
+DEFUN ("char-before", Fchar_before, 0, 2, 0, /*
+Return character in BUFFER before position POS.
+POS is an integer or a buffer pointer.
+If POS is out of range, the value is nil.
+If BUFFER is nil, the current buffer is assumed.
+if POS is nil, the value of point is assumed.
+*/
+       (pos, buffer))
+{
+  struct buffer *b = decode_buffer (buffer, 1);
+  Bufpos n = ((NILP (pos) ? BUF_PT (b) :
+	       get_buffer_pos_char (b, pos, GB_NO_ERROR_IF_BAD)));
+
+  n--;
+  
+  if (n < BUF_BEGV (b))
+    return Qnil;
+  return make_char (BUF_FETCH_CHAR (b, n));
 }
 
 
@@ -2086,6 +2106,7 @@
   DEFSUBR (Ffollowing_char);
   DEFSUBR (Fpreceding_char);
   DEFSUBR (Fchar_after);
+  DEFSUBR (Fchar_before);
   DEFSUBR (Finsert);
   DEFSUBR (Finsert_string);
   DEFSUBR (Finsert_before_markers);

