?: go back to numexpr
[nedit-bw.git] / extended-paragraph-any.patch
blob266fd27d270ad68daf7797655b35fed861825468
1 Subject: "any" option for paragraph jumping
3 With the "any" option paragraph jumping stops on start and end of paragraph.
6 ---
8 doc/help.etx | 13 ++++++----
9 source/text.c | 75 ++++++++++++++++++++++++++++++++++++++++++++--------------
10 2 files changed, 67 insertions(+), 21 deletions(-)
12 diff --quilt old/source/text.c new/source/text.c
13 --- old/source/text.c
14 +++ new/source/text.c
15 @@ -2774,29 +2774,48 @@ static void forwardParagraphAP(Widget w,
16 textBuffer *buf = textD->buffer;
17 int silent = hasKey("nobell", args, nArgs);
18 int not_end = !hasKey("end", args, nArgs);
19 + int any = hasKey("any", args, nArgs);
21 cancelDrag(w);
23 + /* "end" and "any" are mutual exclusive */
24 + if (any && !not_end) {
25 + return;
26 + }
28 /* check if we are at the end of the file, than return */
29 if (insertPos == buf->length) {
30 ringIfNecessary(silent, w);
31 return;
34 - /* need to skip current paragraph? */
35 - if (not_end != lineIsBlank(buf, insertPos, &pos)) {
36 + if (any) {
37 + int stop = !lineIsBlank(buf, insertPos, &pos);
39 while (pos < buf->length) {
40 - if (not_end == nextLineIsBlank(buf, pos, &pos)) {
41 + if (stop == nextLineIsBlank(buf, pos, &pos)) {
42 break;
45 - }
47 - /* skip all blank lines */
48 - while (pos < buf->length) {
49 - if (not_end != nextLineIsBlank(buf, pos, &pos)) {
50 - break;
51 + } else {
53 + /* need to skip current paragraph? */
54 + if (not_end != lineIsBlank(buf, insertPos, &pos)) {
55 + while (pos < buf->length) {
56 + if (not_end == nextLineIsBlank(buf, pos, &pos)) {
57 + break;
58 + }
59 + }
62 + /* skip all blank lines */
63 + while (pos < buf->length) {
64 + if (not_end != nextLineIsBlank(buf, pos, &pos)) {
65 + break;
66 + }
67 + }
71 TextDSetInsertPosition(textD, min(pos, buf->length));
72 @@ -2813,31 +2832,53 @@ static void backwardParagraphAP(Widget w
73 textBuffer *buf = textD->buffer;
74 int silent = hasKey("nobell", args, nArgs);
75 int not_end = !hasKey("end", args, nArgs);
76 + int any = hasKey("any", args, nArgs);
78 cancelDrag(w);
80 + /* "end" and "any" are mutual exclusive */
81 + if (any && !not_end) {
82 + return;
83 + }
85 /* check if we are at the beginning of the file, than return */
86 if (0 == insertPos) {
87 ringIfNecessary(silent, w);
88 return;
91 - if (not_end == lineIsBlank(buf, insertPos, &parStart)
92 - || (insertPos == parStart
93 - && not_end == prevLineIsBlank(buf, parStart, &parStart))) {
94 + if (any) {
95 + int stop = lineIsBlank(buf, insertPos, &parStart)
96 + || !(insertPos == parStart
97 + && prevLineIsBlank(buf, parStart, &parStart));
99 while (parStart > 0) {
100 - if (not_end != prevLineIsBlank(buf, parStart, &pos)) {
101 + if (stop == prevLineIsBlank(buf, parStart, &pos)) {
102 break;
104 parStart = pos;
108 - while (parStart > 0) {
109 - if (not_end == prevLineIsBlank(buf, parStart, &pos)) {
110 - break;
111 + } else {
113 + if (not_end == lineIsBlank(buf, insertPos, &parStart)
114 + || (insertPos == parStart
115 + && not_end == prevLineIsBlank(buf, parStart, &parStart))) {
116 + while (parStart > 0) {
117 + if (not_end != prevLineIsBlank(buf, parStart, &pos)) {
118 + break;
120 + parStart = pos;
123 - parStart = pos;
125 + while (parStart > 0) {
126 + if (not_end == prevLineIsBlank(buf, parStart, &pos)) {
127 + break;
129 + parStart = pos;
134 TextDSetInsertPosition(textD, parStart);
135 diff --quilt old/doc/help.etx new/doc/help.etx
136 --- old/doc/help.etx
137 +++ new/doc/help.etx
138 @@ -3306,13 +3306,16 @@ Action Routines
139 **backward_character( ["nobell"] )**
140 Moves the cursor one character to the left.
142 -**backward_paragraph( ["end"] ["nobell"] )**
143 +**backward_paragraph( ["end" | "any"] ["nobell"] )**
144 Moves the cursor to the beginning of the paragraph, or
145 if the cursor is already at the beginning of a paragraph, moves the cursor to
146 the beginning of the previous paragraph. Paragraphs are defined as regions
147 of text delimited by one or more blank lines. If the "end" option is given
148 the cursor is moved to the end of previous paragraph. The end of a paragraph
149 - is the first blank line after the paragraph, if any.
150 + is the first blank line after the paragraph, if any. If the "any" option is
151 + given, which is mutual exclusive to the "end" option, the cursor is moved to
152 + either the previous beginning or to the previous end of a paragraph,
153 + whichever comes first.
155 **backward_word( ["tail"] ["nobell"] )**
156 Moves the cursor to the beginning of a word, or, if the
157 @@ -3433,13 +3436,15 @@ Action Routines
158 **forward_character()**
159 Moves the cursor one character to the right.
161 -**forward_paragraph( ["end"] ["nobell"] )**
162 +**forward_paragraph( ["end" | "any"] ["nobell"] )**
163 Moves the cursor to the beginning of the next paragraph.
164 Paragraphs are defined as regions of text delimited by one or more blank
165 lines. If the "end" optione is given, the cursor is moved to the end of the
166 current paragraph, or to the end of the next paragraph if the current line
167 is a blank line. The end of a paragraph is the first blank line after the
168 - paragraph, if any.
169 + paragraph, if any. If the "any" option is given, which is mutual exclusive to
170 + the "end" option, the cursor is moved to either the next beginning or to the
171 + next end of a paragraph, whichever comes first.
173 **forward_word( ["tail"] ["nobell"] )**
174 Moves the cursor to the beginning of the next word. Word