| 42 |
|
|
| 43 |
;;; Acknowledgments: |
;;; Acknowledgments: |
| 44 |
|
|
| 45 |
;; Some code used in `kogiku-file-name-completion' |
;; Some code used in `kogiku-file-name-completion' |
| 46 |
;; and `kogiku-try-completion-regexp' are copied from |
;; and `kogiku-try-completion-regexp' are copied from |
| 47 |
;; http://www.bookshelf.jp/cgi-bin/goto.cgi?file=meadow&node=kogiku |
;; http://www.bookshelf.jp/cgi-bin/goto.cgi?file=meadow&node=kogiku |
| 48 |
;; (MeadowMemo maintained by Akihisa Matsushita <akihisa@mail.ne.jp>). |
;; (MeadowMemo maintained by Akihisa Matsushita <akihisa@mail.ne.jp>). |
| 49 |
|
|
| 50 |
;; `kogiku-read-file-name-internal' are |
;; `kogiku-read-file-name-internal' are |
| 51 |
;; translated from emacs/src/fileio.c::read-file-name-internal |
;; translated from emacs/src/fileio.c::read-file-name-internal |
| 52 |
;; in elisp. |
;; in elisp. |
| 53 |
|
|
| 54 |
;;; Version: |
;;; Version: |
| 65 |
|
|
| 66 |
;;; Code: |
;;; Code: |
| 67 |
|
|
| 68 |
(eval-when-compile |
(eval-when-compile |
| 69 |
(require 'cl) |
(require 'cl) |
| 70 |
(require 'migemo)) |
(require 'migemo)) |
| 71 |
|
|
| 86 |
|
|
| 87 |
(defvar kogiku-original-function nil) |
(defvar kogiku-original-function nil) |
| 88 |
(defvar kogiku-completion-key "\t") |
(defvar kogiku-completion-key "\t") |
| 89 |
|
(defvar kogiku-minibuffer-prompt-overlay nil) |
| 90 |
|
|
| 91 |
(defun kogiku-complete (&optional arg) |
(defun kogiku-complete (&optional arg) |
| 92 |
(interactive "P") |
(interactive "P") |
| 118 |
(let ((prompt (buffer-substring (point-min) (field-beginning))) |
(let ((prompt (buffer-substring (point-min) (field-beginning))) |
| 119 |
(buffer-read-only nil) |
(buffer-read-only nil) |
| 120 |
(inhibit-read-only t) |
(inhibit-read-only t) |
| 121 |
(props (text-properties-at (point-min)))) |
(props (text-properties-at (point-min))) |
| 122 |
|
(indicator (format " [%s]" kogiku-minibuffer-prompt-string))) |
| 123 |
(save-excursion |
(save-excursion |
| 124 |
(when (string-match ":[^:]*" prompt) |
(if (eq minibuffer-completion-table 'kogiku-read-file-name-internal) |
| 125 |
(setq prompt (concat (substring prompt 0 (match-beginning 0)) |
(when (string-match ":[^:]*" prompt) |
| 126 |
(format " (%s)" kogiku-minibuffer-prompt-string) |
(setq prompt (concat (substring prompt 0 (match-beginning 0)) |
| 127 |
(substring prompt (match-beginning 0)))) |
indicator |
| 128 |
(set-text-properties 0 (length prompt) props prompt) |
(substring prompt (match-beginning 0)))) |
| 129 |
(delete-region (point-min) (field-beginning)) |
(set-text-properties 0 (length prompt) props prompt) |
| 130 |
(goto-char (point-min)) |
(delete-region (point-min) (field-beginning)) |
| 131 |
(insert prompt)))))) |
(goto-char (point-min)) |
| 132 |
|
(insert prompt)) |
| 133 |
(defvar kogiku-minibuffer-prompt-overlay nil) |
(when (string-match (regexp-quote indicator) prompt) |
| 134 |
|
(setq prompt (replace-match "" nil nil prompt)) |
| 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 |
|
|
| 140 |
(defun kogiku-minibuffer-prompt-not-e21 () |
(defun kogiku-minibuffer-prompt-not-e21 () |
| 141 |
(unless (fboundp 'field-beginning) |
(unless (fboundp 'field-beginning) |
| 142 |
(when (eq minibuffer-completion-table 'kogiku-read-file-name-internal) |
(if (eq minibuffer-completion-table 'kogiku-read-file-name-internal) |
| 143 |
(if kogiku-minibuffer-prompt-overlay |
(let ((max (min (point-max) (1+ (point-min))))) |
| 144 |
(move-overlay kogiku-minibuffer-prompt-overlay |
(if kogiku-minibuffer-prompt-overlay |
| 145 |
(point-min) (1+ (point-min))) |
(move-overlay kogiku-minibuffer-prompt-overlay |
| 146 |
(setq kogiku-minibuffer-prompt-overlay |
(point-min) max) |
| 147 |
(make-overlay (point-min) (1+ (point-min))))) |
(setq kogiku-minibuffer-prompt-overlay |
| 148 |
(overlay-put kogiku-minibuffer-prompt-overlay |
(make-overlay (point-min) max))) |
| 149 |
'before-string |
(overlay-put kogiku-minibuffer-prompt-overlay |
| 150 |
(format "%s: " kogiku-minibuffer-prompt-string)) |
'before-string |
| 151 |
(overlay-put kogiku-minibuffer-prompt-overlay 'evaporate t)))) |
(format "%s: " kogiku-minibuffer-prompt-string)) |
| 152 |
|
(overlay-put kogiku-minibuffer-prompt-overlay 'evaporate t)) |
| 153 |
|
(when kogiku-minibuffer-prompt-overlay |
| 154 |
|
(delete-overlay kogiku-minibuffer-prompt-overlay))))) |
| 155 |
|
|
| 156 |
(if (fboundp 'compare-strings) |
(if (fboundp 'compare-strings) |
| 157 |
(defalias 'kogiku-compare-strings 'compare-strings) |
(defalias 'kogiku-compare-strings 'compare-strings) |
| 158 |
(defun kogiku-compare-strings (string1 start1 end1 string2 start2 end2) |
(defun kogiku-compare-strings (string1 start1 end1 string2 start2 end2) |
| 172 |
(1+ i))))) |
(1+ i))))) |
| 173 |
|
|
| 174 |
(defun kogiku-try-completion-regexp (regexp all-list) |
(defun kogiku-try-completion-regexp (regexp all-list) |
| 175 |
(if (= (length regexp) 0) |
(if (= (length regexp) 0) |
| 176 |
"" |
"" |
| 177 |
(let (common) |
(let (common) |
| 178 |
(setq common |
(setq common |
| 179 |
(substring |
(substring |
| 180 |
(car all-list) |
(car all-list) |
| 181 |
0 |
0 |
| 182 |
(apply 'min |
(apply 'min |
| 183 |
(mapcar |
(mapcar |
| 184 |
(lambda (a) |
(lambda (a) |
| 185 |
(apply 'min |
(apply 'min |
| 186 |
(mapcar |
(mapcar |
| 187 |
(lambda (b) |
(lambda (b) |
| 188 |
(- (abs |
(- (abs |
| 189 |
(kogiku-compare-strings a 0 nil |
(kogiku-compare-strings a 0 nil |
| 190 |
b 0 nil)) |
b 0 nil)) |
| 191 |
1)) |
1)) |
| 286 |
(setq specdir (file-name-directory string)) |
(setq specdir (file-name-directory string)) |
| 287 |
(setq val (kogiku-file-name-completion name realdir)) |
(setq val (kogiku-file-name-completion name realdir)) |
| 288 |
(return (if (not (stringp val)) |
(return (if (not (stringp val)) |
| 289 |
(if changed |
(if changed |
| 290 |
(kogiku-double-dollars string) |
(kogiku-double-dollars string) |
| 291 |
val) |
val) |
| 292 |
(if (not (null specdir)) |
(if (not (null specdir)) |
| 293 |
(concat specdir val) |
(setq val (concat specdir val))) |
| 294 |
(kogiku-double-dollars val) |
(kogiku-double-dollars val)))) |
|
)))) |
|
| 295 |
((eq action t) |
((eq action t) |
| 296 |
(let ((all (kogiku-file-name-all-completions name realdir))) |
(let ((all (kogiku-file-name-all-completions name realdir))) |
| 297 |
(unless (or (null read-file-name-predicate) |
(unless (or (null read-file-name-predicate) |
| 298 |
(eq read-file-name-predicate 'file-exists-p)) |
(eq read-file-name-predicate 'file-exists-p)) |
| 299 |
(delete-if (lambda (x) |
(delete-if (lambda (x) |
| 300 |
(not (funcall read-file-name-predicate x)) |
(not (funcall read-file-name-predicate x)) |
| 301 |
all))) |
all))) |
| 302 |
(return all))) |
(return all))) |
| 317 |
(t |
(t |
| 318 |
tmp)))) |
tmp)))) |
| 319 |
(define-key (current-local-map) kogiku-completion-key 'kogiku-complete))) |
(define-key (current-local-map) kogiku-completion-key 'kogiku-complete))) |
| 320 |
|
|
| 321 |
(add-hook 'minibuffer-setup-hook 'kogiku-install-key) |
(add-hook 'minibuffer-setup-hook 'kogiku-install-key) |
| 322 |
|
|
| 323 |
(defun kogiku-uninstall-key () |
(defun kogiku-uninstall-key () |
| 324 |
(when (and (eq minibuffer-completion-table 'read-file-name-internal) |
(when (and (memq minibuffer-completion-table |
| 325 |
|
'(read-file-name-internal kogiku-read-file-name-internal)) |
| 326 |
(eq (lookup-key (current-local-map) kogiku-completion-key) |
(eq (lookup-key (current-local-map) kogiku-completion-key) |
| 327 |
'kogiku-complete))) |
'kogiku-complete)) |
| 328 |
(define-key (current-local-map) kogiku-completion-key kogiku-original-function)) |
(define-key (current-local-map) kogiku-completion-key kogiku-original-function))) |
| 329 |
(add-hook 'minibuffer-exit-hook 'kogiku-uninstall-key) |
|
| 330 |
|
(add-hook 'minibuffer-exit-hook 'kogiku-uninstall-key) |
| 331 |
|
|
| 332 |
(provide 'kogiku) |
(provide 'kogiku) |
| 333 |
;; kogiku.el ends here |
;; kogiku.el ends here |