Skip to content

Commit e5abd52

Browse files
author
Jason Duncan
committed
Reverted to my own string-trim function.
1 parent 87cc95c commit e5abd52

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

TODO.org

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
** 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)?
4+
*** NOTE the answer is no, this causes a regression. The optional trim-left and trim-right arugments were not added to string-trim until emacs 26.
45
** DONE Could the first conditional in format-table-remove-noise be written either as:
56

67
#+BEGIN_SRC emacs-lisp

format-table.el

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,25 @@ determine what the results count should look like."
109109
(if (plist-get input-mode :top-border-fn)
110110
(-slice ret 0 (1- (length ret))) ret))))
111111

112+
(defun format-table-trim-row (row begin-row end-row)
113+
"Given the string ROW trim the string BEGIN-ROW from the beginning and END-ROW from the end."
114+
(replace-regexp-in-string
115+
(concat "^" (regexp-quote begin-row))
116+
""
117+
(replace-regexp-in-string
118+
(concat (regexp-quote end-row) "$")
119+
""
120+
row)))
121+
112122
(defun format-table-get-col-widths (dashes input-mode)
113123
"Determine the widths of each column in the table.
114124
DASHES is a string containing the row from the source table which separates the
115125
header from the body of the table. INPUT-MODE is used to determine what column
116126
separators and such should look like."
117-
(let* ((separator-begin-row (regexp-quote (plist-get input-mode :separator-begin-row)))
118-
(separator-end-row (regexp-quote (plist-get input-mode :separator-end-row)))
127+
(let* ((separator-begin-row (plist-get input-mode :separator-begin-row))
128+
(separator-end-row (plist-get input-mode :separator-end-row))
119129
(separator-col-separator (plist-get input-mode :separator-col-separator))
120-
(dashes (string-trim dashes separator-begin-row separator-end-row)))
130+
(dashes (format-table-trim-row dashes separator-begin-row separator-end-row)))
121131
(-map #'length (split-string dashes
122132
(regexp-quote separator-col-separator)))))
123133

@@ -128,7 +138,7 @@ separators should look like."
128138
(let* ((begin-row (plist-get input-mode :begin-row))
129139
(end-row (plist-get input-mode :end-row))
130140
(col-separator (plist-get input-mode :col-separator))
131-
(row (string-trim row begin-row end-row))
141+
(row (format-table-trim-row row begin-row end-row))
132142
split)
133143
(reverse
134144
(dolist (cur-width col-widths split)

0 commit comments

Comments
 (0)