-
Notifications
You must be signed in to change notification settings - Fork 1
/
csv-mode.el
executable file
·66 lines (61 loc) · 1.75 KB
/
csv-mode.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
(defun bartuer-csv-load ()
(interactive)
(convert-csv-to-org-table)
(orgtbl-mode t)
)
(defun switch-to-dbview ()
"convert file to sqlite and change to dbview buffer"
(interactive)
(save-buffer)
(convert-csv-to-sqlite3 (buffer-file-name))
(let* ((table_name
(file-name-sans-extension
(file-name-nondirectory
(buffer-file-name))))
(dir_name
(file-name-directory
(buffer-file-name)))
(database_name (concat
dir_name
table_name
".db"))
(view_name (concat table_name ".view")))
(convert-sqlite3-to-org-table-annoted-by-record-list database_name)
(pop-to-buffer view_name))
)
(defvar csv-mode-map
(let ((map (make-keymap)))
(define-key map "\C-j" 'switch-to-dbview)
map)
"mode map for csv-mode"
)
(defun csv-mode-before-save ()
"if there is db backend, save through it, if not, save directly"
(interactive)
(let* ((table_name
(file-name-sans-extension
(file-name-nondirectory
(buffer-file-name))))
(database_name
(concat
(file-name-directory
(buffer-file-name))
table_name ".db"))
)
;; maybe modified both in view and csv buffer, how to resolve conflict ?
;; should save through to csv when save db
(goto-char (point-min))
(when (org-at-table-p (point))
(convert-org-table-to-csv))
)
)
(defun csv-mode ()
"Major mode for csv"
(interactive)
(kill-all-local-variables)
(add-hook 'before-save-hook 'csv-mode-before-save nil t)
(setq mode-name "csv")
(setq truncate-lines t)
(use-local-map csv-mode-map)
(run-hooks 'csv-mode-hook))
(provide 'csv-mode)