]> git.neil.brown.name Git - edlib.git/commitdiff
textfill: get prefix from regexp when appropriate.
authorNeilBrown <neil@brown.name>
Sat, 26 Aug 2023 22:49:58 +0000 (08:49 +1000)
committerNeilBrown <neil@brown.name>
Sun, 27 Aug 2023 03:33:02 +0000 (13:33 +1000)
Revise code for finding start of para so that if the regexp identifies a
prefix - rather than a whole line - we use that prefix to decide where
para starts, rather than skipping punctuation.

Also include trailing spaces of a prefix in the prefix for .md files.

Signed-off-by: NeilBrown <neil@brown.name>
DOC/TODO.md
data/edlib.ini
python/lib-textfill.py

index 9b14eb3f3a5193f05a343eba5ab67430e52732d8..54c19343798b4dbf9d8e98663939311175dc2d52 100644 (file)
@@ -9,12 +9,14 @@ the file.
 
 ### Triage
 
+- [ ] search hangs when seeking "^( *)"
+
 ### Small
 
-- [ ] notmuch addresses in From: list to have menu to add address to
-      any from-* query
+- [ ] notmuch addresses in From: list to have menu to add address to any
+      from-* query
 - [ ] Disable <hide> if cursor is in the hidden region.
-- [ ] fill mode to handle all punctuation at start of this line
+- [X] fill mode to handle all punctuation at start of this line
 - [ ] Enable lib-menu to show short-cut keys
 - [ ] Add menu-bar to lib-menu.  Pop it up on F10 with simple commands
 - [ ] attach an extensible menu to the selection
@@ -23,7 +25,7 @@ the file.
 ### Medium
 
 - [ ] split range management out of autospell so it can be used by other
-  modules.
+      modules.
 - [ ] make it easy for a make-search command to search backwards
 - [ ] Make a start on CUA mode with mouse/menu/selection support.
       Also Function keys: help, close, refresh
@@ -50,8 +52,8 @@ Requirements for a v1.0 release
 - [ ] introspection
 - [ ] markdown editor (with PDF output)
 - [ ] non-line-based render, such as a tabular render for spreadsheet,
-       or side-scrolling horiz row of thumbnails for presentation,
-       or even a menu-bar with row of menus.
+      or side-scrolling horiz row of thumbnails for presentation, or
+      even a menu-bar with row of menus.
 - [ ] documentation reader
 - [ ] block-dev (mmap) doc type, and some hex-mode support
 - [ ] user documentation
@@ -66,12 +68,11 @@ Core features
 - [ ] Ensure all panes that should use "Free" properly, and find some
       what to encourage its use.
 - [ ] Add optional unit-test interface for modules.  This should be
-      implemented at least by lib-search, doc-text and probably
-      many others.  It is particularly for things that are awkward
-      to test with the ncurses/replay test approach.
-- [ ] Send global notify before/after refresh.  LOG must suspend
-      logging (or notifications at least) during refresh if is visible
-      anywhere
+      implemented at least by lib-search, doc-text and probably many
+      others.  It is particularly for things that are awkward to test
+      with the ncurses/replay test approach.
+- [ ] Send global notify before/after refresh.  LOG must suspend logging
+      (or notifications at least) during refresh if is visible anywhere
 - [ ] Do I want "Display" as in "Display:close", or "window" as in
       "window:notify".  Decide, and make everything consistent.
 - [ ] Do I really need global-multicall- or can I just use
@@ -224,9 +225,9 @@ Module features
 
 ### lib-textfill
 
-- [ ] auto-wrap on a line like this one doesn't recognize all the
+- [X] auto-wrap on a line like this one doesn't recognize all the
   punctuation a the start of the line ... should it?
-- [ ] fill mode to handle all punctuation at start of this line
+- [X] fill mode to handle all punctuation at start of this line
 
 ### render-format
 
index 724ee6009a4ee491236711c915e74673804d4e63..0a3a39b369f4c928d9ca2ac9bad6e4861dc2e0d1 100644 (file)
@@ -23,10 +23,10 @@ fill-width = 72
 word-wrap = 1
 fill:start-re = "^("
                 "[^a-zA-Z0-9\n]*$|" # empty/puctuation line
-                " *-|"               # list item
-                " *- *\[[ X]]|"     # todo list item
-                " *#+|"              # section head
-                " *[0-9]*\.)"       # Numbered list
+                " *- *|"               # list item
+                " *- *\[[ X]] *|"     # todo list item
+                " *#+ *|"              # section head
+                " *[0-9]*\.) *"       # Numbered list
 
 [include]
 
index f673450e75034ca4520474c090ee0b96a5faf6bf..d487ac804bf35756d5ff1d40b5f8646e29c55d8e 100644 (file)
@@ -134,22 +134,33 @@ def find_start(focus, mark):
         re = "^[^a-zA-Z0-9\n]*$"
     focus.call("doc:EOL", -100, m)
     try:
-        leng = focus.call("text-search", re, mark, m, 1, 1)
-        # leng is length + 1, we want +1 to kill '\n'
-        focus.call("Move-Char", leng, mark)
+        leng = focus.call("text-search", re, mark, m, 0, 1)
+        # leng is length + 1.  It might match a whole line or
+        # just a prefix. So we move "length + 1" chars, then back
+        # to start of line.  If it matched a whole line we will be on
+        # start of next line.  If just a prefix, we will be on start of
+        # that line.
+        last = focus.call("doc:char", leng, mark, -1, ret='char')
+        focus.call("doc:EOL", -1, mark)
     except edlib.commandfailed:
         if focus.prior(m) != None:
             # Went back 100 lines and found no suitable para-separator line
             return None
+        # at start of file - must be start of para.
+        last = "\n"
         mark.to_mark(m)
     # mark is at start of para - not indented yet.
 
-    # Now choose a prefix, which is non-alphanum or quotes.
-    # Possibly open brackets should be included too?
-    l = focus.call("text-match", "^[^a-zA-Z0-9'\"\n]*", mark.dup())
-    while l > 1:
-        focus.next(mark)
-        l -= 1
+    # Now choose a prefix.  If the re identified one, use that,
+    # otherwise use all non-alphanum or quotes.
+    #
+    if last != '\n':
+        # re found a prefix
+        l = leng
+    else:
+        l = focus.call("text-match", "^[^a-zA-Z0-9'\"\n]*", mark.dup())
+    if l > 0:
+        focus.call("doc:char", l-1, mark)
     return mark
 
 def find_end(focus, mark):