Develop and Download Open Source Software

Browse CVS Repository

Contents of /kogiku/kogiku/kogiku.el

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.11 - (show annotations) (download)
Mon Feb 9 12:29:37 2004 UTC (20 years, 2 months ago) by shirai
Branch: MAIN
Changes since 1.10: +28 -6 lines
(kogiku-file-name-completion): Regexp の間違いを訂正。
(kogiku-busetsu-regexp): 消した。
(kogiku-migemo-get-pattern): 上記に伴う変更。また、余分な migemo
変数の拘束をやめた。
(kogiku-double-dollars): Emacs21 以外でも動くようにした。
(kogiku-minibuffer-prompt-string): Prompt に表示する文字列。
(kogiku-minibuffer-prompt-e21): Emacs21 で prompt に "(kogiku)" と
表示する関数。
(kogiku-minibuffer-prompt-not-e21): Emacs21 以外で prompt に
"kogiku:" と表示する関数。
(kogiku-completion-complete, kogiku-must-match-complete):
`kogiku-minibuffer-prompt(-not)-e21' を呼ぶようにした。

1 ;;; kogiku.el - reading file and directory names with migemo service
2
3 ;; Copyright (C) 2004 Masatake YAMATO
4
5 ;; Author: Masatake YAMATO <jet@gyve.org>
6
7 ;; This file is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation; either version 2, or (at your option)
10 ;; any later version.
11
12 ;; This file is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
16
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GNU Emacs; see the file COPYING. If not, write to
19 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 ;; Boston, MA 02111-1307, USA.
21
22 ;;; Commentary:
23 ;; ?ユ??????<?ゃ???????ュ????migemo??篏帥?c??亜?????????????違?????с????
24
25 ;; (篁???戎?c???????????с??????)篁ュ??windows??eadow??篏帥?c??????????????
26 ;; ?????鴻????????(絎?????????茹?)?????吟?<?障???????????<?ゃ????find-file??
27 ;; ????????????篁???羲√?紊?????綽?荀???????)???<?ゃ????????絎?????絽吾???√????/span>
28 ;; ???????????障??????"desukutoxtupu"?????泣???????????????鴻???????????後???
29 ;; ????return]?с???c????絎????????????с???障??????
30
31 ;; ?????鴻??????????????絎??????????違??"desktop"???? "de"[tab]?????ф?????/span>
32 ;; ???違?????????????障??????鐚?migemo??篏帥???違??????絎??障???????????с??????
33 ;; ?с????"desktop"??"de"??migemo?ф?ユ????????????絮???羝??帥?????帥?若?潟??
34 ;; ?上???????c???????????????????????<?ゃ???????????у???????違?????<?ゃ????
35 ;; ????絎?("desktop"???????鴻???????????????????????茖?絎???茖???????
36 ;; ("de"???????鴻????????????????????????????????с???障????
37
38 ;; kogiku.el??igemo.el????NU Emacs 21???絖????????障????migemo.el??/span>
39 ;; ??篏????障??腆肴????????????kogiku.el?????若?????鴻?????c?????c??????
40 ;; ???c??????????舟??.emacs? (require 'kogiku)???吾????????macs????
41 ;; 莎桁?????障????migemo? http://migemo.namazu.rog ?????ユ???с???障????
42
43 ;;; Acknowledgments:
44
45 ;; Some code used in `kogiku-file-name-completion'
46 ;; and `kogiku-try-completion-regexp' are copied from
47 ;; http://www.bookshelf.jp/cgi-bin/goto.cgi?file=meadow&node=kogiku
48 ;; (MeadowMemo maintained by Akihisa Matsushita <akihisa@mail.ne.jp>).
49
50 ;; `kogiku-read-file-name-internal' are
51 ;; translated from emacs/src/fileio.c::read-file-name-internal
52 ;; in elisp.
53
54 ;;; Version:
55 ;; 2.0.2.
56
57 ;;; History:
58 ;; 2.0.2
59 ;; -- inlucde shirai's patch
60 ;; -- introduce custom
61 ;;
62 ;; 2.0.1 -- update `Acknowledgments'.
63 ;;
64 ;; 2.0 -- rewrite.
65
66 ;;; Code:
67
68 (eval-when-compile
69 (require 'cl)
70 (require 'migemo))
71
72 (defgroup kogiku nil
73 "reading file and directory name with migemo service"
74 :group 'convenience)
75
76 (defcustom kogiku-completion-key "\t"
77 ""
78 :group 'kogiku
79 :type 'sexp
80 :options '("\t" "\e\t")
81 :set (lambda (symbol value)
82 (set-default symbol value)
83 (setq kogiku-original-function-for-minibuffer-local-completion-map
84 (let ((tmp (lookup-key minibuffer-local-completion-map value)))
85 (if (or (null tmp) (eq tmp 'kogiku-completion-complete))
86 'minibuffer-complete
87 tmp))
88 kogiku-original-function-for-minibuffer-local-must-match-map
89 (let ((tmp (lookup-key minibuffer-local-must-match-map value)))
90 (if (or (null tmp) (eq tmp 'kogiku-must-match-complete))
91 'minibuffer-complete
92 tmp)))
93 (define-key
94 minibuffer-local-completion-map
95 value
96 'kogiku-completion-complete)
97 (define-key
98 minibuffer-local-must-match-map
99 value
100 'kogiku-must-match-complete)))
101
102 (defcustom kogiku-minibuffer-prompt-string "kogiku"
103 "*Kogiku indicator in minibuffer."
104 :group 'kogiku
105 :type 'string)
106
107 (defvar kogiku-original-function-for-minibuffer-local-completion-map
108 nil)
109
110 (defvar kogiku-original-function-for-minibuffer-local-must-match-map
111 nil)
112
113 (defun kogiku-completion-complete (&optional arg)
114 (interactive "P")
115 (when (and arg
116 (eq minibuffer-completion-table 'read-file-name-internal))
117 (setq minibuffer-completion-table 'kogiku-read-file-name-internal)
118 (kogiku-minibuffer-prompt-e21))
119 (funcall kogiku-original-function-for-minibuffer-local-completion-map)
120 (kogiku-minibuffer-prompt-not-e21))
121
122 (defun kogiku-must-match-complete (&optional arg)
123 (interactive "P")
124 (when (and arg
125 (eq minibuffer-completion-table 'read-file-name-internal))
126 (setq minibuffer-completion-table 'kogiku-read-file-name-internal)
127 (kogiku-minibuffer-prompt-e21))
128 (funcall kogiku-original-function-for-minibuffer-local-must-match-map)
129 (kogiku-minibuffer-prompt-not-e21))
130
131 (defun kogiku-minibuffer-prompt-e21 ()
132 (when (fboundp 'field-beginning)
133 (let ((prompt (buffer-substring (point-min) (field-beginning)))
134 (buffer-read-only nil)
135 (inhibit-read-only t)
136 (props (text-properties-at (point-min))))
137 (save-excursion
138 (when (string-match ":[^:]*" prompt)
139 (setq prompt (concat (substring prompt 0 (match-beginning 0))
140 (format " (%s)" kogiku-minibuffer-prompt-string)
141 (substring prompt (match-beginning 0))))
142 (set-text-properties 0 (length prompt) props prompt)
143 (delete-region (point-min) (field-beginning))
144 (goto-char (point-min))
145 (insert prompt))))))
146
147 (defvar kogiku-minibuffer-prompt-overlay nil)
148
149 (defun kogiku-minibuffer-prompt-not-e21 ()
150 (unless (fboundp 'field-beginning)
151 (when (eq minibuffer-completion-table 'kogiku-read-file-name-internal)
152 (if kogiku-minibuffer-prompt-overlay
153 (move-overlay kogiku-minibuffer-prompt-overlay
154 (point-min) (1+ (point-min)))
155 (setq kogiku-minibuffer-prompt-overlay
156 (make-overlay (point-min) (1+ (point-min)))))
157 (overlay-put kogiku-minibuffer-prompt-overlay
158 'before-string
159 (format "%s: " kogiku-minibuffer-prompt-string))
160 (overlay-put kogiku-minibuffer-prompt-overlay 'evaporate t))))
161
162 (if (fboundp 'compare-strings)
163 (defalias 'kogiku-compare-strings 'compare-strings)
164 (defun kogiku-compare-strings (string1 start1 end1 string2 start2 end2)
165 "Convenience `compare-strings' for XEmacs."
166 (let* ((str1 (substring string1 start1 end1))
167 (str2 (substring string2 start2 end2))
168 (len (min (length str1) (length str2)))
169 (i 0))
170 (if (string= str1 str2)
171 t
172 (setq i (catch 'ignore
173 (while (< i len)
174 (when (not (eq (aref str1 i) (aref str2 i)))
175 (throw 'ignore i))
176 (setq i (1+ i)))
177 i))
178 (1+ i)))))
179
180 (defun kogiku-try-completion-regexp (regexp all-list)
181 (if (= (length regexp) 0)
182 ""
183 (let (common)
184 (setq common
185 (substring
186 (car all-list)
187 0
188 (apply 'min
189 (mapcar
190 (lambda (a)
191 (apply 'min
192 (mapcar
193 (lambda (b)
194 (- (abs
195 (kogiku-compare-strings a 0 nil
196 b 0 nil))
197 1))
198 (delete a all-list))))
199 all-list))))
200 common)))
201
202 (defun kogiku-migemo-get-pattern (string)
203 (let ((migemo-pattern-alist migemo-pattern-alist)
204 (migemo-white-space-regexp " *"))
205 (let ((case-fold-search nil))
206 (while (string-match "[^a-zA-Z]\\([a-z]+\\)" string)
207 (setq string
208 (replace-match (capitalize (match-string 1 string)) nil nil string 1))))
209 (migemo-get-pattern string)))
210
211 (defun kogiku-file-name-completion (string dir &optional all)
212 (let* ((expanded-string (expand-file-name string dir))
213 (files (directory-files dir))
214 (pattern
215 (if (string-match "/$" expanded-string)
216 ""
217 (concat "^\\("
218 (cond
219 ((string-match "\\cj$" string)
220 string)
221 ((string-match "^\\(\\(\\Cj*\\)?\\cj+\\)\\(\\Cj+\\)$" string)
222 (concat (match-string 1 string)
223 "\\("
224 (kogiku-migemo-get-pattern (match-string 3 string))
225 "\\)"))
226 (t
227 (kogiku-migemo-get-pattern (file-name-nondirectory string))))
228 "\\)")))
229 (candidates (delete nil
230 (mapcar
231 (lambda (f)
232 (if (string-match pattern f)
233 (if (file-directory-p (expand-file-name f dir))
234 ;; ???c????????? / ?х??????????/span>
235 (file-name-as-directory f)
236 f)))
237 files)))
238 (count (length candidates))
239 common)
240 (if all
241 candidates
242 (cond
243 ((eq count 0) nil)
244 ((eq count 1) (let ((candidate (car candidates)))
245 (if (file-directory-p candidate)
246 (file-name-as-directory candidate)
247 candidate)))
248 (t
249 (if (null (delete nil (mapcar (lambda (candidate)
250 (string-match "\\cj" candidate))
251 candidates)))
252 ;; ????????茖????ユ??????????с???????翫??????絽檎????
253 ;; `try-completion' ???若???с?障????????
254 (try-completion string (mapcar 'list candidates))
255 (setq common (kogiku-try-completion-regexp pattern candidates))
256 (if (eq (length common) 0) string common)))))))
257
258 (defun kogiku-file-name-all-completions (string dir)
259 (kogiku-file-name-completion string dir t))
260
261 (defun kogiku-double-dollars (input)
262 (let ((ret ""))
263 (while (string-match "\\$" input)
264 (setq ret (concat ret
265 (substring input 0 (match-beginning 0))
266 "$$"))
267 (setq input (substring input (match-end 0))))
268 (concat ret input)))
269
270 (defun kogiku-read-file-name-internal (string dir action)
271 (block nil
272 (unless (boundp 'read-file-name-predicate)
273 (setq read-file-name-predicate nil))
274 (let ((realdir dir)
275 (name string)
276 (orig-string)
277 (changed 0)
278 (val)
279 (specdir))
280 (if (eq 0 (length string))
281 (if (eq action 'lambda)
282 (return nil))
283 (setq orig-string string)
284 (setq string (substitute-in-file-name string))
285 (setq changed (null (string-equal string orig-string)))
286 (setq name (file-name-nondirectory string))
287 (setq val (file-name-directory string))
288 (if (not (null val))
289 (setq realdir (expand-file-name val realdir))))
290 (cond
291 ((null action)
292 (setq specdir (file-name-directory string))
293 (setq val (kogiku-file-name-completion name realdir))
294 (return (if (not (stringp val))
295 (if changed
296 (kogiku-double-dollars string)
297 val)
298 (if (not (null specdir))
299 (concat specdir val)
300 (kogiku-double-dollars val)
301 ))))
302 ((eq action t)
303 (let ((all (kogiku-file-name-all-completions name realdir)))
304 (unless (or (null read-file-name-predicate)
305 (eq read-file-name-predicate 'file-exists-p))
306 (delete-if (lambda (x)
307 (not (funcall read-file-name-predicate x))
308 all)))
309 (return all)))
310 ((eq action 'lambda)
311 (return (if read-file-name-predicate
312 (funcall read-file-name-predicate string)
313 (file-exists-p string))))))))
314
315 (provide 'kogiku)
316 ;; kogiku.el ends here

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26