From: NeilBrown Date: Sat, 26 Aug 2023 22:49:58 +0000 (+1000) Subject: textfill: get prefix from regexp when appropriate. X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=acc9a0a97aa8e10a0f294e56404ff7f8fecccacc;p=edlib.git textfill: get prefix from regexp when appropriate. 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 --- diff --git a/DOC/TODO.md b/DOC/TODO.md index 9b14eb3f..54c19343 100644 --- a/DOC/TODO.md +++ b/DOC/TODO.md @@ -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 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 diff --git a/data/edlib.ini b/data/edlib.ini index 724ee600..0a3a39b3 100644 --- a/data/edlib.ini +++ b/data/edlib.ini @@ -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] diff --git a/python/lib-textfill.py b/python/lib-textfill.py index f673450e..d487ac80 100644 --- a/python/lib-textfill.py +++ b/python/lib-textfill.py @@ -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):