Skip to content

Commit b3da869

Browse files
author
Jason Duncan
committed
Finished addressing the docstrings.
1 parent 9e06474 commit b3da869

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

TODO.org

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
** TODO Some docstrings are quite long which lets you pass package-lint and makes for good enough M-x apropos output, but they wrap poorly in M-x help.
1+
** DONE Some docstrings are quite long which lets you pass package-lint and makes for good enough M-x apropos output, but they wrap poorly in M-x help.
22
** DONE "delimiater" -> "delimiter"
33
** DONE Since you're using Emacs 25 you can use the string-trim functions (could format-table-trim-row be rewritten as just (string-trim row begin-row end-row)?
44
** DONE Could the first conditional in format-table-remove-noise be written either as:

format-table.el

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@
7373
(json . json)))
7474

7575
(defun format-table-pad-right (value length)
76-
"Pad the string VALUE to the length specified by LENGTH using spaces to the right."
76+
"Pad the string VALUE to the LENGTH specified using spaces to the right."
7777
(format (concat "%-" (number-to-string length) "s") value))
7878

7979
(defun format-table-pad-center (value length)
80-
"Pad the string VALUE to the length specified by LENGTH by surrounding with spaces."
80+
"Pad the string VALUE to the LENGTH specified by surrounding with spaces."
8181
(let* ((value-length (length value))
8282
(left-length (/ (- length value-length) 2))
8383
(right-length (+ left-length
@@ -93,6 +93,9 @@
9393
(make-string right-length ? ))))
9494

9595
(defun format-table-remove-noise (lines input-mode)
96+
"Remove lines which constitute noise, such as empty lines or results count.
97+
LINES is the list of source lines, split on newlines. INPUT-MODE is used to
98+
determine what the results count should look like."
9699
"Given the set of table LINES and some extra information in INPUT-MODE, filter out any empty lines or lines which otherwise do not belong to the table of values."
97100
(let* ((row-count-format (plist-get input-mode :row-count-format))
98101
(regexp (when row-count-format (format row-count-format "[[:digit:]]+")))
@@ -107,7 +110,10 @@
107110
(-slice ret 0 (1- (length ret))) ret))))
108111

109112
(defun format-table-get-col-widths (dashes input-mode)
110-
"Using the line of all DASHES from the table and the INPUT-MODE, determine the widths of the columns and return them in a list."
113+
"Determine the widths of each column in the table.
114+
DASHES is a string containing the row from the source table which separates the
115+
header from the body of the table. INPUT-MODE is used to determine what column
116+
separators and such should look like."
111117
(let* ((separator-begin-row (regexp-quote (plist-get input-mode :separator-begin-row)))
112118
(separator-end-row (regexp-quote (plist-get input-mode :separator-end-row)))
113119
(separator-col-separator (plist-get input-mode :separator-col-separator))
@@ -116,7 +122,9 @@
116122
(regexp-quote separator-col-separator)))))
117123

118124
(defun format-table-split-row (row col-widths input-mode)
119-
"Split the given string ROW based on the fixed positions listed in COL-WIDTHS and any additional information in INPUT-MODE."
125+
"Split the given string ROW based on the fixed positions listed in COL-WIDTHS.
126+
INPUT-MODE is used to determine what beginning of row, end of row, and column
127+
separators should look like."
120128
(let* ((begin-row (plist-get input-mode :begin-row))
121129
(end-row (plist-get input-mode :end-row))
122130
(col-separator (plist-get input-mode :col-separator))
@@ -135,29 +143,28 @@
135143
cur-width))))))))
136144

137145
(defun format-table-assemble-table (header body)
138-
"Given the HEADER list of column names and nested list of values BODY, return an alist with both and some extra meta information about same."
146+
"Assemble the HEADER and BODY of the table into an alist with some extra info."
139147
(let ((max-col-widths (format-table-get-max-col-widths (cons header body))))
140148
(list :header header
141149
:body body
142150
:max-col-widths max-col-widths
143151
:row-count (length body))))
144152

145153
(defun format-table-parse-table (lines col-widths input-mode)
146-
"Given the list of table LINES, set of COL-WIDTHS, and INPUT-MODE, build a table of values as a plist."
154+
"Parse the list of table LINES into a plist."
147155
(let* ((header (format-table-split-row (car lines) col-widths input-mode))
148156
(body (--map (format-table-split-row it col-widths input-mode) (-slice lines 2))))
149157
(format-table-assemble-table header body)))
150158

151159
(defun format-table-get-max-col-widths (table)
152-
"Determine the length of the longest value in each column from TABLE and return as a list."
160+
"List the length of the longest value in each column from TABLE."
153161
(let ((last (make-list (length (car table)) 0)))
154162
(dolist (cur-row table last)
155163
(setq last
156164
(-zip-with #'max (-map #'length cur-row) last)))))
157165

158166
(defun format-table-render-row (row max-col-widths output-mode &optional pad-fn)
159167
"Render a table row with the proper column separators and a newline.
160-
161168
Arguments are the list of values ROW, the list of MAX-COL-WIDTHS, and delimiter
162169
information in OUTPUT-MODE. Optionally use PAD-FN to pad each column value,
163170
otherwise values will be padded to the right with spaces."
@@ -177,7 +184,6 @@ otherwise values will be padded to the right with spaces."
177184

178185
(defun format-table-render-separator-row (max-col-widths output-mode)
179186
"Render a row which separates the header row from the rest of the rows.
180-
181187
Columns will be spaced accrding to MAX-COL-WIDTHS and delimited using strings
182188
from OUTPUT-MODE."
183189
(append
@@ -244,7 +250,7 @@ from OUTPUT-MODE."
244250
(format-table-assemble-table header body)))
245251

246252
(defun format-table-cleanup-and-parse (str input-mode)
247-
"Parse the given string STR using delimiter information in INPUT-MODE to a plist."
253+
"Parse the given STR using delimiter information in INPUT-MODE to a plist."
248254
(if (equal input-mode 'json)
249255
(format-table-parse-json str)
250256
(let* ((lines (split-string str "[\n]+"))
@@ -255,7 +261,6 @@ from OUTPUT-MODE."
255261

256262
(defun format-table (str input-mode output-mode)
257263
"Reformat tabular data.
258-
259264
Process the given string STR containing a table in a format specified by
260265
INPUT-MODE, gather and reformat the table contained within to the format
261266
specified by OUTPUT-MODE."

0 commit comments

Comments
 (0)