1 ;;; lookup-select.el --- lookup-select-mode
2 ;; Copyright (C) 1999 Lookup Development Team <lookup@ring.gr.jp>
4 ;; Author: Keisuke Nishida <kei@psn.net>
5 ;; Version: $Id: lookup-select.el,v 1.3 2000-10-06 09:40:20 youngs Exp $
7 ;; This file is part of Lookup.
9 ;; Lookup is free software; you can redistribute it and/or modify it
10 ;; under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2 of the License, or
12 ;; (at your option) any later version.
14 ;; Lookup is distributed in the hope that it will be useful, but
15 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with Lookup; if not, write to the Free Software Foundation,
21 ;; Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 (defun lookup-select-display (session)
33 (with-current-buffer (lookup-open-buffer (lookup-select-buffer))
35 (let ((inhibit-read-only t))
37 (insert "Type `m' to select, `u' to unselect, `?' for help.\n\n")
40 (append '((?% "Identifier" "Title" "Method")
41 (?- "----------" "-----" "------"))
43 (list (if (lookup-dictionary-selected-p dic) ?* ? )
44 (lookup-dictionary-id dic)
45 (lookup-dictionary-title dic)
46 (mapconcat 'lookup-method-key
47 (lookup-dictionary-methods dic) "")))
48 (lookup-module-dictionaries
49 (lookup-session-module session)))))
50 (lookup-select-goto-first))
51 (lookup-pop-to-buffer (current-buffer))))
53 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
55 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
57 (defvar lookup-select-mode-map nil
58 "*Keymap for Lookup Select mode.")
60 (unless lookup-select-mode-map
61 (setq lookup-select-mode-map (make-sparse-keymap))
62 (define-key lookup-select-mode-map " " 'lookup-select-next-line)
63 (define-key lookup-select-mode-map "n" 'lookup-select-next-line)
64 (define-key lookup-select-mode-map "p" 'lookup-select-previous-line)
65 (define-key lookup-select-mode-map "\en" 'lookup-history-next)
66 (define-key lookup-select-mode-map "\ep" 'lookup-history-previous)
67 (define-key lookup-select-mode-map "\ef" 'lookup-module-forward)
68 (define-key lookup-select-mode-map "\eb" 'lookup-module-backward)
69 (define-key lookup-select-mode-map "m" 'lookup-select-do-select)
70 (define-key lookup-select-mode-map "u" 'lookup-select-do-unselect)
71 (define-key lookup-select-mode-map "a" 'lookup-select-do-select-all)
72 (define-key lookup-select-mode-map "\C-m" 'lookup-select-do-select-only)
73 (define-key lookup-select-mode-map "d" 'lookup-select-mark-disable)
74 (define-key lookup-select-mode-map "x" 'lookup-select-do-execute)
75 ; (define-key lookup-select-mode-map "i" 'lookup-select-info)
76 (define-key lookup-select-mode-map "M" 'lookup-select-menu)
77 (define-key lookup-select-mode-map "f" 'lookup-select-search-pattern)
78 (define-key lookup-select-mode-map "o" 'delete-other-windows)
79 (define-key lookup-select-mode-map "/" 'lookup-select-text-search)
80 (define-key lookup-select-mode-map "g" 'lookup-select-update)
81 (define-key lookup-select-mode-map "q" 'lookup-suspend)
82 (define-key lookup-select-mode-map "Q" 'lookup-exit)
83 (define-key lookup-select-mode-map "R" 'lookup-restart)
84 (define-key lookup-select-mode-map "?" 'lookup-select-help))
86 (defconst lookup-select-mode-help
87 "Lookup Select
\e$B%b!<%I
\e(B:
89 `n'(ext) -
\e$B<!$N<-=q$X
\e(B `p'(revios) -
\e$BA0$N<-=q$X
\e(B
91 `m'(ark) -
\e$B<-=q$rA*Br
\e(B `u'(nmark) -
\e$B<-=q$rHsA*Br
\e(B
92 `a'(ll) -
\e$BA4$F$N<-=q$rA*Br
\e(B `RET' -
\e$B$=$N<-=q$@$1$rA*Br
\e(B
93 `d'(isable) -
\e$B<-=q$rL58z2=
\e(B (e)`x'(ecute) -
\e$BL58z2=$r<B9T
\e(B
95 `f'(ind) -
\e$B8!:w$r<B9T
\e(B `M'(enu) -
\e$B<-=q$N%a%K%e!<$rI=<(
\e(B
96 `o'(pen) -
\e$B2hLL$r:GBg2=
\e(B `/' -
\e$B$=$N<-=q$+$iA4J88!:w
\e(B
98 `q' -
\e$B%P%C%U%!$rH4$1$k
\e(B `g' -
\e$B%b%8%e!<%k$r=i4|2=$7D>$9
\e(B
99 `Q' - Lookup
\e$B$r=*N;$9$k
\e(B `R' - Lookup
\e$B$r:F5/F0$9$k
\e(B")
101 (defvar lookup-select-mode-hook nil)
103 (defun lookup-select-mode ()
105 (kill-all-local-variables)
106 (buffer-disable-undo)
107 (setq major-mode 'lookup-select-mode)
108 (setq mode-name "Select")
109 (setq mode-line-buffer-identification '("Lookup:%12b"))
110 (setq buffer-read-only t)
111 (setq truncate-lines t)
112 (use-local-map lookup-select-mode-map)
113 (run-hooks 'lookup-select-mode-hook))
116 ;:: Interactive commands
119 (defun lookup-select-next-line ()
120 "
\e$B<!$N9T$K?J$`!#
\e(B"
122 (if (eobp) (ding) (forward-line)))
124 (defun lookup-select-previous-line ()
125 "
\e$BA0$N9T$KLa$k!#
\e(B"
127 (if (bobp) (ding) (forward-line -1)))
129 (defun lookup-select-do-select ()
130 "
\e$B%]%$%s%H9T$N<-=q$rA*Br$9$k!#
\e(B"
132 (lookup-select-set-selected t))
134 (defun lookup-select-do-unselect ()
135 "
\e$B%]%$%s%H9T$N<-=q$rHsA*Br$K$9$k!#
\e(B"
137 (lookup-select-set-selected nil))
139 (defun lookup-select-toggle-selected ()
140 "
\e$B%]%$%s%H9T$N<-=q$NA*Br>uBV$r%H%0%k$9$k!#
\e(B"
142 (let ((dict (lookup-select-point-dictionary)))
143 (lookup-select-set-selected
144 (not (lookup-dictionary-selected-p dict)))))
146 (defun lookup-select-do-select-all ()
147 "
\e$BA4$F$N<-=q$rA*Br$9$k!#
\e(B"
150 (lookup-select-goto-first)
152 (lookup-select-set-selected t))))
154 (defun lookup-select-do-select-only ()
155 "
\e$B%]%$%s%H9T$N<-=q$N$_$rA*Br$9$k!#
\e(B"
157 (if (not (lookup-select-point-dictionary))
158 (error "No dictionary on current line")
160 (lookup-select-goto-first)
162 (lookup-select-set-selected nil)))
163 (lookup-select-set-selected t t)))
165 (defun lookup-select-mark-disable ()
166 "
\e$B%]%$%s%H9T$N<-=q$KL58z2=$N%^!<%/$rIU$1$k!#
\e(B"
168 (lookup-select-mark ?D t))
170 (defun lookup-select-do-execute ()
171 "
\e$BL58z2=$r<B9T$9$k!#
\e(B"
174 (lookup-select-goto-first)
175 (let* ((inhibit-read-only t)
176 (module (lookup-session-module lookup-current-session))
177 (dicts (lookup-module-dictionaries module)))
178 (while (re-search-forward "^D" nil t)
179 (setq dicts (delq (lookup-select-point-dictionary) dicts))
180 (kill-region (progn (beginning-of-line) (point))
181 (progn (forward-line) (point))))
182 (lookup-module-set-dictionaries module dicts))))
184 (defun lookup-select-menu ()
185 "
\e$B<-=q$,%a%K%e!<$KBP1~$7$F$$$k>l9g!"$=$l$r;2>H$9$k!#
\e(B"
187 (let* ((dict (lookup-select-point-dictionary))
188 (entries (lookup-vse-get-menu dict)))
190 (let* ((module (lookup-session-module lookup-current-session))
191 (title (lookup-dictionary-title dict))
192 (query (lookup-make-query 'reference title)))
193 (lookup-display-entries module query entries))
194 (error "This dictionary has no menu"))))
196 (defun lookup-select-search-pattern (pattern)
197 "
\e$BA*Br$5$l$?<-=q$+$i8!:w$r9T$J$&!#
\e(B"
198 (interactive (list (lookup-read-string "Look up" nil 'lookup-input-history)))
199 (lookup-search-pattern (lookup-session-module lookup-last-session) pattern))
201 (defun lookup-select-text-search (string &optional force)
202 "
\e$B%]%$%s%H9T$N<-=q$+$iA4J88!:w$r9T$J$&!#
\e(B"
204 (list (let ((dictionary (lookup-select-point-dictionary)))
205 (if (memq 'text (lookup-dictionary-methods dictionary))
206 (lookup-read-string "Look up" nil 'lookup-input-history)
207 (error "This dictionary does not support text search")))
209 (let ((module (lookup-session-module lookup-current-session))
210 (dictionary (lookup-select-point-dictionary))
211 (query (lookup-make-query 'text string)))
212 (message "searcing...")
213 (lookup-display-entries module query
214 (lookup-vse-search-query dictionary query))
215 (message "searcing...done")))
217 (defun lookup-select-update ()
218 "
\e$B8=:_$N8!:w%b%8%e!<%k$r=i4|2=$7D>$9!#
\e(B
219 \e$B$?$@$7@_Dj%U%!%$%k$rJQ99$7$?>l9g$K$O!"JQ99$rH?1G$9$k$K$O
\e(B
220 \\[lookup-restart]
\e$B$rMQ$$$kI,MW$,$"$k!#
\e(B"
222 (let ((module (lookup-session-module lookup-current-session)))
223 (message "Updating %s..." (lookup-module-name module))
224 (lookup-module-clear module)
225 (lookup-module-init module)
226 (lookup-select-dictionary module)
227 (message "Updating %s...done" (lookup-module-name module))))
229 (defun lookup-select-help ()
230 "Select
\e$B%b!<%I$N4J0W%X%k%W$rI=<($9$k!#
\e(B"
232 (with-current-buffer (lookup-open-buffer (lookup-help-buffer))
234 (let ((inhibit-read-only t))
236 (insert lookup-select-mode-help))
237 (lookup-display-help (current-buffer))))
240 ;:: Internal functions
243 (defun lookup-select-goto-first ()
244 (goto-char (point-min))
247 (defun lookup-select-point-dictionary ()
251 (if (looking-at "[^ ]+") (lookup-get-dictionary (match-string 0)))))
253 (defun lookup-select-set-selected (value &optional dont-move)
254 (let ((dict (lookup-select-point-dictionary)))
256 (lookup-dictionary-set-selected dict value)
257 (lookup-select-mark (if value ?* ? ) (not dont-move)))))
259 (defun lookup-select-mark (mark &optional down-after)
261 (let ((inhibit-read-only t))
264 (insert-char mark 1)))
265 (if down-after (forward-line)))
267 (provide 'lookup-select)
269 ;;; lookup-select.el ends here