diff options
| author | F. Jason Park | 2022-11-04 05:01:35 -0700 |
|---|---|---|
| committer | F. Jason Park | 2022-11-04 19:32:23 -0700 |
| commit | ae0642f8595e5bc5b521bbfa73ae114bf25a418d (patch) | |
| tree | 8a6b0427774853d0af7e4aa7ab3bda2f224cba18 | |
| parent | 0606b095d2411f43a7e842707bcec006e9952a60 (diff) | |
| download | emacs-ae0642f8595e5bc5b521bbfa73ae114bf25a418d.tar.gz emacs-ae0642f8595e5bc5b521bbfa73ae114bf25a418d.zip | |
Offer completions for GET subcommand flags in erc-dcc
* lisp/erc/erc-dcc.el (pcomplete/erc-mode/DCC): Add /DCC GET switches.
This is unfinished business from bug#54458.
* test/lisp/erc/erc-dcc-tests.el (erc-dcc-tests--pcomplete-common,
pcomplete/erc-mode/DCC--get-basic, pcomplete/erc-mode/DCC--get-1flag,
pcomplete/erc-mode/DCC--get-2flags,
pcomplete/erc-mode/DCC--get-2flags-reverse): Add helper and tests for
completing /DCC GET switches.
| -rw-r--r-- | lisp/erc/erc-dcc.el | 7 | ||||
| -rw-r--r-- | test/lisp/erc/erc-dcc-tests.el | 119 |
2 files changed, 123 insertions, 3 deletions
diff --git a/lisp/erc/erc-dcc.el b/lisp/erc/erc-dcc.el index 90a10766c4c..ebeab921fb9 100644 --- a/lisp/erc/erc-dcc.el +++ b/lisp/erc/erc-dcc.el | |||
| @@ -411,8 +411,11 @@ where FOO is one of CLOSE, GET, SEND, LIST, CHAT, etc." | |||
| 411 | "Provide completion for the /DCC command." | 411 | "Provide completion for the /DCC command." |
| 412 | (pcomplete-here (append '("chat" "close" "get" "list") | 412 | (pcomplete-here (append '("chat" "close" "get" "list") |
| 413 | (when (fboundp 'make-network-process) '("send")))) | 413 | (when (fboundp 'make-network-process) '("send")))) |
| 414 | (when (equal "get" (downcase (pcomplete-arg 1))) | ||
| 415 | (pcomplete-opt "ts") | ||
| 416 | (pcomplete-opt (if (equal "-s" (pcomplete-arg 'first 2)) "t" "s"))) | ||
| 414 | (pcomplete-here | 417 | (pcomplete-here |
| 415 | (pcase (intern (downcase (pcomplete-arg 1))) | 418 | (pcase (intern (downcase (pcomplete-arg 'first 1))) |
| 416 | ('chat (mapcar (lambda (elt) (plist-get elt :nick)) | 419 | ('chat (mapcar (lambda (elt) (plist-get elt :nick)) |
| 417 | (cl-remove-if-not | 420 | (cl-remove-if-not |
| 418 | (lambda (elt) | 421 | (lambda (elt) |
| @@ -428,7 +431,7 @@ where FOO is one of CLOSE, GET, SEND, LIST, CHAT, etc." | |||
| 428 | erc-dcc-list))) | 431 | erc-dcc-list))) |
| 429 | ('send (pcomplete-erc-all-nicks)))) | 432 | ('send (pcomplete-erc-all-nicks)))) |
| 430 | (pcomplete-here | 433 | (pcomplete-here |
| 431 | (pcase (intern (downcase (pcomplete-arg 2))) | 434 | (pcase (intern (downcase (pcomplete-arg 'first 1))) |
| 432 | ('get (mapcar (lambda (elt) (plist-get elt :file)) | 435 | ('get (mapcar (lambda (elt) (plist-get elt :file)) |
| 433 | (cl-remove-if-not | 436 | (cl-remove-if-not |
| 434 | (lambda (elt) | 437 | (lambda (elt) |
diff --git a/test/lisp/erc/erc-dcc-tests.el b/test/lisp/erc/erc-dcc-tests.el index a1dfbab9dc5..8645d7f1044 100644 --- a/test/lisp/erc/erc-dcc-tests.el +++ b/test/lisp/erc/erc-dcc-tests.el | |||
| @@ -20,8 +20,9 @@ | |||
| 20 | ;;; Commentary: | 20 | ;;; Commentary: |
| 21 | 21 | ||
| 22 | ;;; Code: | 22 | ;;; Code: |
| 23 | (require 'ert) | 23 | (require 'ert-x) |
| 24 | (require 'erc-dcc) | 24 | (require 'erc-dcc) |
| 25 | (require 'erc-pcomplete) | ||
| 25 | 26 | ||
| 26 | (ert-deftest erc-dcc-ctcp-query-send-regexp () | 27 | (ert-deftest erc-dcc-ctcp-query-send-regexp () |
| 27 | (let ((s "DCC SEND \"file name\" 2130706433 9899 1405135128")) | 28 | (let ((s "DCC SEND \"file name\" 2130706433 9899 1405135128")) |
| @@ -164,4 +165,120 @@ | |||
| 164 | (should (eq t (plist-get (car erc-dcc-list) :turbo))) | 165 | (should (eq t (plist-get (car erc-dcc-list) :turbo))) |
| 165 | (should (equal (pop calls) (list elt "foo.bin" proc)))))))) | 166 | (should (equal (pop calls) (list elt "foo.bin" proc)))))))) |
| 166 | 167 | ||
| 168 | (defun erc-dcc-tests--pcomplete-common (test-fn) | ||
| 169 | (with-current-buffer (get-buffer-create "*erc-dcc-do-GET-command*") | ||
| 170 | (let* ((proc (start-process "fake" (current-buffer) "sleep" "10")) | ||
| 171 | (elt (list :nick "tester!~tester@fake.irc" | ||
| 172 | :type 'GET | ||
| 173 | :peer nil | ||
| 174 | :parent proc | ||
| 175 | :ip "127.0.0.1" | ||
| 176 | :port "9899" | ||
| 177 | :file "foo.bin" | ||
| 178 | :size 1405135128)) | ||
| 179 | ;; | ||
| 180 | erc-accidental-paste-threshold-seconds | ||
| 181 | erc-insert-modify-hook erc-send-completed-hook | ||
| 182 | erc-kill-channel-hook erc-kill-server-hook erc-kill-buffer-hook) | ||
| 183 | (erc-mode) | ||
| 184 | (pcomplete-erc-setup) | ||
| 185 | (add-hook 'erc-complete-functions #'erc-pcompletions-at-point 0 t) | ||
| 186 | (setq erc-server-process proc | ||
| 187 | erc-input-marker (make-marker) | ||
| 188 | erc-insert-marker (make-marker) | ||
| 189 | erc-server-current-nick "dummy") | ||
| 190 | (setq-local erc-dcc-list (list elt)) ; for interactive noodling | ||
| 191 | (set-process-query-on-exit-flag proc nil) | ||
| 192 | (goto-char (point-max)) | ||
| 193 | (set-marker erc-insert-marker (point-max)) | ||
| 194 | (erc-display-prompt) | ||
| 195 | (goto-char erc-input-marker) | ||
| 196 | (funcall test-fn)) | ||
| 197 | (when noninteractive | ||
| 198 | (kill-buffer)))) | ||
| 199 | |||
| 200 | (ert-deftest pcomplete/erc-mode/DCC--get-basic () | ||
| 201 | (erc-dcc-tests--pcomplete-common | ||
| 202 | (lambda () | ||
| 203 | (insert "/dcc get ") | ||
| 204 | (call-interactively #'completion-at-point) | ||
| 205 | (save-excursion | ||
| 206 | (beginning-of-line) | ||
| 207 | (should (search-forward "/dcc get tester" nil t))) | ||
| 208 | (call-interactively #'completion-at-point) | ||
| 209 | (save-excursion | ||
| 210 | (beginning-of-line) | ||
| 211 | (should (search-forward "/dcc get tester foo.bin" nil t)))))) | ||
| 212 | |||
| 213 | (ert-deftest pcomplete/erc-mode/DCC--get-1flag () | ||
| 214 | (erc-dcc-tests--pcomplete-common | ||
| 215 | (lambda () | ||
| 216 | (goto-char erc-input-marker) | ||
| 217 | (delete-region (point) (point-max)) | ||
| 218 | (insert "/dcc get -") | ||
| 219 | (call-interactively #'completion-at-point) | ||
| 220 | (with-current-buffer (get-buffer "*Completions*") | ||
| 221 | (goto-char (point-min)) | ||
| 222 | (search-forward "-s") | ||
| 223 | (search-forward "-t")) | ||
| 224 | (insert "s ") | ||
| 225 | (call-interactively #'completion-at-point) | ||
| 226 | (save-excursion | ||
| 227 | (beginning-of-line) | ||
| 228 | (should (search-forward "/dcc get -s tester" nil t))) | ||
| 229 | (call-interactively #'completion-at-point) | ||
| 230 | (save-excursion | ||
| 231 | (beginning-of-line) | ||
| 232 | (should (search-forward "/dcc get -s tester foo.bin" nil t)))))) | ||
| 233 | |||
| 234 | (ert-deftest pcomplete/erc-mode/DCC--get-2flags () | ||
| 235 | (erc-dcc-tests--pcomplete-common | ||
| 236 | (lambda () | ||
| 237 | (goto-char erc-input-marker) | ||
| 238 | (delete-region (point) (point-max)) | ||
| 239 | (insert "/dcc get -") | ||
| 240 | (call-interactively #'completion-at-point) | ||
| 241 | (with-current-buffer (get-buffer "*Completions*") | ||
| 242 | (goto-char (point-min)) | ||
| 243 | (search-forward "-s") | ||
| 244 | (search-forward "-t")) | ||
| 245 | (insert "s -") | ||
| 246 | (call-interactively #'completion-at-point) | ||
| 247 | (save-excursion | ||
| 248 | (beginning-of-line) | ||
| 249 | (should (search-forward "/dcc get -s -t " nil t))) | ||
| 250 | (call-interactively #'completion-at-point) | ||
| 251 | (save-excursion | ||
| 252 | (beginning-of-line) | ||
| 253 | (should (search-forward "/dcc get -s -t tester" nil t))) | ||
| 254 | (call-interactively #'completion-at-point) | ||
| 255 | (save-excursion | ||
| 256 | (beginning-of-line) | ||
| 257 | (should (search-forward "/dcc get -s -t tester foo.bin" nil t)))))) | ||
| 258 | |||
| 259 | (ert-deftest pcomplete/erc-mode/DCC--get-2flags-reverse () | ||
| 260 | (erc-dcc-tests--pcomplete-common | ||
| 261 | (lambda () | ||
| 262 | (goto-char erc-input-marker) | ||
| 263 | (delete-region (point) (point-max)) | ||
| 264 | (insert "/dcc get -") | ||
| 265 | (call-interactively #'completion-at-point) | ||
| 266 | (with-current-buffer (get-buffer "*Completions*") | ||
| 267 | (goto-char (point-min)) | ||
| 268 | (search-forward "-s") | ||
| 269 | (search-forward "-t")) | ||
| 270 | (insert "t -") | ||
| 271 | (call-interactively #'completion-at-point) | ||
| 272 | (save-excursion | ||
| 273 | (beginning-of-line) | ||
| 274 | (should (search-forward "/dcc get -t -s " nil t))) | ||
| 275 | (call-interactively #'completion-at-point) | ||
| 276 | (save-excursion | ||
| 277 | (beginning-of-line) | ||
| 278 | (should (search-forward "/dcc get -t -s tester" nil t))) | ||
| 279 | (call-interactively #'completion-at-point) | ||
| 280 | (save-excursion | ||
| 281 | (beginning-of-line) | ||
| 282 | (should (search-forward "/dcc get -t -s tester foo.bin" nil t)))))) | ||
| 283 | |||
| 167 | ;;; erc-dcc-tests.el ends here | 284 | ;;; erc-dcc-tests.el ends here |