Guest User

my-csv-column-width.el

a guest
Jul 6th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 1.22 KB | None | 0 0
  1. ;;; `csv-align-fields' の列の幅を設定可能にする
  2.  
  3. (defcustom my-csv-column-width 25
  4.   "`csv-align-fields' でCSVテキストを整列表示させたときの列の最小幅。"
  5.   :type 'integer)
  6. (make-variable-buffer-local 'my-csv-column-width)
  7.  
  8. (advice-add 'csv--column-widths :filter-return
  9.             (lambda (widths)
  10.               (mapcar (lambda (width) (max my-csv-column-width width))
  11.                       widths)))
  12.  
  13. (defun my-csv-align-fields (width hard beg end)
  14.   "CSV列の最小幅設定 `my-csv-column-width' を更新して `csv-align-fields' を呼ぶ。"
  15.   (interactive (cons (read-number "Set my-csv-column-width to: "
  16.                                   my-csv-column-width)
  17.                      (cons current-prefix-arg
  18.                            (if (use-region-p)
  19.                                (list (region-beginning) (region-end))
  20.                              (list (point-min) (point-max))))))
  21.   (message "CSV column width set to %d (was %d)"
  22.            width my-csv-column-width)
  23.   (setq my-csv-column-width width)
  24.   (csv-align-fields hard beg end))
  25.  
  26. ;; C-c A で `my-csv-align-fields'。
  27. (eval-after-load "csv-mode"
  28.   `(define-key csv-mode-map (kbd "C-c A") #'my-csv-align-fields))
Add Comment
Please, Sign In to add comment