| 73 |
"reading file and directory name with migemo service" |
"reading file and directory name with migemo service" |
| 74 |
:group 'convenience) |
:group 'convenience) |
| 75 |
|
|
|
(defcustom kogiku-minibuffer-prompt-string "kogiku" |
|
|
"*Kogiku indicator in minibuffer." |
|
|
:group 'kogiku |
|
|
:type 'string) |
|
|
|
|
| 76 |
(defcustom kogiku-enable-once nil |
(defcustom kogiku-enable-once nil |
| 77 |
"*If non-nil, kogiku effects a one time when call with a prefix argument. |
"*If non-nil, kogiku effects a one time when call with a prefix argument. |
| 78 |
If nil, kogiku toggle with a prefix argument." |
If nil, kogiku toggle with a prefix argument." |
| 84 |
:group 'kogiku |
:group 'kogiku |
| 85 |
:type 'sexp) |
:type 'sexp) |
| 86 |
|
|
| 87 |
|
(defcustom kogiku-take-over-targets '(read-file-name-internal |
| 88 |
|
ffap-read-file-or-url-internal) |
| 89 |
|
"*小菊がのっとる`minibuffer-completion-table'の種類。 |
| 90 |
|
minibufferに制御が移ったときに`minibuffer-completion-table'の値が |
| 91 |
|
`kogiku-take-over-targets'の要素であれば、小菊による補完の準備を行なう。" |
| 92 |
|
:group 'kogiku |
| 93 |
|
:type '(repeat symbol)) |
| 94 |
|
|
| 95 |
|
(defcustom kogiku-minibuffer-prompt-string "kogiku" |
| 96 |
|
"*Kogiku indicator in minibuffer." |
| 97 |
|
:group 'kogiku |
| 98 |
|
:type 'string) |
| 99 |
|
|
| 100 |
|
(defcustom kogiku-minibuffer-indicator-strings '("ON" "off" "ONESHOT") |
| 101 |
|
"*Indicators in minibuffer prpmpt." |
| 102 |
|
:group 'kogiku |
| 103 |
|
:type '(list (string :tag "Toggle-mode ON") |
| 104 |
|
(string :tag "Toggle-mode off") |
| 105 |
|
(string :tag "Oneshot-mode"))) |
| 106 |
|
|
| 107 |
(defface kogiku-indicator-face |
(defface kogiku-indicator-face |
| 108 |
'((((class color) (type tty)) (:foreground "blue" :bold t)) |
'((((class color) (type tty)) (:foreground "blue" :bold t)) |
| 109 |
(((class color) (background light)) (:foreground "dark blue" :bold t)) |
(((class color) (background light)) (:foreground "dark blue" :bold t)) |
| 112 |
"*Face of kogiku indicator." |
"*Face of kogiku indicator." |
| 113 |
:group 'kogiku) |
:group 'kogiku) |
| 114 |
|
|
|
(defface kogiku-change-face |
|
|
'((((class color) (type tty)) (:foreground "blue")) |
|
|
(((class color) (background light)) (:foreground "dark blue")) |
|
|
(((class color) (background dark)) (:foreground "cyan")) |
|
|
(t (:underline t))) |
|
|
"*Face of kogiku indicator." |
|
|
:group 'kogiku) |
|
|
|
|
|
(defcustom kogiku-take-over-targets '(read-file-name-internal |
|
|
ffap-read-file-or-url-internal) |
|
|
"小菊がのっとる`minibuffer-completion-table'の種類。 |
|
|
minibufferに制御が移ったときに`minibuffer-completion-table'の値が |
|
|
`kogiku-take-over-targets'の要素であれば、小菊による補完の準備を行なう。" |
|
|
:group 'kogiku |
|
|
:type '(repeat symbol)) |
|
|
|
|
| 115 |
(defvar kogiku-original-functions nil) |
(defvar kogiku-original-functions nil) |
| 116 |
(defvar kogiku-original-completion-table nil) |
(defvar kogiku-original-completion-tables nil) |
| 117 |
|
|
| 118 |
(defvar kogiku-completion-key "\t") |
(defvar kogiku-completion-key "\t") |
| 119 |
(defvar kogiku-minibuffer-prompt-overlay nil) |
(defvar kogiku-minibuffer-prompt-overlay nil) |
| 120 |
(defvar kogiku-mode-change-original-functions nil) |
(defvar kogiku-mode-change-original-functions nil) |
| 121 |
|
|
| 122 |
|
(defvar kogiku-emacs21-p (fboundp 'field-beginning)) |
| 123 |
|
|
| 124 |
(defun kogiku-complete (&optional arg) |
(defun kogiku-complete (&optional arg) |
| 125 |
(interactive "P") |
(interactive "P") |
| 126 |
(if kogiku-enable-once |
(if kogiku-enable-once |
| 131 |
(let ((minibuffer-completion-table minibuffer-completion-table)) |
(let ((minibuffer-completion-table minibuffer-completion-table)) |
| 132 |
(when fire |
(when fire |
| 133 |
(setq minibuffer-completion-table 'kogiku-read-file-name-internal)) |
(setq minibuffer-completion-table 'kogiku-read-file-name-internal)) |
| 134 |
(funcall (car kogiku-original-functions)))) |
(prog1 |
| 135 |
|
(funcall (car kogiku-original-functions)) |
| 136 |
|
(kogiku-minibuffer-prompt)))) |
| 137 |
|
|
| 138 |
(defun kogiku-complete-with-toggle (switch) |
(defun kogiku-complete-with-toggle (switch) |
| 139 |
(cond |
(cond |
| 140 |
((and switch |
((and switch |
| 141 |
(eq minibuffer-completion-table 'kogiku-read-file-name-internal)) |
(eq minibuffer-completion-table 'kogiku-read-file-name-internal)) |
| 142 |
(setq minibuffer-completion-table kogiku-original-completion-table)) |
(setq minibuffer-completion-table (car kogiku-original-completion-tables)) |
| 143 |
|
(kogiku-minibuffer-prompt)) |
| 144 |
(switch |
(switch |
| 145 |
(setq minibuffer-completion-table 'kogiku-read-file-name-internal))) |
(setq minibuffer-completion-table 'kogiku-read-file-name-internal) |
| 146 |
|
(kogiku-minibuffer-prompt))) |
| 147 |
(prog1 |
(prog1 |
| 148 |
(funcall (car kogiku-original-functions)) |
(funcall (car kogiku-original-functions)) |
| 149 |
(kogiku-minibuffer-prompt))) |
(kogiku-minibuffer-prompt))) |
| 150 |
|
|
| 151 |
|
(defvar kogiku-minibuffer-prompt-map nil |
| 152 |
|
"kogiku prompt map for mode change.") |
| 153 |
|
|
| 154 |
|
(let ((map (make-sparse-keymap))) |
| 155 |
|
(define-key map [mouse-2] 'kogiku-mode-change-at-mouse) |
| 156 |
|
(setq kogiku-minibuffer-prompt-map map)) |
| 157 |
|
|
| 158 |
(defun kogiku-minibuffer-prompt () |
(defun kogiku-minibuffer-prompt () |
| 159 |
(if (fboundp 'field-beginning) |
(let* ((mode (cond |
| 160 |
;; Emacs 21 |
(kogiku-enable-once |
| 161 |
(let ((indicator (format "[%s]" kogiku-minibuffer-prompt-string)) |
(nth 2 kogiku-minibuffer-indicator-strings)) |
| 162 |
(props (text-properties-at (point-min))) |
((eq minibuffer-completion-table 'kogiku-read-file-name-internal) |
| 163 |
(buffer-read-only nil) |
(nth 0 kogiku-minibuffer-indicator-strings)) |
| 164 |
(inhibit-read-only t)) |
(t |
| 165 |
(save-excursion |
(nth 1 kogiku-minibuffer-indicator-strings)))) |
| 166 |
(goto-char (point-min)) |
(indicator |
| 167 |
(cond |
(if kogiku-emacs21-p |
| 168 |
((and (not (eq minibuffer-completion-table 'kogiku-read-file-name-internal)) |
(format "[%s:%s] " kogiku-minibuffer-prompt-string mode) |
| 169 |
(looking-at (concat "^" (regexp-quote indicator) " "))) |
(format "%s(%s): " kogiku-minibuffer-prompt-string mode))) |
| 170 |
(delete-region (point-min) (match-end 0))) |
(max (if kogiku-emacs21-p (1+ (point-min)) (point-max)))) |
| 171 |
((and (eq minibuffer-completion-table 'kogiku-read-file-name-internal) |
(when kogiku-emacs21-p |
| 172 |
(not (looking-at (concat "^" (regexp-quote indicator) " ")))) |
(add-text-properties 0 (1- (length indicator)) |
| 173 |
(setq indicator (concat indicator " ")) |
'(face kogiku-indicator-face) |
| 174 |
(insert indicator) |
indicator) |
| 175 |
(set-text-properties (point-min) (field-beginning) props) |
(add-text-properties 0 (length indicator) |
| 176 |
(add-text-properties (point-min) (+ -1 (point-min) (length indicator)) |
`(local-map ,kogiku-minibuffer-prompt-map) |
| 177 |
'(face kogiku-indicator-face)))))) |
indicator)) |
| 178 |
;; Others |
(if kogiku-minibuffer-prompt-overlay |
| 179 |
(if (eq minibuffer-completion-table 'kogiku-read-file-name-internal) |
(move-overlay kogiku-minibuffer-prompt-overlay |
| 180 |
(let ((max (min (point-max) (1+ (point-min))))) |
(point-min) max) |
| 181 |
(if kogiku-minibuffer-prompt-overlay |
(setq kogiku-minibuffer-prompt-overlay |
| 182 |
(move-overlay kogiku-minibuffer-prompt-overlay |
(make-overlay (point-min) max))) |
| 183 |
(point-min) max) |
(overlay-put kogiku-minibuffer-prompt-overlay |
| 184 |
(setq kogiku-minibuffer-prompt-overlay |
'before-string indicator) |
| 185 |
(make-overlay (point-min) max))) |
(overlay-put kogiku-minibuffer-prompt-overlay 'evaporate t) |
| 186 |
(overlay-put kogiku-minibuffer-prompt-overlay |
indicator)) |
|
'before-string |
|
|
(format "%s: " kogiku-minibuffer-prompt-string)) |
|
|
(overlay-put kogiku-minibuffer-prompt-overlay 'evaporate t)) |
|
|
(when kogiku-minibuffer-prompt-overlay |
|
|
(delete-overlay kogiku-minibuffer-prompt-overlay))))) |
|
| 187 |
|
|
| 188 |
(if (fboundp 'compare-strings) |
(if (fboundp 'compare-strings) |
| 189 |
(defalias 'kogiku-compare-strings 'compare-strings) |
(defalias 'kogiku-compare-strings 'compare-strings) |
| 334 |
(funcall read-file-name-predicate string) |
(funcall read-file-name-predicate string) |
| 335 |
(file-exists-p string)))))))) |
(file-exists-p string)))))))) |
| 336 |
|
|
| 337 |
|
(defun kogiku-mode-change-at-mouse (event) |
| 338 |
|
(interactive "e") |
| 339 |
|
(save-window-excursion |
| 340 |
|
(save-excursion |
| 341 |
|
(set-buffer (window-buffer (posn-window (event-end event)))) |
| 342 |
|
(kogiku-mode-change)))) |
| 343 |
|
|
| 344 |
(defun kogiku-mode-change () |
(defun kogiku-mode-change () |
| 345 |
(interactive) |
(interactive) |
| 346 |
(setq kogiku-enable-once (not kogiku-enable-once)) |
;; Cyclic: on-off, off->oneshot, oneshot->on |
| 347 |
(when (and kogiku-enable-once |
(let ((nextmode (cond |
| 348 |
(eq minibuffer-completion-table 'kogiku-read-file-name-internal)) |
(kogiku-enable-once 'on) |
| 349 |
(setq minibuffer-completion-table 'read-file-name-internal)) |
((eq minibuffer-completion-table |
| 350 |
(when (and (not kogiku-enable-once) |
'kogiku-read-file-name-internal) 'off) |
| 351 |
(eq minibuffer-completion-table 'read-file-name-internal)) |
(t 'oneshot)))) |
| 352 |
(setq minibuffer-completion-table 'kogiku-read-file-name-internal)) |
(cond |
| 353 |
(kogiku-minibuffer-prompt) |
((eq nextmode 'on) |
| 354 |
(let ((msg (format "[%s%s-mode]" |
(setq kogiku-enable-once nil) |
| 355 |
(if kogiku-enable-once |
(setq minibuffer-completion-table 'kogiku-read-file-name-internal)) |
| 356 |
(concat kogiku-minibuffer-prompt-string " ") "") |
((eq nextmode 'off) |
| 357 |
(if kogiku-enable-once "ONESHOT" "TOGGLE"))) |
(setq kogiku-enable-once nil) |
| 358 |
(max (point-max)) |
(setq minibuffer-completion-table (car kogiku-original-completion-tables))) |
| 359 |
(inhibit-quit t)) |
(t ;; oneshot |
| 360 |
(put-text-property 0 (length msg) 'face 'kogiku-change-face msg) |
(setq kogiku-enable-once t) |
| 361 |
(save-excursion |
(setq minibuffer-completion-table (car kogiku-original-completion-tables)))) |
| 362 |
(goto-char max) |
(kogiku-minibuffer-prompt))) |
|
(insert " " msg)) |
|
|
(sit-for 5) |
|
|
(save-excursion |
|
|
(delete-region max (point-max))))) |
|
| 363 |
|
|
| 364 |
(defun kogiku-install-key () |
(defun kogiku-install-key () |
| 365 |
(when (memq minibuffer-completion-table kogiku-take-over-targets) |
(when (memq minibuffer-completion-table kogiku-take-over-targets) |
| 366 |
(setq kogiku-original-completion-table minibuffer-completion-table) |
(push minibuffer-completion-table kogiku-original-completion-tables) |
| 367 |
(push (lookup-key (current-local-map) kogiku-completion-key) |
(push (lookup-key (current-local-map) kogiku-completion-key) |
| 368 |
kogiku-original-functions) |
kogiku-original-functions) |
| 369 |
(define-key (current-local-map) kogiku-completion-key 'kogiku-complete) |
(define-key (current-local-map) kogiku-completion-key 'kogiku-complete) |
| 370 |
(push (lookup-key (current-local-map) kogiku-mode-change-key) |
(push (lookup-key (current-local-map) kogiku-mode-change-key) |
| 371 |
kogiku-mode-change-original-functions) |
kogiku-mode-change-original-functions) |
| 372 |
(define-key (current-local-map) kogiku-mode-change-key 'kogiku-mode-change))) |
(define-key (current-local-map) kogiku-mode-change-key 'kogiku-mode-change) |
| 373 |
|
(kogiku-minibuffer-prompt))) |
| 374 |
|
|
| 375 |
(add-hook 'minibuffer-setup-hook 'kogiku-install-key) |
(add-hook 'minibuffer-setup-hook 'kogiku-install-key) |
| 376 |
|
|
| 379 |
(memq minibuffer-completion-table kogiku-take-over-targets)) |
(memq minibuffer-completion-table kogiku-take-over-targets)) |
| 380 |
(eq (lookup-key (current-local-map) kogiku-completion-key) |
(eq (lookup-key (current-local-map) kogiku-completion-key) |
| 381 |
'kogiku-complete)) |
'kogiku-complete)) |
| 382 |
|
(pop kogiku-original-completion-tables) |
| 383 |
(define-key (current-local-map) kogiku-completion-key (pop kogiku-original-functions)) |
(define-key (current-local-map) kogiku-completion-key (pop kogiku-original-functions)) |
| 384 |
(when (eq (lookup-key (current-local-map) kogiku-mode-change-key) |
(when (eq (lookup-key (current-local-map) kogiku-mode-change-key) |
| 385 |
'kogiku-mode-change) |
'kogiku-mode-change) |