Skip to content

Instantly share code, notes, and snippets.

@ichiban
Created July 6, 2012 08:02
Show Gist options
  • Save ichiban/3058843 to your computer and use it in GitHub Desktop.
Save ichiban/3058843 to your computer and use it in GitHub Desktop.
TSV to ruby
(require 'cl)
(defun tsv-to-ruby (&optional b e)
"TSV to ruby"
(interactive "r")
(lexical-let ((str (buffer-substring b e)))
(delete-region b e)
(insert (mapconcat #'identity
(list "["
(mapconcat #'tsv-to-ruby-line (split-string str "\n") ",\n ")
"]")
""))))
(defun tsv-to-ruby-line (line)
(mapconcat #'identity
(list "["
(mapconcat #'tsv-to-ruby-elem (split-string line "\t") ", ")
"]")
""))
(defun tsv-to-ruby-elem (elem)
(format "%S" elem))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment