push up read_from_pipes.patch
[nedit-bw.git] / extended-paragraph.patch
blobeae5ef7cb65a0270d9d26a7d4ef9839593e54f4b
1 ---
3 source/text.c | 146 +++++++++++++++++++++++++++++++++++++++++-----------------
4 1 files changed, 105 insertions(+), 41 deletions(-)
6 diff --quilt old/source/text.c new/source/text.c
7 --- old/source/text.c
8 +++ new/source/text.c
9 @@ -222,14 +222,14 @@ static void simpleInsertAtCursor(Widget
10 int allowPendingDelete);
11 static int pendingSelection(Widget w);
12 static int deletePendingSelection(Widget w, XEvent *event);
13 static int deleteEmulatedTab(Widget w, XEvent *event);
14 static void selectWord(Widget w, int pointerX);
15 -static int spanForward(textBuffer *buf, int startPos, char *searchChars,
16 - int ignoreSpace, int *foundPos);
17 -static int spanBackward(textBuffer *buf, int startPos, char *searchChars, int
18 - ignoreSpace, int *foundPos);
19 +static int spanForward(textBuffer *buf, int startPos, const char *searchChars,
20 + int ignoreSpace, int *foundPos);
21 +static int spanBackward(textBuffer *buf, int startPos, const char *searchChars,
22 + int ignoreSpace, int *foundPos);
23 static void selectLine(Widget w);
24 static int startOfWord(TextWidget w, int pos);
25 static int endOfWord(TextWidget w, int pos);
26 static void checkAutoScroll(TextWidget w, int x, int y);
27 static void endDrag(Widget w);
28 @@ -2713,69 +2713,133 @@ static void backwardWordAP(Widget w, XEv
29 checkMoveSelectionChange(w, event, insertPos, args, nArgs);
30 checkAutoShowInsertPos(w);
31 callCursorMovementCBs(w, event);
34 +static Boolean lineIsBlank(textBuffer *buf, int pos, int *start)
36 + static const char whiteChars[] = " \t";
37 + char c;
39 + pos = BufStartOfLine(buf, pos);
40 + *start = pos;
42 + while (pos < buf->length) {
43 + c = BufGetCharacter(buf, pos);
45 + /* we reached the end of a blank line */
46 + if ('\n' == c) {
47 + return True;
48 + }
50 + /* check for any blank character */
51 + if (NULL != strchr(whiteChars, c)) {
52 + pos++;
53 + } else {
54 + /* this line is a not a blank line */
55 + return False;
56 + }
57 + }
59 + /* no end of line and no non blank character */
60 + return True;
63 +static Boolean nextLineIsBlank(textBuffer *buf, int pos, int *next)
65 + /* get start of next line */
66 + pos = min(BufEndOfLine(buf, pos) + 1, buf->length);
68 + if (pos == buf->length) {
69 + /* buffer without last end-of-line */
70 + *next = pos;
71 + return False;
72 + } else {
73 + return lineIsBlank(buf, pos, next);
74 + }
77 +static Boolean prevLineIsBlank(textBuffer *buf, int pos, int *prev)
79 + /* get end of prev line */
80 + pos = max(BufStartOfLine(buf, pos) - 1, 0);
82 + return lineIsBlank(buf, pos, prev);
85 static void forwardParagraphAP(Widget w, XEvent *event, String *args,
86 - Cardinal *nArgs)
87 + Cardinal *nArgs)
89 textDisp *textD = ((TextWidget)w)->text.textD;
90 int pos, insertPos = TextDGetInsertPosition(textD);
91 textBuffer *buf = textD->buffer;
92 - char c;
93 - static char whiteChars[] = " \t";
94 int silent = hasKey("nobell", args, nArgs);
96 cancelDrag(w);
98 + /* check if we are at the end of the file, than return */
99 if (insertPos == buf->length) {
100 ringIfNecessary(silent, w);
101 - return;
102 + return;
104 - pos = min(BufEndOfLine(buf, insertPos)+1, buf->length);
106 + /* need to skip current paragraph? */
107 + if (!lineIsBlank(buf, insertPos, &pos)) {
108 + while (pos < buf->length) {
109 + if (nextLineIsBlank(buf, pos, &pos)) {
110 + break;
115 + /* skip all blank lines */
116 while (pos < buf->length) {
117 - c = BufGetCharacter(buf, pos);
118 - if (c == '\n')
119 - break;
120 - if (strchr(whiteChars, c) != NULL)
121 - pos++;
122 - else
123 - pos = min(BufEndOfLine(buf, pos)+1, buf->length);
124 + if (!nextLineIsBlank(buf, pos, &pos)) {
125 + break;
128 - TextDSetInsertPosition(textD, min(pos+1, buf->length));
130 + TextDSetInsertPosition(textD, min(pos, buf->length));
131 checkMoveSelectionChange(w, event, insertPos, args, nArgs);
132 checkAutoShowInsertPos(w);
133 callCursorMovementCBs(w, event);
136 static void backwardParagraphAP(Widget w, XEvent *event, String *args,
137 - Cardinal *nArgs)
138 + Cardinal *nArgs)
140 textDisp *textD = ((TextWidget)w)->text.textD;
141 int parStart, pos, insertPos = TextDGetInsertPosition(textD);
142 textBuffer *buf = textD->buffer;
143 - char c;
144 - static char whiteChars[] = " \t";
145 int silent = hasKey("nobell", args, nArgs);
148 cancelDrag(w);
149 - if (insertPos == 0) {
151 + /* check if we are at the beginning of the file, than return */
152 + if (0 == insertPos) {
153 ringIfNecessary(silent, w);
154 - return;
155 + return;
157 - parStart = BufStartOfLine(buf, max(insertPos-1, 0));
158 - pos = max(parStart - 2, 0);
159 - while (pos > 0) {
160 - c = BufGetCharacter(buf, pos);
161 - if (c == '\n')
162 - break;
163 - if (strchr(whiteChars, c) != NULL)
164 - pos--;
165 - else {
166 - parStart = BufStartOfLine(buf, pos);
167 - pos = max(parStart - 2, 0);
170 + if (lineIsBlank(buf, insertPos, &parStart)
171 + || (insertPos == parStart
172 + && prevLineIsBlank(buf, parStart, &parStart))) {
173 + while (parStart > 0) {
174 + if (!prevLineIsBlank(buf, parStart, &pos)) {
175 + break;
177 + parStart = pos;
181 + while (parStart > 0) {
182 + if (prevLineIsBlank(buf, parStart, &pos)) {
183 + break;
185 + parStart = pos;
188 TextDSetInsertPosition(textD, parStart);
189 checkMoveSelectionChange(w, event, insertPos, args, nArgs);
190 checkAutoShowInsertPos(w);
191 callCursorMovementCBs(w, event);
193 @@ -3695,15 +3759,15 @@ static int endOfWord(TextWidget w, int p
194 ** Search forwards in buffer "buf" for the first character NOT in
195 ** "searchChars", starting with the character "startPos", and returning the
196 ** result in "foundPos" returns True if found, False if not. If ignoreSpace
197 ** is set, then Space, Tab, and Newlines are ignored in searchChars.
199 -static int spanForward(textBuffer *buf, int startPos, char *searchChars,
200 - int ignoreSpace, int *foundPos)
201 +static int spanForward(textBuffer *buf, int startPos, const char *searchChars,
202 + int ignoreSpace, int *foundPos)
204 int pos;
205 - char *c;
206 + const char *c;
208 pos = startPos;
209 while (pos < buf->length) {
210 for (c=searchChars; *c!='\0'; c++)
211 if(!(ignoreSpace && (*c==' ' || *c=='\t' || *c=='\n')))
212 @@ -3723,15 +3787,15 @@ static int spanForward(textBuffer *buf,
213 ** Search backwards in buffer "buf" for the first character NOT in
214 ** "searchChars", starting with the character BEFORE "startPos", returning the
215 ** result in "foundPos" returns True if found, False if not. If ignoreSpace is
216 ** set, then Space, Tab, and Newlines are ignored in searchChars.
218 -static int spanBackward(textBuffer *buf, int startPos, char *searchChars, int
219 - ignoreSpace, int *foundPos)
220 +static int spanBackward(textBuffer *buf, int startPos, const char *searchChars,
221 + int ignoreSpace, int *foundPos)
223 int pos;
224 - char *c;
225 + const char *c;
227 if (startPos == 0) {
228 *foundPos = 0;
229 return False;