[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master ae0642f859 3/5: Offer completions for GET subcommand flags in erc
From: |
F. Jason Park |
Subject: |
master ae0642f859 3/5: Offer completions for GET subcommand flags in erc-dcc |
Date: |
Fri, 4 Nov 2022 22:52:31 -0400 (EDT) |
branch: master
commit ae0642f8595e5bc5b521bbfa73ae114bf25a418d
Author: F. Jason Park <jp@neverwas.me>
Commit: F. Jason Park <jp@neverwas.me>
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.
---
lisp/erc/erc-dcc.el | 7 ++-
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 90a10766c4..ebeab921fb 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."
"Provide completion for the /DCC command."
(pcomplete-here (append '("chat" "close" "get" "list")
(when (fboundp 'make-network-process) '("send"))))
+ (when (equal "get" (downcase (pcomplete-arg 1)))
+ (pcomplete-opt "ts")
+ (pcomplete-opt (if (equal "-s" (pcomplete-arg 'first 2)) "t" "s")))
(pcomplete-here
- (pcase (intern (downcase (pcomplete-arg 1)))
+ (pcase (intern (downcase (pcomplete-arg 'first 1)))
('chat (mapcar (lambda (elt) (plist-get elt :nick))
(cl-remove-if-not
(lambda (elt)
@@ -428,7 +431,7 @@ where FOO is one of CLOSE, GET, SEND, LIST, CHAT, etc."
erc-dcc-list)))
('send (pcomplete-erc-all-nicks))))
(pcomplete-here
- (pcase (intern (downcase (pcomplete-arg 2)))
+ (pcase (intern (downcase (pcomplete-arg 'first 1)))
('get (mapcar (lambda (elt) (plist-get elt :file))
(cl-remove-if-not
(lambda (elt)
diff --git a/test/lisp/erc/erc-dcc-tests.el b/test/lisp/erc/erc-dcc-tests.el
index a1dfbab9dc..8645d7f104 100644
--- a/test/lisp/erc/erc-dcc-tests.el
+++ b/test/lisp/erc/erc-dcc-tests.el
@@ -20,8 +20,9 @@
;;; Commentary:
;;; Code:
-(require 'ert)
+(require 'ert-x)
(require 'erc-dcc)
+(require 'erc-pcomplete)
(ert-deftest erc-dcc-ctcp-query-send-regexp ()
(let ((s "DCC SEND \"file name\" 2130706433 9899 1405135128"))
@@ -164,4 +165,120 @@
(should (eq t (plist-get (car erc-dcc-list) :turbo)))
(should (equal (pop calls) (list elt "foo.bin" proc))))))))
+(defun erc-dcc-tests--pcomplete-common (test-fn)
+ (with-current-buffer (get-buffer-create "*erc-dcc-do-GET-command*")
+ (let* ((proc (start-process "fake" (current-buffer) "sleep" "10"))
+ (elt (list :nick "tester!~tester@fake.irc"
+ :type 'GET
+ :peer nil
+ :parent proc
+ :ip "127.0.0.1"
+ :port "9899"
+ :file "foo.bin"
+ :size 1405135128))
+ ;;
+ erc-accidental-paste-threshold-seconds
+ erc-insert-modify-hook erc-send-completed-hook
+ erc-kill-channel-hook erc-kill-server-hook erc-kill-buffer-hook)
+ (erc-mode)
+ (pcomplete-erc-setup)
+ (add-hook 'erc-complete-functions #'erc-pcompletions-at-point 0 t)
+ (setq erc-server-process proc
+ erc-input-marker (make-marker)
+ erc-insert-marker (make-marker)
+ erc-server-current-nick "dummy")
+ (setq-local erc-dcc-list (list elt)) ; for interactive noodling
+ (set-process-query-on-exit-flag proc nil)
+ (goto-char (point-max))
+ (set-marker erc-insert-marker (point-max))
+ (erc-display-prompt)
+ (goto-char erc-input-marker)
+ (funcall test-fn))
+ (when noninteractive
+ (kill-buffer))))
+
+(ert-deftest pcomplete/erc-mode/DCC--get-basic ()
+ (erc-dcc-tests--pcomplete-common
+ (lambda ()
+ (insert "/dcc get ")
+ (call-interactively #'completion-at-point)
+ (save-excursion
+ (beginning-of-line)
+ (should (search-forward "/dcc get tester" nil t)))
+ (call-interactively #'completion-at-point)
+ (save-excursion
+ (beginning-of-line)
+ (should (search-forward "/dcc get tester foo.bin" nil t))))))
+
+(ert-deftest pcomplete/erc-mode/DCC--get-1flag ()
+ (erc-dcc-tests--pcomplete-common
+ (lambda ()
+ (goto-char erc-input-marker)
+ (delete-region (point) (point-max))
+ (insert "/dcc get -")
+ (call-interactively #'completion-at-point)
+ (with-current-buffer (get-buffer "*Completions*")
+ (goto-char (point-min))
+ (search-forward "-s")
+ (search-forward "-t"))
+ (insert "s ")
+ (call-interactively #'completion-at-point)
+ (save-excursion
+ (beginning-of-line)
+ (should (search-forward "/dcc get -s tester" nil t)))
+ (call-interactively #'completion-at-point)
+ (save-excursion
+ (beginning-of-line)
+ (should (search-forward "/dcc get -s tester foo.bin" nil t))))))
+
+(ert-deftest pcomplete/erc-mode/DCC--get-2flags ()
+ (erc-dcc-tests--pcomplete-common
+ (lambda ()
+ (goto-char erc-input-marker)
+ (delete-region (point) (point-max))
+ (insert "/dcc get -")
+ (call-interactively #'completion-at-point)
+ (with-current-buffer (get-buffer "*Completions*")
+ (goto-char (point-min))
+ (search-forward "-s")
+ (search-forward "-t"))
+ (insert "s -")
+ (call-interactively #'completion-at-point)
+ (save-excursion
+ (beginning-of-line)
+ (should (search-forward "/dcc get -s -t " nil t)))
+ (call-interactively #'completion-at-point)
+ (save-excursion
+ (beginning-of-line)
+ (should (search-forward "/dcc get -s -t tester" nil t)))
+ (call-interactively #'completion-at-point)
+ (save-excursion
+ (beginning-of-line)
+ (should (search-forward "/dcc get -s -t tester foo.bin" nil t))))))
+
+(ert-deftest pcomplete/erc-mode/DCC--get-2flags-reverse ()
+ (erc-dcc-tests--pcomplete-common
+ (lambda ()
+ (goto-char erc-input-marker)
+ (delete-region (point) (point-max))
+ (insert "/dcc get -")
+ (call-interactively #'completion-at-point)
+ (with-current-buffer (get-buffer "*Completions*")
+ (goto-char (point-min))
+ (search-forward "-s")
+ (search-forward "-t"))
+ (insert "t -")
+ (call-interactively #'completion-at-point)
+ (save-excursion
+ (beginning-of-line)
+ (should (search-forward "/dcc get -t -s " nil t)))
+ (call-interactively #'completion-at-point)
+ (save-excursion
+ (beginning-of-line)
+ (should (search-forward "/dcc get -t -s tester" nil t)))
+ (call-interactively #'completion-at-point)
+ (save-excursion
+ (beginning-of-line)
+ (should (search-forward "/dcc get -t -s tester foo.bin" nil t))))))
+
;;; erc-dcc-tests.el ends here