From: NeilBrown Date: Mon, 22 May 2023 10:53:47 +0000 (+1000) Subject: handle text-fill in .md files better. X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=d88059b7c1ec3bb5ef6fa86d3f0d7b65e69c582f;p=edlib.git handle text-fill in .md files better. Enhance text-fill so that various style attributes can be on the pane rather than on the character, and set pane attributes for markdown to notice the starts of various paragraph types, particularly the various list entries. Signed-off-by: NeilBrown --- diff --git a/python/config.py b/python/config.py index e42c4f34..7deefc44 100644 --- a/python/config.py +++ b/python/config.py @@ -27,6 +27,14 @@ def config_appeared(key, focus, **a): else: focus.call("doc:set:view-default", "textfill,whitespace,autospell") focus.call("doc:set:fill-width", "72") + + focus.call("doc:set:fill:start-re", + "^([^a-zA-Z0-9\\n]*$| *-| *- *\\[[ X]]| *#+| *\\*+| *[0-9]*\\.)" + ) + focus.call("doc:set:fill:end-re", + "^([^a-zA-Z0-9\\n]*$| *-| *- *\\[[ X]]| *#+| *\\*+| *[0-9]*\\.)" + ) + return edlib.Efallthrough editor.call("global-set-command", "doc:appeared-config", config_appeared) diff --git a/python/lib-textfill.py b/python/lib-textfill.py index 41bb59ac..4c55c4ac 100644 --- a/python/lib-textfill.py +++ b/python/lib-textfill.py @@ -128,6 +128,8 @@ def find_start(focus, mark): mark = mark.dup() m = mark.dup() re = focus.call("doc:get-attr", mark, "fill:start-re", ret='str') + if not re: + re = focus['fill:start-re'] if not re: re = "^[^a-zA-Z0-9\n]*$" focus.call("doc:EOL", -100, m) @@ -154,6 +156,8 @@ def find_end(focus, mark): m = mark.dup() focus.call("doc:EOL", 100, m) re = focus.call("doc:get-attr", mark, "fill:end-re", ret='str') + if not re: + re = focus['fill:end-re'] if not re: re = "^[^a-zA-Z0-9\n]*$" try: @@ -181,6 +185,8 @@ def get_prefixes(focus, mark, lines): # only one line, so prefix is all spaces but based on first line prefix = focus.call("doc:get-attr", "fill:default-prefix", m, ret='str') + if not prefix: + prefix = focus['fill:default-prefix'] if not prefix: prefix = "" # When a single line is being wrapped, all of these @@ -188,6 +194,8 @@ def get_prefixes(focus, mark, lines): # other lines. repeating_prefix = focus.call("doc:get-attr", "fill:repeating-prefix", m, ret='str') + if not repeating_prefix: + repeating_prefix = focus['fill:repeating-prefix'] if not repeating_prefix: repeating_prefix='' repeating_prefix += ' \t'