about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-12-09 14:43:10 +0100
committerbptato <nincsnevem662@gmail.com>2023-12-09 16:36:23 +0100
commit6a1b1a2edfc6adf3d1d1a1aaa2c9fd95eccc8ff7 (patch)
treef2760bbb12b79925fa1c87dde9e05ddd74310683
parent14f5605061501fa56d9b4970571858f6451e4710 (diff)
downloadchawan-6a1b1a2edfc6adf3d1d1a1aaa2c9fd95eccc8ff7.tar.gz
pager: add `{', `}'; document externInto
{ & } acts like in vi (except the cursor is not moved to the line
beginning).

No reason to leave externInto undocumented, as it is even used in
the default config.
-rw-r--r--doc/config.md18
-rw-r--r--res/chawan.html1
-rw-r--r--res/config.toml2
-rw-r--r--src/local/container.nim14
-rw-r--r--src/server/buffer.nim21
5 files changed, 55 insertions, 1 deletions
diff --git a/doc/config.md b/doc/config.md
index 8a078b01..0b017f1c 100644
--- a/doc/config.md
+++ b/doc/config.md
@@ -732,6 +732,16 @@ Note: this does not suspend buffer processes.</td>
 </tr>
 
 <tr>
+<td>`pager.cursorPrevParagraph(n = 1)`</td>
+<td>Move the cursor to the beginning of the nth next paragraph.</td>
+</tr>
+
+<tr>
+<td>`pager.cursorNextParagraph(n = 1)`</td>
+<td>Move the cursor to the end of the nth previous paragraph.</td>
+</tr>
+
+<tr>
 <td>`pager.cursorNthLink(n = 1)`</td>
 <td>Move the cursor to the nth link of the document.</td>
 </tr>
@@ -1027,6 +1037,14 @@ result. null is returned if the command wasn't executed successfully, or if
 the command returned a non-zero exit value.</td>
 </tr>
 
+<tr>
+<td>`pager.externInto(cmd, ins)`
+</td>
+<td>Like extern(), but redirect `ins` into the command's standard input stream.
+`true` is returned if the command exits successfully, otherwise the return
+value is `false`.</td>
+</tr>
+
 </table>
 
 
diff --git a/res/chawan.html b/res/chawan.html
index 271e3e6b..c2be720c 100644
--- a/res/chawan.html
+++ b/res/chawan.html
@@ -62,6 +62,7 @@ up/down by one row
 <li><kbd>C-d</kbd>, <kbd>C-u</kbd>: scroll up/down by half a page
 <li><kbd>C-f</kbd>, <kbd>C-b</kbd> (or <kbd>PgDn</kbd>, <kbd>PgUp</kbd>)</kbd>:
 scroll up/down by an entire page
+<li><kbd>{</kbd>, <kbd>}</kbd>: move cursor to the previous/next paragraph
 <li><kbd>(</kbd>, <kbd>)</kbd> (or <kbd>zh</kbd>, <kbd>zl</kbd>): shift
 screen to the left/right by one cell
 <li><kbd>&lt;</kbd>, <kbd>&gt;</kbd>: shift screen to the left/right by one page
diff --git a/res/config.toml b/res/config.toml
index a263fcb7..2e5d0a8b 100644
--- a/res/config.toml
+++ b/res/config.toml
@@ -85,6 +85,8 @@ b = 'pager.cursorPrevWord()'
 w = 'pager.cursorNextWord()'
 '[' = 'pager.cursorPrevLink()'
 ']' = 'pager.cursorNextLink()'
+'{' = 'n => pager.cursorPrevParagraph(n)'
+'}' = 'n => pager.cursorNextParagraph(n)'
 H = 'n => pager.cursorTop(n)'
 M = '() => pager.cursorMiddle()'
 L = 'n => pager.cursorBottom(n)'
diff --git a/src/local/container.nim b/src/local/container.nim
index 2a0051e6..7cb67862 100644
--- a/src/local/container.nim
+++ b/src/local/container.nim
@@ -850,6 +850,20 @@ proc cursorPrevLink*(container: Container) {.jsfunc.} =
       if res.x > -1 and res.y != -1:
         container.setCursorXYCenter(res.x, res.y))
 
+proc cursorNextParagraph*(container: Container, n = 1) {.jsfunc.} =
+  container.iface
+    .findNextParagraph(container.cursory, n)
+    .then(proc(res: int) =
+      container.setCursorY(res)
+    )
+
+proc cursorPrevParagraph*(container: Container, n = 1) {.jsfunc.} =
+  container.iface
+    .findPrevParagraph(container.cursory, n)
+    .then(proc(res: int) =
+      container.setCursorY(res)
+    )
+
 proc cursorNthLink*(container: Container, n = 1) {.jsfunc.} =
   container.iface
     .findNthLink(n)
diff --git a/src/server/buffer.nim b/src/server/buffer.nim
index e69af1fb..fff6f195 100644
--- a/src/server/buffer.nim
+++ b/src/server/buffer.nim
@@ -68,7 +68,8 @@ type
     CLICK, FIND_NEXT_LINK, FIND_PREV_LINK, FIND_NTH_LINK, FIND_REV_NTH_LINK,
     FIND_NEXT_MATCH, FIND_PREV_MATCH, GET_SOURCE, GET_LINES, UPDATE_HOVER,
     PASS_FD, CONNECT, CONNECT2, GOTO_ANCHOR, CANCEL, GET_TITLE, SELECT,
-    REDIRECT_TO_FD, READ_FROM_FD, SET_CONTENT_TYPE, CLONE
+    REDIRECT_TO_FD, READ_FROM_FD, SET_CONTENT_TYPE, CLONE, FIND_PREV_PARAGRAPH,
+    FIND_NEXT_PARAGRAPH
 
   # LOADING_PAGE: istream open
   # LOADING_RESOURCES: istream closed, resources open
@@ -477,6 +478,24 @@ proc findNextLink*(buffer: Buffer, cursorx, cursory: int): tuple[x, y: int] {.pr
       inc i
   return (-1, -1)
 
+proc findPrevParagraph*(buffer: Buffer, cursory, n: int): int {.proxy.} =
+  var y = cursory
+  for i in 0 ..< n:
+    while y >= 0 and buffer.lines[y].str.onlyWhitespace():
+      dec y
+    while y >= 0 and not buffer.lines[y].str.onlyWhitespace():
+      dec y
+  return y
+
+proc findNextParagraph*(buffer: Buffer, cursory, n: int): int {.proxy.} =
+  var y = cursory
+  for i in 0 ..< n:
+    while y < buffer.lines.len and buffer.lines[y].str.onlyWhitespace():
+      inc y
+    while y < buffer.lines.len and not buffer.lines[y].str.onlyWhitespace():
+      inc y
+  return y
+
 proc findNthLink*(buffer: Buffer, i: int): tuple[x, y: int] {.proxy.} =
   if i == 0:
     return (-1, -1)