1 ;;; liece-minibuf.el --- Minibuffer custom completion.
2 ;; Copyright (C) 1998-2000 Daiki Ueno
4 ;; Author: Daiki Ueno <ueno@unixuser.org>
7 ;; Keywords: minibuffer, completion
9 ;; This file is part of Liece.
11 ;; This program is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; This program is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
32 (require 'liece-compat)
36 (defvar liece-minibuffer-map nil)
37 (defvar liece-minibuffer-complete-function nil)
39 (unless liece-minibuffer-map
40 (setq liece-minibuffer-map
41 (let ((map (make-sparse-keymap)))
42 (set-keymap-parent map minibuffer-local-map)
43 (define-key map " " nil)
44 (define-key map "\t" 'liece-minibuffer-complete)
45 (define-key map "\r" 'exit-minibuffer)
46 (define-key map "\n" 'exit-minibuffer)
49 (defun liece-minibuffer-complete ()
51 (if (and liece-minibuffer-complete-function
52 (fboundp liece-minibuffer-complete-function))
53 (funcall liece-minibuffer-complete-function)))
55 (defun liece-minibuffer-parse-modes ()
57 (let (preceding-char (state 'flag) type)
61 (setq preceding-char (char-before))
63 ((and (memq state '(flag arg))
64 (or (char-equal preceding-char ?+)
65 (char-equal preceding-char ?-)))
68 ((and (eq state 'mode) (char-equal preceding-char ? ))
70 ((and (eq state 'mode) (memq preceding-char '(?o ?v)))
71 (setq type (nconc type (list 'nick preceding-char
72 (char-before (1- (point)))))))
73 ((and (eq state 'mode) (eq preceding-char ?b))
74 (setq type (nconc type (list 'ban (char-before (1- (point)))))))))
77 (defun liece-minibuffer-prepare-candidate ()
78 (let ((point (point)))
79 (skip-syntax-backward "^ ")
80 (prog1 (buffer-substring (point) point)
83 (defun liece-minibuffer-delete-candidate ()
84 (let ((point (point)))
85 (skip-syntax-backward "^ ")
86 (delete-region (point) point)))
88 (defun liece-minibuffer-finalize-completion (completion pattern all)
92 (temp-minibuffer-message (_ "[No match]")))
93 ((not (string= pattern completion))
94 (liece-minibuffer-delete-candidate)
97 (with-output-to-temp-buffer "*Completions*"
98 (funcall completion-display-completion-list-function
99 (sort all (function (lambda (x y)
102 (or (car-safe y) y))))))))))
104 (defun liece-minibuffer-complete-channel-modes ()
105 (let* ((preceding-char (char-before)) completion candidate all
108 liece-supported-channel-mode-alist ""))
109 (nicks (liece-channel-get-nicks))
111 (context (liece-minibuffer-parse-modes))
112 (state (car context)) (type (cdr context)))
114 ((memq state '(flag mode))
115 (temp-minibuffer-message
116 (format (_ "[Modes are: %s]") modes)))
117 ((and (eq state 'arg) (memq 'ban type))
119 (setq uahs (list-to-alist (liece-channel-get-bans)))
123 (list (concat nick "!"
124 (liece-nick-get-user-at-host nick)))))
126 (setq candidate (liece-minibuffer-prepare-candidate)
127 completion (try-completion candidate uahs)
128 all (all-completions candidate uahs)))
129 ((and (eq state 'arg) (memq 'nick type))
130 (let* ((masks (cond ((memq ?o type) (liece-channel-get-operators))
131 ((memq ?v type) (liece-channel-get-voices))))
138 (string-list-member-ignore-case item '(, masks)))))
140 (setq nicks (mapcar (function list) nicks)
141 candidate (liece-minibuffer-prepare-candidate)
142 completion (try-completion candidate nicks)
143 all (all-completions candidate nicks)))))
144 (liece-minibuffer-finalize-completion completion candidate all)))
146 (defun liece-minibuffer-complete-user-modes ()
147 (temp-minibuffer-message
149 (_ "[Modes are: %s]")
150 (mapconcat (function car) liece-supported-user-mode-alist ""))))
152 (defun liece-minibuffer-completing-default-read
153 (prompt table &optional predicate require-match initial-input)
154 "Completing-read w/ default argument like in 'kill-buffer'."
158 (format "%s(default %s) " prompt initial-input)
160 table predicate require-match nil)))
161 (if (and (string= default-read "") initial-input)
165 (defun liece-minibuffer-completing-sequential-read
166 (prompt &optional count table predicate require-match multiple-candidate)
167 "Execute completing-read w/ default argument consequently."
168 (let ((count (or count 0)) string result)
172 (format "%s (%d): " prompt (incf count))
173 table predicate require-match nil))
174 (or multiple-candidate
175 (remove-alist 'table string))
176 (not (string= "" string)))
177 (push string result))
180 (provide 'liece-minibuf)
182 ;;; liece-minibuf.el ends here