diff options
author | Kyle Meyer <kyle@kyleam.com> | 2014-09-28 01:18:18 -0400 |
---|---|---|
committer | Kyle Meyer <kyle@kyleam.com> | 2014-09-28 01:18:18 -0400 |
commit | bf24b6b129620726943183169498a0f29949bc94 (patch) | |
tree | 12c25901a03bb87a563bf174cd765342989f19a4 /lisp | |
parent | 31c0a8283b8c7ec08319ddd8f304080422384691 (diff) | |
download | emacs.d-bf24b6b129620726943183169498a0f29949bc94.tar.gz |
Add columnify-file
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/init-text.el | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/lisp/init-text.el b/lisp/init-text.el index c733927..ecd4831 100644 --- a/lisp/init-text.el +++ b/lisp/init-text.el @@ -31,4 +31,29 @@ is non-nil, the region is copied with `x-select-text'." (when arg (x-select-text (buffer-substring-no-properties (point-min) (point-max)))))) +(defun km/columnify-file (delim) + "Separate current file on DELIM using column program. + +By default, DELIM is set to \",\". With a single prefix argument, +use whitespace as the delimiter. With two prefix arguments, +prompt for a delimiter. + +If a columnified buffer already exists, just switch to it." + (interactive (list (cond ((not current-prefix-arg) ",") + ((> (prefix-numeric-value current-prefix-arg) 4) + (read-string "Delimiter: ")) + (t nil)))) + (let* ((bufname (buffer-name)) + (output-buffer-name (concat "*cols: " bufname "*")) + (output-buffer (get-buffer output-buffer-name)) + (fname (file-relative-name buffer-file-name)) + (col-args '("-t"))) + (unless output-buffer + (setq output-buffer (get-buffer-create output-buffer-name)) + (when delim + (add-to-list 'col-args (format "-s'%s'" delim))) + (apply 'call-process "column" fname output-buffer nil + col-args)) + (switch-to-buffer output-buffer))) + (provide 'init-text) |