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.5 - (hide annotations) (download)
Sun Feb 8 18:25:52 2004 UTC (20 years, 2 months ago) by jet
Branch: MAIN
Changes since 1.4: +10 -6 lines
(kogiku-completion-key): 前置引数が
与えられた場合のみmigemoの補完を実行するよう変更した。

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

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