diff src/editfns.c @ 40:7e54bd776075 r19-15b103

Import from CVS: tag r19-15b103
author cvs
date Mon, 13 Aug 2007 08:54:25 +0200
parents e04119814345
children 56c54cf7c5b6
line wrap: on
line diff
--- a/src/editfns.c	Mon Aug 13 08:54:02 2007 +0200
+++ b/src/editfns.c	Mon Aug 13 08:54:25 2007 +0200
@@ -631,20 +631,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 +2108,7 @@
   DEFSUBR (Ffollowing_char);
   DEFSUBR (Fpreceding_char);
   DEFSUBR (Fchar_after);
+  DEFSUBR (Fchar_before);
   DEFSUBR (Finsert);
   DEFSUBR (Finsert_string);
   DEFSUBR (Finsert_before_markers);