-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathui-dictionary.el
executable file
·109 lines (86 loc) · 3.68 KB
/
ui-dictionary.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
(defun translate-at-point ()
(interactive)
(if (setq bounds (bounds-of-thing-at-point 'word))
(translation-buffer (buffer-substring-no-properties
(car bounds)
(cdr bounds)))
(message "don't find any word.")))
;;(translate-at-point)
(defun translation-buffer (content)
(let ((buffer-name "*translation-buffer*")
(command (concatenate 'string "sbcl ~/emacs/external-git-repo/dictionary/dictionary-cli2.lisp " content)))
(with-output-to-temp-buffer buffer-name
(start-process-shell-command "execute-process" buffer-name command))
(select-window (display-buffer buffer-name))
(set-buffer buffer-name)
(insert content)))
(local-set-key (kbd "C-c C-t") 'translate-at-point)
;;(translation-buffer "jopa")
(setq buffer (get-buffer-create "*test-sbcl*"))
(setq process (start-process "test process sbcl" buffer "sbcl"))
(select-window (display-buffer buffer))
(unless (equal 'run (process-status process))
(message "wrong"))
(kill-process process)
(process-command process)
(process-status process)
(process-filter process)
(process-send-string process "(+ 2 3 12)\n")
(process-send-string process "(load \"~/emacs/external-git-repo/dictionary/dictionary-init.lisp\")\n")
(process-send-string process "(db-dictionary:search-in-db-by-regexp \"jopa\")\n")
;; (defun slime-output-filter (process string)
;; (with-current-buffer (process-buffer process)
;; (when (and (plusp (length string))
;; (eq (process-status slime-buffer-connection) 'open))
;; (slime-write-string string))))
(setq kept nil)
(defun my-output-filter (process string)
(with-current-buffer (process-buffer process)
(setf kept (cons string kept))
(insert string)))
(set-process-filter process 'my-output-filter)
;; notice doesn't work.
;; (add-function :before (process-filter process) 'my-output-filter)
(setq translate-output-buffer nil)
(get-buffer-create "*translate-output*")
;; run sequence.
(defun run-translation-process()
(setq history-of-translation-list nil)
;; (setq buffer (get-buffer-create "*test-sbcl*"))
(setq process nil)
(defun get-process()
(unless (and (processp process) (equal 'run (process-status process)))
(setf process (start-process "sbcl-for-translating-script" (get-buffer-create "*test-sbcl*") "sbcl" "--noinform" "--disable-debugger"))
(process-send-string process "(load \"~/emacs/external-git-repo/dictionary/dictionary-init.lisp\")\n")
(set-process-filter process 'my-output-filter))
process)
(defun get-translate-output-buffer()
(if (get-buffer "*translate-output*")
(get-buffer "*translate-output*")
(get-buffer-create "*translate-output*")))
(defun my-output-filter(process string)
(with-current-buffer (process-buffer process)
(setf history-of-translation-list (cons string history-of-translation-list))
(with-current-buffer (get-translate-output-buffer)
(insert string))
(insert string)))
(defun translate-word-trigger(word)
(process-send-string (get-process) (concatenate 'string "(db-dictionary:search-in-db-by-regexp \"" word "\")\n")))
(defun translate-at-point()
(interactive)
(if (setq bounds (bounds-of-thing-at-point 'word))
(progn
;; todo added scroll cursor to the top of translate-output-buffer buffer.
(with-current-buffer (get-translate-output-buffer)
(goto-char (point-min)))
(display-buffer (get-translate-output-buffer))
(translate-word-trigger (buffer-substring-no-properties
(car bounds)
(cdr bounds))))
(message "don't find any word.")))
(local-set-key (kbd "C-t") 'translate-at-point)
(message "process translation has starded"))
;; end run sequence.
(run-translation-process)
(scroll-down 100000)
(processp)