let all function types return NO_TAG
[nedit-bw.git] / enhanced-update-selectionCount.patch
bloba27315beda18662c8d6fd91e4ae29e7c2e0c1d0a
1 ---
3 source/window.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++---
4 1 files changed, 53 insertions(+), 3 deletions(-)
6 diff --quilt old/source/window.c new/source/window.c
7 --- old/source/window.c
8 +++ new/source/window.c
9 @@ -2759,11 +2759,11 @@ static int updateLineNumDisp(WindowInfo*
10 ** Update the optional statistics line.
12 void UpdateStatsLine(WindowInfo *window)
14 int line, pos, colNum;
15 - char *string, *format, slinecol[32];
16 + char *string, *format, slinecol[64];
17 Widget statW = window->statsLine;
18 XmString xmslinecol;
19 #ifdef SGI_CUSTOM
20 char *sleft, *smid, *sright;
21 #endif
22 @@ -2785,17 +2785,67 @@ void UpdateStatsLine(WindowInfo *window)
23 sprintf(string, "%s%s%s %d bytes", window->path, window->filename,
24 format, window->buffer->length);
25 sprintf(slinecol, "L: --- C: ---");
26 } else {
27 int start, end, isRect, rectStart, rectEnd, bytesSelected = 0;
29 if (BufGetSelectionPos(window->buffer, &start, &end, &isRect, &rectStart, &rectEnd)) {
30 bytesSelected = isRect ? 0 : end - start;
31 + } else {
32 + isRect = 0;
35 if (bytesSelected > 0) {
36 - sprintf(slinecol, "[%d] L: %d C: %2d", bytesSelected, line, colNum);
37 + snprintf(slinecol, sizeof(slinecol), "[%d] L: %d C: %2d",
38 + bytesSelected, line, colNum);
39 + } else if (isRect) {
40 + /* count lines in the rectangle from start to end */
41 + int nlines = 1;
42 + const textBuffer *buffer = window->buffer;
43 + const char *buf = buffer->buf;
44 + const char *txtbeg, *txtend;
45 + int len = end - start;
47 + if (start < buffer->gapStart) {
48 + /* rectangle is before or spans the buffer gap */
49 + txtbeg = buf + start;
51 + if (start + len <= buffer->gapStart) {
52 + /* all before the gap - nothing to count after the gap */
53 + txtend = txtbeg + len;
54 + len = 0;
55 + } else {
56 + /* bridges the gap - count upto the gap */
57 + txtend = buf + buffer->gapStart;
58 + /* and adjust settings for post-gap count */
59 + len -= buffer->gapStart - start;
60 + start = buffer->gapStart;
61 + }
63 + for (; txtbeg < txtend; txtbeg++) {
64 + if (*txtbeg == '\n') {
65 + nlines++; /* count newlines before the gap */
66 + }
67 + }
68 + }
70 + if (len > 0) {
71 + /* stuff to count after the gap */
72 + txtbeg = buf + start + buffer->gapEnd - buffer->gapStart;
73 + txtend = txtbeg + len;
75 + for (; txtbeg < txtend; txtbeg++) {
76 + if (*txtbeg == '\n') {
77 + nlines++;
78 + }
79 + }
80 + }
82 + snprintf(slinecol, sizeof(slinecol), "[%dx%d] L: %d C: %d",
83 + rectEnd - rectStart, nlines, line, colNum);
84 } else {
85 - sprintf(slinecol, "L: %d C: %2d", line, colNum);
86 + snprintf(slinecol, sizeof(slinecol), "L: %d C: %2d", line, colNum);
88 if (window->showLineNumbers)
89 sprintf(string, "%s%s%s byte %d of %d", window->path,
90 window->filename, format, pos,
91 window->buffer->length);