diff src/buffer.c @ 5914:bd4d2c8ef9cc

Use the existing C-level line number cache within #'line-number. src/ChangeLog addition: 2015-05-15 Aidan Kehoe <kehoea@parhasard.net> * buffer.c: * buffer.c (Fline_number): New C implementation, using the line number cache of line-number.c, with a new optional BUFFER argument. * buffer.c (syms_of_buffer): Make it available to Lisp. * line-number.c (buffer_line_number): New argument, RESPECT-NARROWING, describing whether to count from the beginning of the visible region or from the beginning of the buffer. * line-number.h: * line-number.h (buffer_line_number): Update its declaration. * redisplay.c (window_line_number): Call it with the new argument. lisp/ChangeLog addition: 2015-05-15 Aidan Kehoe <kehoea@parhasard.net> * simple.el: * simple.el (line-number): Moved to buffer.c; we have an existing line number cache in C, it's a shame not to have it available.
author Aidan Kehoe <kehoea@parhasard.net>
date Fri, 15 May 2015 18:11:47 +0100
parents 8139bdf8db04
children
line wrap: on
line diff
--- a/src/buffer.c	Mon May 11 18:04:58 2015 +0100
+++ b/src/buffer.c	Fri May 15 18:11:47 2015 +0100
@@ -85,6 +85,7 @@
 #include "file-coding.h"
 #include "frame-impl.h"
 #include "insdel.h"
+#include "line-number.h"
 #include "lstream.h"
 #include "process.h"            /* for kill_buffer_processes */
 #ifdef REGION_CACHE_NEEDS_WORK
@@ -1746,7 +1747,28 @@
 
   return Qnil;
 }
-
+
+/* It was a shame to have the line number cache around and not used from
+   Lisp, so move this here from simple.el. */
+
+DEFUN ("line-number", Fline_number, 0, 3, 0, /*
+Return the line number of POSITION within BUFFER.
+
+POSITION defaults to point. If RESPECT-NARROWING is non-nil, then the narrowed
+line number is returned; otherwise, the absolute line number is returned.  The
+returned line can always be given to `goto-line' to get back to the current
+line.
+*/
+       (position, respect_narrowing, buffer_))
+{
+  struct buffer *buf = decode_buffer (buffer_, 0);
+  Charbpos pos = (NILP (position) ? BUF_PT (buf) :
+		  get_buffer_pos_char (buf, position, GB_COERCE_RANGE));
+
+  return make_fixnum (buffer_line_number (buf, pos, 1,
+                                          !NILP (respect_narrowing)) + 1);
+}
+
 #ifdef MEMORY_USAGE_STATS
 
 struct buffer_stats
@@ -1952,6 +1974,7 @@
   DEFSUBR (Fbarf_if_buffer_read_only);
   DEFSUBR (Fbury_buffer);
   DEFSUBR (Fkill_all_local_variables);
+  DEFSUBR (Fline_number);
 #if defined (DEBUG_XEMACS) && defined (MULE)
   DEFSUBR (Fbuffer_char_byte_converion_info);
   DEFSUBR (Fstring_char_byte_converion_info);