Add csvivify
This commit is contained in:
parent
04d1f4e50a
commit
30bfa6be01
1 changed files with 26 additions and 0 deletions
26
elisp/csvivify.el
Normal file
26
elisp/csvivify.el
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
;;; csvivify.el --- Turn org or markdown tables into csv in-place -*- lexical-binding: t -*-
|
||||||
|
|
||||||
|
;;; Commentary:
|
||||||
|
|
||||||
|
;; For most use-cases, this is unnecessary, as org tables can already convert
|
||||||
|
;; to and from markdown and CSV, but it was a fun exercise to write.
|
||||||
|
|
||||||
|
;;; Code:
|
||||||
|
|
||||||
|
(defun csvivify ()
|
||||||
|
"Make org or markdown table into csv in-place."
|
||||||
|
(interactive)
|
||||||
|
(when (region-active-p)
|
||||||
|
(let* ((from (region-beginning))
|
||||||
|
(to (region-end))
|
||||||
|
(remainder (- (point-max) to)))
|
||||||
|
(flush-lines "\|[-\\+]+\|" from to)
|
||||||
|
(flush-lines "^|[\s|:-]+|$" from to)
|
||||||
|
(save-excursion
|
||||||
|
(while (re-search-forward "[\s]+|[\s]+" (- (point-max) remainder) t)
|
||||||
|
(replace-match ",")))
|
||||||
|
(save-excursion
|
||||||
|
(while (re-search-forward "^|\s+\\|\s+|$" (- (point-max) remainder) t)
|
||||||
|
(replace-match ""))))))
|
||||||
|
|
||||||
|
;;; csvivify.el ends here
|
Loading…
Add table
Add a link
Reference in a new issue