    Selected characters/rectangle statistics line feedback

    Based on Arne Forlie's Selected character count patch

    http://sourceforge.net/tracker/index.php?func=detail&aid=1043759&group_id=11005&atid=311005
	    [ 1043759 ] Selected character count

    This patch implements a continuously updated count of
    selected characters in the status line.
    It only works for normal selections (not for
    rectangular selections) and it doesn't work when
    quadruple clicking to select the whole file.

    It is a response to feature request 1040294, which
    asked for something similar.

    Augmented to show rectangle dimensions when a rectangular selection is
    active.

diff -ur nedit_official nedit_mod
diff -ur nedit_official/source/window.c nedit_mod/source/window.c
--- nedit_official/source/window.c	2007-10-02 17:47:10.000000000 +0200
+++ nedit_mod/source/window.c	2007-10-17 18:43:07.000000000 +0200
@@ -2734,7 +2734,55 @@
                 format, window->buffer->length);
         sprintf(slinecol, "L: ---  C: ---");
     } else {
-        sprintf(slinecol, "L: %d  C: %d", line, colNum);
+        int start, end, isRect, rectStart, rectEnd, bytesSelected = 0;
+        if (BufGetSelectionPos(window->buffer, &start, &end, &isRect, &rectStart, &rectEnd)) {
+            bytesSelected = isRect ? 0 : end - start;
+        }
+        else {
+            isRect = 0;
+        }
+
+        if (bytesSelected > 0) {
+            sprintf(slinecol, "[%d]  L: %d  C: %d", bytesSelected, line, colNum);
+        } else if (isRect) {
+            /* count lines in the rectangle from start to end */
+            int nlines = 1;
+            const textBuffer *buffer = window->buffer;
+            const char *buf = buffer->buf;
+            const char *txtbeg, *txtend;
+            int len = end - start;
+            if (start < buffer->gapStart) {
+                /* rectangle is before or spans the buffer gap */
+                txtbeg = buf + start;
+                if (start + len <= buffer->gapStart) {
+                    /* all before the gap - nothing to count after the gap */
+                    txtend = txtbeg + len;
+                    len = 0;
+                }
+                else {
+                    /* bridges the gap - count upto the gap */
+                    txtend = buf + buffer->gapStart;
+                    /* and adjust settings for post-gap count */
+                    len -= buffer->gapStart - start;
+                    start = buffer->gapStart;
+                }
+                for (; txtbeg < txtend; txtbeg++)
+                    if (*txtbeg == '\n')
+                        nlines++;   /* count newlines before the gap */
+            }
+            if (len > 0) {
+                /* stuff to count after the gap */
+                txtbeg = buf + start + buffer->gapEnd - buffer->gapStart;
+                txtend = txtbeg + len;
+                for (; txtbeg < txtend; txtbeg++)
+                    if (*txtbeg == '\n')
+                        nlines++;
+            }
+            sprintf(slinecol, "[%dx%d] L: %d  C: %d",
+                    rectEnd-rectStart, nlines, line, colNum);
+        } else {
+            sprintf(slinecol, "L: %d  C: %d", line, colNum);
+        }
         if (window->showLineNumbers)
             sprintf(string, "%s%s%s byte %d of %d", window->path,
                     window->filename, format, pos, 
