| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
(require 'erc) |
|---|
| 36 |
(require 'erc-match) |
|---|
| 37 |
(require 'hippie-exp) |
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
(define-erc-module hecomplete nil |
|---|
| 41 |
"Complete nick at point." |
|---|
| 42 |
((add-hook 'erc-complete-functions 'erc-hecomplete)) |
|---|
| 43 |
((remove-hook 'erc-complete-functions 'erc-hecomplete))) |
|---|
| 44 |
|
|---|
| 45 |
(defun erc-hecomplete () |
|---|
| 46 |
"Complete nick at point. |
|---|
| 47 |
See `erc-try-complete-nick' for more technical info. |
|---|
| 48 |
This function is obsolete, use `erc-pcomplete' instead." |
|---|
| 49 |
(interactive) |
|---|
| 50 |
(let ((hippie-expand-try-functions-list '(erc-try-complete-nick))) |
|---|
| 51 |
(hippie-expand nil))) |
|---|
| 52 |
|
|---|
| 53 |
(defgroup erc-hecomplete nil |
|---|
| 54 |
"Nick completion. It is recommended to use erc-pcomplete instead." |
|---|
| 55 |
:group 'erc) |
|---|
| 56 |
|
|---|
| 57 |
(defcustom erc-nick-completion 'all |
|---|
| 58 |
"Determine how the list of nicks is determined during nick completion. |
|---|
| 59 |
See `erc-complete-nick' for information on how to activate this. |
|---|
| 60 |
|
|---|
| 61 |
pals: Use `erc-pals'. |
|---|
| 62 |
all: All channel members. |
|---|
| 63 |
|
|---|
| 64 |
You may also provide your own function that returns a list of completions. |
|---|
| 65 |
One example is `erc-nick-completion-exclude-myself', |
|---|
| 66 |
or you may use an arbitrary lisp expression." |
|---|
| 67 |
:type '(choice (const :tag "List of pals" pals) |
|---|
| 68 |
(const :tag "All channel members" all) |
|---|
| 69 |
(const :tag "All channel members except yourself" |
|---|
| 70 |
erc-nick-completion-exclude-myself) |
|---|
| 71 |
(repeat :tag "List" (string :tag "Nick")) |
|---|
| 72 |
function |
|---|
| 73 |
sexp) |
|---|
| 74 |
:group 'erc-hecomplete) |
|---|
| 75 |
|
|---|
| 76 |
(defcustom erc-nick-completion-ignore-case t |
|---|
| 77 |
"*Non-nil means don't consider case significant in nick completion. |
|---|
| 78 |
Case will be automatically corrected when non-nil. |
|---|
| 79 |
For instance if you type \"dely TAB\" the word completes and changes to |
|---|
| 80 |
\"delYsid\"." |
|---|
| 81 |
:group 'erc-hecomplete |
|---|
| 82 |
:type 'boolean) |
|---|
| 83 |
|
|---|
| 84 |
(defun erc-nick-completion-exclude-myself () |
|---|
| 85 |
"Get a list of all the channel members except you. |
|---|
| 86 |
|
|---|
| 87 |
This function returns a list of all the members in the channel, except |
|---|
| 88 |
your own nick. This way if you're named foo and someone is called foobar, |
|---|
| 89 |
typing \"f o TAB\" will directly give you foobar. Use this with |
|---|
| 90 |
`erc-nick-completion'." |
|---|
| 91 |
(remove |
|---|
| 92 |
(erc-current-nick) |
|---|
| 93 |
(erc-get-channel-nickname-list))) |
|---|
| 94 |
|
|---|
| 95 |
(defcustom erc-nick-completion-postfix ": " |
|---|
| 96 |
"*When `erc-complete' is used in the first word after the prompt, |
|---|
| 97 |
add this string when a unique expansion was found." |
|---|
| 98 |
:group 'erc-hecomplete |
|---|
| 99 |
:type 'string) |
|---|
| 100 |
|
|---|
| 101 |
(defun erc-command-list () |
|---|
| 102 |
"Returns a list of strings of the defined user commands." |
|---|
| 103 |
(let ((case-fold-search nil)) |
|---|
| 104 |
(mapcar (lambda (x) |
|---|
| 105 |
(concat "/" (downcase (substring (symbol-name x) 8)))) |
|---|
| 106 |
(apropos-internal "erc-cmd-[A-Z]+")))) |
|---|
| 107 |
|
|---|
| 108 |
(defun erc-try-complete-nick (old) |
|---|
| 109 |
"Complete nick at point. |
|---|
| 110 |
This is a function to put on `hippie-expand-try-functions-list'. |
|---|
| 111 |
Then use \\[hippie-expand] to expand nicks. |
|---|
| 112 |
The type of completion depends on `erc-nick-completion'." |
|---|
| 113 |
(cond ((eq erc-nick-completion 'pals) |
|---|
| 114 |
(try-complete-erc-nick old erc-pals)) |
|---|
| 115 |
((eq erc-nick-completion 'all) |
|---|
| 116 |
(try-complete-erc-nick old (append |
|---|
| 117 |
(erc-get-channel-nickname-list) |
|---|
| 118 |
(erc-command-list)))) |
|---|
| 119 |
((functionp erc-nick-completion) |
|---|
| 120 |
(try-complete-erc-nick old (funcall erc-nick-completion))) |
|---|
| 121 |
(t |
|---|
| 122 |
(try-complete-erc-nick old erc-nick-completion)))) |
|---|
| 123 |
|
|---|
| 124 |
(defvar try-complete-erc-nick-window-configuration nil |
|---|
| 125 |
"The window configuration for `try-complete-erc-nick'. |
|---|
| 126 |
When called the first time, a window config is stored here, |
|---|
| 127 |
and when completion is done, the window config is restored |
|---|
| 128 |
from here. See `try-complete-erc-nick-restore' and |
|---|
| 129 |
`try-complete-erc-nick'.") |
|---|
| 130 |
|
|---|
| 131 |
(defun try-complete-erc-nick-restore () |
|---|
| 132 |
"Restore window configuration." |
|---|
| 133 |
(if (not try-complete-erc-nick-window-configuration) |
|---|
| 134 |
(when (get-buffer "*Completions*") |
|---|
| 135 |
(delete-windows-on "*Completions*")) |
|---|
| 136 |
(set-window-configuration |
|---|
| 137 |
try-complete-erc-nick-window-configuration) |
|---|
| 138 |
(setq try-complete-erc-nick-window-configuration nil))) |
|---|
| 139 |
|
|---|
| 140 |
(defun try-complete-erc-nick (old completions) |
|---|
| 141 |
"Try to complete current word depending on `erc-try-complete-nick'. |
|---|
| 142 |
The argument OLD has to be nil the first call of this function, and t |
|---|
| 143 |
for subsequent calls (for further possible completions of the same |
|---|
| 144 |
string). It returns t if a new completion is found, nil otherwise. The |
|---|
| 145 |
second argument COMPLETIONS is a list of completions to use. Actually, |
|---|
| 146 |
it is only used when OLD is nil. It will be copied to `he-expand-list' |
|---|
| 147 |
on the first call. After that, it is no longer used. |
|---|
| 148 |
Window configurations are stored in |
|---|
| 149 |
`try-complete-erc-nick-window-configuration'." |
|---|
| 150 |
(let (expansion |
|---|
| 151 |
final |
|---|
| 152 |
(alist (if (consp (car completions)) |
|---|
| 153 |
completions |
|---|
| 154 |
(mapcar (lambda (s) |
|---|
| 155 |
(if (and (erc-complete-at-prompt) |
|---|
| 156 |
(and (not (= (length s) 0)) |
|---|
| 157 |
(not (eq (elt s 0) ?/)))) |
|---|
| 158 |
(list (concat s erc-nick-completion-postfix)) |
|---|
| 159 |
(list (concat s " ")))) |
|---|
| 160 |
completions))) |
|---|
| 161 |
(completion-ignore-case erc-nick-completion-ignore-case)) |
|---|
| 162 |
(he-init-string (he-dabbrev-beg) (point)) |
|---|
| 163 |
|
|---|
| 164 |
|
|---|
| 165 |
|
|---|
| 166 |
|
|---|
| 167 |
(unless (string= he-search-string "") |
|---|
| 168 |
(setq expansion (try-completion he-search-string alist) |
|---|
| 169 |
final (or (eq t expansion) |
|---|
| 170 |
(and expansion |
|---|
| 171 |
(eq t (try-completion expansion alist)))))) |
|---|
| 172 |
(cond ((not expansion) |
|---|
| 173 |
|
|---|
| 174 |
(try-complete-erc-nick-restore) |
|---|
| 175 |
(he-reset-string) |
|---|
| 176 |
nil) |
|---|
| 177 |
((eq t expansion) |
|---|
| 178 |
|
|---|
| 179 |
(try-complete-erc-nick-restore) |
|---|
| 180 |
(he-reset-string) |
|---|
| 181 |
t) |
|---|
| 182 |
((and old (string= expansion he-search-string)) |
|---|
| 183 |
|
|---|
| 184 |
|
|---|
| 185 |
|
|---|
| 186 |
|
|---|
| 187 |
(try-complete-erc-nick-restore) |
|---|
| 188 |
(he-reset-string) |
|---|
| 189 |
nil) |
|---|
| 190 |
(final |
|---|
| 191 |
|
|---|
| 192 |
(try-complete-erc-nick-restore) |
|---|
| 193 |
(he-substitute-string expansion) |
|---|
| 194 |
t) |
|---|
| 195 |
(t |
|---|
| 196 |
|
|---|
| 197 |
|
|---|
| 198 |
|
|---|
| 199 |
(setq try-complete-erc-nick-window-configuration |
|---|
| 200 |
(current-window-configuration)) |
|---|
| 201 |
(with-output-to-temp-buffer "*Completions*" |
|---|
| 202 |
(display-completion-list (all-completions he-search-string alist))) |
|---|
| 203 |
(he-substitute-string expansion) |
|---|
| 204 |
t)))) |
|---|
| 205 |
|
|---|
| 206 |
(defun erc-at-beginning-of-line-p (point &optional bol-func) |
|---|
| 207 |
(save-excursion |
|---|
| 208 |
(funcall (or bol-func |
|---|
| 209 |
'erc-bol)) |
|---|
| 210 |
(equal point (point)))) |
|---|
| 211 |
|
|---|
| 212 |
(defun erc-complete-at-prompt () |
|---|
| 213 |
"Returns t if point is directly after `erc-prompt' when doing completion." |
|---|
| 214 |
(erc-at-beginning-of-line-p (he-dabbrev-beg))) |
|---|
| 215 |
|
|---|
| 216 |
(provide 'erc-hecomplete) |
|---|
| 217 |
|
|---|
| 218 |
|
|---|
| 219 |
|
|---|
| 220 |
|
|---|
| 221 |
|
|---|
| 222 |
|
|---|
| 223 |
|
|---|
| 224 |
|
|---|
| 225 |
|
|---|
| 226 |
|
|---|