aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilip Kaludercic2021-06-09 18:05:35 +0200
committerPhilip Kaludercic2021-06-09 18:21:01 +0200
commit0b367ec39f41825f3eb2ce6acc4d2dd764ecc898 (patch)
treee2c8714e9dcbe807d2f7408d43fb7a881428a693
parent8ea5766050a2bc27ad1166daca3ab2b4707d5728 (diff)
downloademacs-0b367ec39f41825f3eb2ce6acc4d2dd764ecc898.tar.gz
emacs-0b367ec39f41825f3eb2ce6acc4d2dd764ecc898.zip
Remove custom rcirc-completion implementation
* rcirc.el (rcirc-completion-at-point): Improve completion suggestions (rcirc-completions): Remove variable (rcirc-completion-start): Remove variable (rcirc-complete): Remove function (rcirc-mode-map): Bind TAB to completion-at-point (rcirc-mode): Use cycling for completion
-rw-r--r--lisp/net/rcirc.el67
1 files changed, 24 insertions, 43 deletions
diff --git a/lisp/net/rcirc.el b/lisp/net/rcirc.el
index b919e03dce6..d463a14548b 100644
--- a/lisp/net/rcirc.el
+++ b/lisp/net/rcirc.el
@@ -1023,50 +1023,30 @@ The list is updated automatically by `defun-rcirc-command'.")
1023 (if (re-search-backward "[[:space:]@]" rcirc-prompt-end-marker t) 1023 (if (re-search-backward "[[:space:]@]" rcirc-prompt-end-marker t)
1024 (1+ (point)) 1024 (1+ (point))
1025 rcirc-prompt-end-marker))) 1025 rcirc-prompt-end-marker)))
1026 (table (if (and (= beg rcirc-prompt-end-marker) 1026 (table (cond
1027 (eq (char-after beg) ?/)) 1027 ;; No completion before the prompt
1028 (delete-dups 1028 ((< beg rcirc-prompt-end-marker) nil)
1029 (nconc (sort (copy-sequence rcirc-client-commands) 1029 ;; Only complete nicks mid-message
1030 'string-lessp) 1030 ((> beg rcirc-prompt-end-marker)
1031 (sort (copy-sequence rcirc-server-commands) 1031 (rcirc-channel-nicks (rcirc-buffer-process)
1032 'string-lessp))) 1032 rcirc-target))
1033 (rcirc-channel-nicks (rcirc-buffer-process) 1033 ;; Complete commands at the beginning of the
1034 rcirc-target)))) 1034 ;; message, when the first character is a dash
1035 ((eq (char-after beg) ?/)
1036 (mapcar
1037 (lambda (cmd) (concat cmd " "))
1038 (nconc (sort (copy-sequence rcirc-client-commands)
1039 'string-lessp)
1040 (sort (copy-sequence rcirc-server-commands)
1041 'string-lessp))))
1042 ;; Complete usernames right after the prompt by
1043 ;; appending a colon after the name
1044 ((mapcar
1045 (lambda (str) (concat str ": "))
1046 (rcirc-channel-nicks (rcirc-buffer-process)
1047 rcirc-target))))))
1035 (list beg (point) table)))) 1048 (list beg (point) table))))
1036 1049
1037(defvar rcirc-completions nil
1038 "List of possible completions to cycle through.")
1039
1040(defvar rcirc-completion-start nil
1041 "Point indicating where completion starts.")
1042
1043(defun rcirc-complete ()
1044 "Cycle through completions from list of nicks in channel or IRC commands.
1045IRC command completion is performed only if `/' is the first input char."
1046 (interactive)
1047 (unless (rcirc-looking-at-input)
1048 (error "Point not located after rcirc prompt"))
1049 (if (eq last-command this-command)
1050 (setq rcirc-completions
1051 (append (cdr rcirc-completions) (list (car rcirc-completions))))
1052 (let ((completion-ignore-case t)
1053 (table (rcirc-completion-at-point)))
1054 (setq rcirc-completion-start (car table))
1055 (setq rcirc-completions
1056 (and rcirc-completion-start
1057 (all-completions (buffer-substring rcirc-completion-start
1058 (cadr table))
1059 (nth 2 table))))))
1060 (let ((completion (car rcirc-completions)))
1061 (when completion
1062 (delete-region rcirc-completion-start (point))
1063 (insert
1064 (cond
1065 ((= (aref completion 0) ?/) (concat completion " "))
1066 ((= rcirc-completion-start rcirc-prompt-end-marker)
1067 (format rcirc-nick-completion-format completion))
1068 (t completion))))))
1069
1070(defun set-rcirc-decode-coding-system (coding-system) 1050(defun set-rcirc-decode-coding-system (coding-system)
1071 "Set the decode CODING-SYSTEM used in this channel." 1051 "Set the decode CODING-SYSTEM used in this channel."
1072 (interactive "zCoding system for incoming messages: ") 1052 (interactive "zCoding system for incoming messages: ")
@@ -1082,7 +1062,7 @@ IRC command completion is performed only if `/' is the first input char."
1082 (define-key map (kbd "RET") 'rcirc-send-input) 1062 (define-key map (kbd "RET") 'rcirc-send-input)
1083 (define-key map (kbd "M-p") 'rcirc-insert-prev-input) 1063 (define-key map (kbd "M-p") 'rcirc-insert-prev-input)
1084 (define-key map (kbd "M-n") 'rcirc-insert-next-input) 1064 (define-key map (kbd "M-n") 'rcirc-insert-next-input)
1085 (define-key map (kbd "TAB") 'rcirc-complete) 1065 (define-key map (kbd "TAB") 'completion-at-point)
1086 (define-key map (kbd "C-c C-b") 'rcirc-browse-url) 1066 (define-key map (kbd "C-c C-b") 'rcirc-browse-url)
1087 (define-key map (kbd "C-c C-c") 'rcirc-edit-multiline) 1067 (define-key map (kbd "C-c C-c") 'rcirc-edit-multiline)
1088 (define-key map (kbd "C-c C-j") 'rcirc-cmd-join) 1068 (define-key map (kbd "C-c C-j") 'rcirc-cmd-join)
@@ -1195,6 +1175,7 @@ This number is independent of the number of lines in the buffer.")
1195 1175
1196 (add-hook 'completion-at-point-functions 1176 (add-hook 'completion-at-point-functions
1197 'rcirc-completion-at-point nil 'local) 1177 'rcirc-completion-at-point nil 'local)
1178 (setq-local completion-cycle-threshold t)
1198 1179
1199 (run-mode-hooks 'rcirc-mode-hook)) 1180 (run-mode-hooks 'rcirc-mode-hook))
1200 1181