Develop and Download Open Source Software

Browse CVS Repository

Annotation of /kogiku/kogiku/kogiku.el

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


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

1 jet 1.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     (defvar kogiku-original-function-for-minibuffer-local-completion-map
103     nil)
104    
105     (defvar kogiku-original-function-for-minibuffer-local-must-match-map
106     nil)
107    
108 jet 1.5 (defun kogiku-completion-complete (&optional arg)
109     (interactive "P")
110 shirai 1.10 (when (and arg
111     (eq minibuffer-completion-table 'read-file-name-internal))
112     (setq minibuffer-completion-table 'kogiku-read-file-name-internal)
113     (kogiku-minibuffer-prompt))
114     (funcall kogiku-original-function-for-minibuffer-local-completion-map))
115 jet 1.1
116 jet 1.5 (defun kogiku-must-match-complete (&optional arg)
117     (interactive "P")
118 shirai 1.10 (when (and arg
119     (eq minibuffer-completion-table 'read-file-name-internal))
120     (setq minibuffer-completion-table 'kogiku-read-file-name-internal)
121     (kogiku-minibuffer-prompt))
122     (funcall kogiku-original-function-for-minibuffer-local-must-match-map))
123    
124     (defun kogiku-minibuffer-prompt ()
125     (when (fboundp 'field-beginning)
126     (let ((prompt (buffer-substring (point-min) (field-beginning)))
127     (buffer-read-only nil)
128     (inhibit-read-only t)
129     (props (text-properties-at (point-min))))
130     (save-excursion
131     (when (string-match ":[^:]*" prompt)
132     (setq prompt (concat (substring prompt 0 (match-beginning 0))
133     " (kogiku)"
134     (substring prompt (match-beginning 0))))
135     (set-text-properties 0 (length prompt) props prompt)
136     (delete-region (point-min) (field-beginning))
137     (goto-char (point-min))
138     (insert prompt))))))
139 jet 1.1
140     (if (fboundp 'compare-strings)
141     (defalias 'kogiku-compare-strings 'compare-strings)
142     (defun kogiku-compare-strings (string1 start1 end1 string2 start2 end2)
143     "Convenience `compare-strings' for XEmacs."
144     (let* ((str1 (substring string1 start1 end1))
145     (str2 (substring string2 start2 end2))
146     (len (min (length str1) (length str2)))
147     (i 0))
148     (if (string= str1 str2)
149     t
150     (setq i (catch 'ignore
151     (while (< i len)
152     (when (not (eq (aref str1 i) (aref str2 i)))
153     (throw 'ignore i))
154     (setq i (1+ i)))
155     i))
156     (1+ i)))))
157    
158     (defun kogiku-try-completion-regexp (regexp all-list)
159     (if (= (length regexp) 0)
160     ""
161     (let (common)
162     (setq common
163     (substring
164     (car all-list)
165     0
166     (apply 'min
167     (mapcar
168     (lambda (a)
169     (apply 'min
170     (mapcar
171     (lambda (b)
172     (- (abs
173     (kogiku-compare-strings a 0 nil
174     b 0 nil))
175     1))
176     (delete a all-list))))
177     all-list))))
178     common)))
179    
180     (defun kogiku-migemo-get-pattern (string)
181 shirai 1.2 (let ((migemo-pattern-alist migemo-pattern-alist)
182     (migemo-white-space-regexp " *"))
183 jet 1.1 (let ((case-fold-search nil))
184     (while (string-match "[^a-zA-Z]\\([a-z]+\\)" string)
185     (setq string
186 shirai 1.7 (replace-match (capitalize (match-string 1 string)) nil nil string 1))))
187 jet 1.1 (migemo-get-pattern string)))
188    
189     (defun kogiku-file-name-completion (string dir &optional all)
190     (let* ((expanded-string (expand-file-name string dir))
191     (files (directory-files dir))
192     (pattern
193     (if (string-match "/$" expanded-string)
194     ""
195     (concat "^\\("
196     (cond
197     ((string-match "\\cj$" string)
198     string)
199 shirai 1.6 ((string-match "^\\(\\(\\Cj*\\)?\\cj+\\)\\(\\Cj+\\)$" string)
200 jet 1.1 (concat (match-string 1 string)
201     "\\("
202 shirai 1.6 (kogiku-migemo-get-pattern (match-string 3 string))
203 jet 1.1 "\\)"))
204     (t
205     (kogiku-migemo-get-pattern (file-name-nondirectory string))))
206     "\\)")))
207 jet 1.3 (candidates (delete nil
208 jet 1.1 (mapcar
209     (lambda (f)
210     (if (string-match pattern f)
211     (if (file-directory-p (expand-file-name f dir))
212     ;; ???c????????? / ?х??????????/span>
213     (file-name-as-directory f)
214     f)))
215     files)))
216 jet 1.3 (count (length candidates))
217 jet 1.1 common)
218     (if all
219 jet 1.3 candidates
220 jet 1.1 (cond
221     ((eq count 0) nil)
222 jet 1.3 ((eq count 1) (let ((candidate (car candidates)))
223 jet 1.1 (if (file-directory-p candidate)
224     (file-name-as-directory candidate)
225     candidate)))
226     (t
227 jet 1.3 (if (null (delete nil (mapcar (lambda (candidate)
228     (string-match "\\cj" candidate))
229     candidates)))
230     ;; ????????茖????ユ??????????с???????翫??????絽檎????
231     ;; `try-completion' ???若???с?障????????
232 shirai 1.4 (try-completion string (mapcar 'list candidates))
233 jet 1.3 (setq common (kogiku-try-completion-regexp pattern candidates))
234     (if (eq (length common) 0) string common)))))))
235 jet 1.1
236     (defun kogiku-file-name-all-completions (string dir)
237     (kogiku-file-name-completion string dir t))
238    
239 jet 1.3 (defun kogiku-double-dollars (input)
240 shirai 1.8 (let ((ret ""))
241     (while (string-match "\\$" input)
242     (setq ret (concat ret
243     (substring input 0 (match-beginning 0))
244     "$$"))
245     (setq input (substring input (match-end 0))))
246     (concat ret input)))
247 jet 1.3
248 jet 1.1 (defun kogiku-read-file-name-internal (string dir action)
249     (block nil
250     (unless (boundp 'read-file-name-predicate)
251     (setq read-file-name-predicate nil))
252     (let ((realdir dir)
253     (name string)
254     (orig-string)
255     (changed 0)
256     (val)
257     (specdir))
258     (if (eq 0 (length string))
259     (if (eq action 'lambda)
260     (return nil))
261     (setq orig-string string)
262     (setq string (substitute-in-file-name string))
263     (setq changed (null (string-equal string orig-string)))
264     (setq name (file-name-nondirectory string))
265     (setq val (file-name-directory string))
266     (if (not (null val))
267     (setq realdir (expand-file-name val realdir))))
268     (cond
269     ((null action)
270     (setq specdir (file-name-directory string))
271     (setq val (kogiku-file-name-completion name realdir))
272     (return (if (not (stringp val))
273     (if changed
274 jet 1.3 (kogiku-double-dollars string)
275 jet 1.1 val)
276     (if (not (null specdir))
277     (concat specdir val)
278 jet 1.3 (kogiku-double-dollars val)
279 jet 1.1 ))))
280     ((eq action t)
281     (let ((all (kogiku-file-name-all-completions name realdir)))
282     (unless (or (null read-file-name-predicate)
283     (eq read-file-name-predicate 'file-exists-p))
284     (delete-if (lambda (x)
285     (not (funcall read-file-name-predicate x))
286     all)))
287     (return all)))
288     ((eq action 'lambda)
289     (return (if read-file-name-predicate
290     (funcall read-file-name-predicate string)
291     (file-exists-p string))))))))
292    
293     (provide 'kogiku)
294     ;; kogiku.el ends here

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