enable openmotif-2.3.1 and link on phoenix host
[nedit-bw.git] / extended-paragraph.patch
blob44ae9357eb7185a162574a9e2133aa57e604007a
1 Subject: rewrite paragraph jumping code
3 This uses a state machine like code for the paragraph jumping code.
4 This makes it simplier to extend it with more versatility.
6 ---
8 source/text.c | 146 +++++++++++++++++++++++++++++++++++++++++-----------------
9 1 file changed, 105 insertions(+), 41 deletions(-)
11 diff --quilt old/source/text.c new/source/text.c
12 --- old/source/text.c
13 +++ new/source/text.c
14 @@ -222,14 +222,14 @@ static void simpleInsertAtCursor(Widget
15 int allowPendingDelete);
16 static int pendingSelection(Widget w);
17 static int deletePendingSelection(Widget w, XEvent *event);
18 static int deleteEmulatedTab(Widget w, XEvent *event);
19 static void selectWord(Widget w, int pointerX);
20 -static int spanForward(textBuffer *buf, int startPos, char *searchChars,
21 - int ignoreSpace, int *foundPos);
22 -static int spanBackward(textBuffer *buf, int startPos, char *searchChars, int
23 - ignoreSpace, int *foundPos);
24 +static int spanForward(textBuffer *buf, int startPos, const char *searchChars,
25 + int ignoreSpace, int *foundPos);
26 +static int spanBackward(textBuffer *buf, int startPos, const char *searchChars,
27 + int ignoreSpace, int *foundPos);
28 static void selectLine(Widget w);
29 static int startOfWord(TextWidget w, int pos);
30 static int endOfWord(TextWidget w, int pos);
31 static void checkAutoScroll(TextWidget w, int x, int y);
32 static void endDrag(Widget w);
33 @@ -2713,69 +2713,133 @@ static void backwardWordAP(Widget w, XEv
34 checkMoveSelectionChange(w, event, insertPos, args, nArgs);
35 checkAutoShowInsertPos(w);
36 callCursorMovementCBs(w, event);
39 +static Boolean lineIsBlank(textBuffer *buf, int pos, int *start)
41 + static const char whiteChars[] = " \t";
42 + char c;
44 + pos = BufStartOfLine(buf, pos);
45 + *start = pos;
47 + while (pos < buf->length) {
48 + c = BufGetCharacter(buf, pos);
50 + /* we reached the end of a blank line */
51 + if ('\n' == c) {
52 + return True;
53 + }
55 + /* check for any blank character */
56 + if (NULL != strchr(whiteChars, c)) {
57 + pos++;
58 + } else {
59 + /* this line is a not a blank line */
60 + return False;
61 + }
62 + }
64 + /* no end of line and no non blank character */
65 + return True;
68 +static Boolean nextLineIsBlank(textBuffer *buf, int pos, int *next)
70 + /* get start of next line */
71 + pos = min(BufEndOfLine(buf, pos) + 1, buf->length);
73 + if (pos == buf->length) {
74 + /* buffer without last end-of-line */
75 + *next = pos;
76 + return False;
77 + } else {
78 + return lineIsBlank(buf, pos, next);
79 + }
82 +static Boolean prevLineIsBlank(textBuffer *buf, int pos, int *prev)
84 + /* get end of prev line */
85 + pos = max(BufStartOfLine(buf, pos) - 1, 0);
87 + return lineIsBlank(buf, pos, prev);
90 static void forwardParagraphAP(Widget w, XEvent *event, String *args,
91 - Cardinal *nArgs)
92 + Cardinal *nArgs)
94 textDisp *textD = ((TextWidget)w)->text.textD;
95 int pos, insertPos = TextDGetInsertPosition(textD);
96 textBuffer *buf = textD->buffer;
97 - char c;
98 - static char whiteChars[] = " \t";
99 int silent = hasKey("nobell", args, nArgs);
101 cancelDrag(w);
103 + /* check if we are at the end of the file, than return */
104 if (insertPos == buf->length) {
105 ringIfNecessary(silent, w);
106 - return;
107 + return;
109 - pos = min(BufEndOfLine(buf, insertPos)+1, buf->length);
111 + /* need to skip current paragraph? */
112 + if (!lineIsBlank(buf, insertPos, &pos)) {
113 + while (pos < buf->length) {
114 + if (nextLineIsBlank(buf, pos, &pos)) {
115 + break;
120 + /* skip all blank lines */
121 while (pos < buf->length) {
122 - c = BufGetCharacter(buf, pos);
123 - if (c == '\n')
124 - break;
125 - if (strchr(whiteChars, c) != NULL)
126 - pos++;
127 - else
128 - pos = min(BufEndOfLine(buf, pos)+1, buf->length);
129 + if (!nextLineIsBlank(buf, pos, &pos)) {
130 + break;
133 - TextDSetInsertPosition(textD, min(pos+1, buf->length));
135 + TextDSetInsertPosition(textD, min(pos, buf->length));
136 checkMoveSelectionChange(w, event, insertPos, args, nArgs);
137 checkAutoShowInsertPos(w);
138 callCursorMovementCBs(w, event);
141 static void backwardParagraphAP(Widget w, XEvent *event, String *args,
142 - Cardinal *nArgs)
143 + Cardinal *nArgs)
145 textDisp *textD = ((TextWidget)w)->text.textD;
146 int parStart, pos, insertPos = TextDGetInsertPosition(textD);
147 textBuffer *buf = textD->buffer;
148 - char c;
149 - static char whiteChars[] = " \t";
150 int silent = hasKey("nobell", args, nArgs);
153 cancelDrag(w);
154 - if (insertPos == 0) {
156 + /* check if we are at the beginning of the file, than return */
157 + if (0 == insertPos) {
158 ringIfNecessary(silent, w);
159 - return;
160 + return;
162 - parStart = BufStartOfLine(buf, max(insertPos-1, 0));
163 - pos = max(parStart - 2, 0);
164 - while (pos > 0) {
165 - c = BufGetCharacter(buf, pos);
166 - if (c == '\n')
167 - break;
168 - if (strchr(whiteChars, c) != NULL)
169 - pos--;
170 - else {
171 - parStart = BufStartOfLine(buf, pos);
172 - pos = max(parStart - 2, 0);
175 + if (lineIsBlank(buf, insertPos, &parStart)
176 + || (insertPos == parStart
177 + && prevLineIsBlank(buf, parStart, &parStart))) {
178 + while (parStart > 0) {
179 + if (!prevLineIsBlank(buf, parStart, &pos)) {
180 + break;
182 + parStart = pos;
186 + while (parStart > 0) {
187 + if (prevLineIsBlank(buf, parStart, &pos)) {
188 + break;
190 + parStart = pos;
193 TextDSetInsertPosition(textD, parStart);
194 checkMoveSelectionChange(w, event, insertPos, args, nArgs);
195 checkAutoShowInsertPos(w);
196 callCursorMovementCBs(w, event);
198 @@ -3695,15 +3759,15 @@ static int endOfWord(TextWidget w, int p
199 ** Search forwards in buffer "buf" for the first character NOT in
200 ** "searchChars", starting with the character "startPos", and returning the
201 ** result in "foundPos" returns True if found, False if not. If ignoreSpace
202 ** is set, then Space, Tab, and Newlines are ignored in searchChars.
204 -static int spanForward(textBuffer *buf, int startPos, char *searchChars,
205 - int ignoreSpace, int *foundPos)
206 +static int spanForward(textBuffer *buf, int startPos, const char *searchChars,
207 + int ignoreSpace, int *foundPos)
209 int pos;
210 - char *c;
211 + const char *c;
213 pos = startPos;
214 while (pos < buf->length) {
215 for (c=searchChars; *c!='\0'; c++)
216 if(!(ignoreSpace && (*c==' ' || *c=='\t' || *c=='\n')))
217 @@ -3723,15 +3787,15 @@ static int spanForward(textBuffer *buf,
218 ** Search backwards in buffer "buf" for the first character NOT in
219 ** "searchChars", starting with the character BEFORE "startPos", returning the
220 ** result in "foundPos" returns True if found, False if not. If ignoreSpace is
221 ** set, then Space, Tab, and Newlines are ignored in searchChars.
223 -static int spanBackward(textBuffer *buf, int startPos, char *searchChars, int
224 - ignoreSpace, int *foundPos)
225 +static int spanBackward(textBuffer *buf, int startPos, const char *searchChars,
226 + int ignoreSpace, int *foundPos)
228 int pos;
229 - char *c;
230 + const char *c;
232 if (startPos == 0) {
233 *foundPos = 0;
234 return False;