mirror of
https://github.com/janet-lang/janet
synced 2025-05-04 16:34:15 +00:00
Long strings now autoindent contents - doc-format is simpler.
No need to try and auto detect the base indentation - it is 0. This will be taken care of by the parser.
This commit is contained in:
parent
21a6017547
commit
56a915b5b1
@ -1694,8 +1694,9 @@
|
|||||||
(env-walk keyword? env local))
|
(env-walk keyword? env local))
|
||||||
|
|
||||||
(defn doc-format
|
(defn doc-format
|
||||||
`Reformat a docstring to wrap a certain width.
|
`Reformat a docstring to wrap a certain width. Docstrings can either be plaintext
|
||||||
Returns a buffer containing the formatted text.`
|
or a subset of markdown. This allows a long single line of prose or formatted text to be
|
||||||
|
a well-formed docstring. Returns a buffer containing the formatted text.`
|
||||||
[str &opt width indent]
|
[str &opt width indent]
|
||||||
(default indent 4)
|
(default indent 4)
|
||||||
(def max-width (- (or width (dyn :doc-width 80)) 8))
|
(def max-width (- (or width (dyn :doc-width 80)) 8))
|
||||||
@ -1708,38 +1709,8 @@
|
|||||||
(var leading 0)
|
(var leading 0)
|
||||||
(var c nil)
|
(var c nil)
|
||||||
|
|
||||||
(def base-indent
|
|
||||||
# Is there a better way?
|
|
||||||
(do
|
|
||||||
(var min-indent 0)
|
|
||||||
(var curr-indent 0)
|
|
||||||
(var start-of-line false)
|
|
||||||
(set c (get str pos))
|
|
||||||
(while (not= nil c)
|
|
||||||
(case c
|
|
||||||
10 (do
|
|
||||||
(set start-of-line true)
|
|
||||||
(set curr-indent 0))
|
|
||||||
32 (when start-of-line
|
|
||||||
(++ curr-indent))
|
|
||||||
(when start-of-line
|
|
||||||
(set start-of-line false)
|
|
||||||
(when (or (= 0 min-indent)
|
|
||||||
(< curr-indent min-indent))
|
|
||||||
(set min-indent curr-indent))))
|
|
||||||
(set c (get str (++ pos))))
|
|
||||||
min-indent))
|
|
||||||
|
|
||||||
(set pos 0)
|
(set pos 0)
|
||||||
|
|
||||||
(defn skip-base-indent []
|
|
||||||
(var pos* pos)
|
|
||||||
(set c (get str pos*))
|
|
||||||
(while (and (< (- pos* pos) base-indent)
|
|
||||||
(= 32 c))
|
|
||||||
(set c (get str (++ pos*))))
|
|
||||||
(set pos pos*))
|
|
||||||
|
|
||||||
(defn skip-line-indent []
|
(defn skip-line-indent []
|
||||||
(var pos* pos)
|
(var pos* pos)
|
||||||
(set c (get str pos*))
|
(set c (get str pos*))
|
||||||
@ -1895,19 +1866,15 @@
|
|||||||
(defn push-fcb []
|
(defn push-fcb []
|
||||||
(update-levels)
|
(update-levels)
|
||||||
(push-line)
|
(push-line)
|
||||||
(skip-base-indent)
|
|
||||||
(while (not (end-fcb?))
|
(while (not (end-fcb?))
|
||||||
(push-line)
|
(push-line))
|
||||||
(skip-base-indent))
|
|
||||||
(push-line))
|
(push-line))
|
||||||
|
|
||||||
(defn push-icb []
|
(defn push-icb []
|
||||||
(buffer/push-string res (buffer/new-filled leading 32))
|
(buffer/push-string res (buffer/new-filled leading 32))
|
||||||
(push-line)
|
(push-line)
|
||||||
(skip-base-indent)
|
|
||||||
(while (not (start-nl?))
|
(while (not (start-nl?))
|
||||||
(push-line)
|
(push-line))
|
||||||
(skip-base-indent))
|
|
||||||
(push-nl))
|
(push-nl))
|
||||||
|
|
||||||
(defn push-p []
|
(defn push-p []
|
||||||
@ -1936,7 +1903,6 @@
|
|||||||
(push-nl))
|
(push-nl))
|
||||||
|
|
||||||
(while (< pos len)
|
(while (< pos len)
|
||||||
(skip-base-indent)
|
|
||||||
(skip-line-indent)
|
(skip-line-indent)
|
||||||
(cond
|
(cond
|
||||||
(start-nl?)
|
(start-nl?)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user