26 lines
826 B
EmacsLisp
26 lines
826 B
EmacsLisp
;;; 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
|