From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Leo Newsgroups: gmane.emacs.bugs Subject: bug#6076: 23.1.96; [PATCH] rcirc-complete for nicks and commands Date: Sun, 02 May 2010 09:49:09 +0100 Message-ID: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: dough.gmane.org 1272790582 30238 80.91.229.12 (2 May 2010 08:56:22 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sun, 2 May 2010 08:56:22 +0000 (UTC) To: 6076@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun May 02 10:56:21 2010 connect(): No such file or directory Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1O8UyI-00033U-HF for geb-bug-gnu-emacs@m.gmane.org; Sun, 02 May 2010 10:56:19 +0200 Original-Received: from localhost ([127.0.0.1]:38248 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O8UyH-0002os-WA for geb-bug-gnu-emacs@m.gmane.org; Sun, 02 May 2010 04:56:18 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1O8Uxz-0002iG-FE for bug-gnu-emacs@gnu.org; Sun, 02 May 2010 04:55:59 -0400 Original-Received: from [140.186.70.92] (port=44100 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O8Uxx-0002i1-I3 for bug-gnu-emacs@gnu.org; Sun, 02 May 2010 04:55:58 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1O8Uxu-00028a-Vj for bug-gnu-emacs@gnu.org; Sun, 02 May 2010 04:55:57 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:44115) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O8Uxu-00028V-SQ for bug-gnu-emacs@gnu.org; Sun, 02 May 2010 04:55:54 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.69) (envelope-from ) id 1O8Uv7-0006Oc-US; Sun, 02 May 2010 04:53:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Leo Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 02 May 2010 08:53:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 6076 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.127279035424577 (code B ref -1); Sun, 02 May 2010 08:53:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 2 May 2010 08:52:34 +0000 Original-Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O8Uuf-0006OM-JV for submit@debbugs.gnu.org; Sun, 02 May 2010 04:52:34 -0400 Original-Received: from mx10.gnu.org ([199.232.76.166]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O8Uud-0006OF-Kc for submit@debbugs.gnu.org; Sun, 02 May 2010 04:52:32 -0400 Original-Received: from lists.gnu.org ([199.232.76.165]:43778) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1O8Uua-0002vs-HJ for submit@debbugs.gnu.org; Sun, 02 May 2010 04:52:28 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1O8UuZ-0001Rz-GL for bug-gnu-emacs@gnu.org; Sun, 02 May 2010 04:52:27 -0400 Original-Received: from [140.186.70.92] (port=50397 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O8UuX-0001LB-Ki for bug-gnu-emacs@gnu.org; Sun, 02 May 2010 04:52:26 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1O8UrT-0001UE-Gl for bug-gnu-emacs@gnu.org; Sun, 02 May 2010 04:49:18 -0400 Original-Received: from ppsw-33.csi.cam.ac.uk ([131.111.8.133]:41708) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O8UrT-0001U0-2P for bug-gnu-emacs@gnu.org; Sun, 02 May 2010 04:49:15 -0400 X-Cam-AntiVirus: no malware found X-Cam-SpamDetails: not scanned X-Cam-ScannerInfo: http://www.cam.ac.uk/cs/email/scanner/ Original-Received: from cpc1-cmbg13-0-0-cust596.cmbg.cable.ntl.com ([86.9.122.85]:62559 helo=Victoria.local) by ppsw-33.csi.cam.ac.uk (smtp.hermes.cam.ac.uk [131.111.8.159]:587) with esmtpsa (PLAIN:sl392) (TLSv1:DHE-RSA-AES128-SHA:128) id 1O8UrP-0003g7-AD (Exim 4.70) for bug-gnu-emacs@gnu.org (return-path ); Sun, 02 May 2010 09:49:11 +0100 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list Resent-Date: Sun, 02 May 2010 04:53:01 -0400 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:36636 Archived-At: --=-=-= The attached patch replaces rcirc-complete-nick with rcirc-complete that completes both nicks and user commands. User command completion is only done after '/'. I have yet to find a reliable way to obtaining a list of commands supported by an irc server. So in the end only the standard commands are copied from RFCs. Let me know if there is a better solution. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-New-command-rcirc-complete-that-completes-both-nicks.patch >From 25bedc278df5376f24eff69f0dd48c19bc046e6f Mon Sep 17 00:00:00 2001 From: Leo Date: Sun, 2 May 2010 07:00:56 +0100 Subject: [PATCH] New command rcirc-complete that completes both nicks and irc commands --- lisp/net/rcirc.el | 90 ++++++++++++++++++++++++++++++++++------------------- 1 files changed, 58 insertions(+), 32 deletions(-) diff --git a/lisp/net/rcirc.el b/lisp/net/rcirc.el index 8d70415..0a87200 100644 --- a/lisp/net/rcirc.el +++ b/lisp/net/rcirc.el @@ -756,42 +756,49 @@ If SILENT is non-nil, do not print the message in any irc buffer." (setq rcirc-input-ring-index (1- rcirc-input-ring-index)) (insert (rcirc-prev-input-string -1)))) -(defvar rcirc-nick-completions nil) -(defvar rcirc-nick-completion-start-offset nil) +(defvar rcirc-completions nil) +(defvar rcirc-completion-start-offset nil) -(defun rcirc-complete-nick () - "Cycle through nick completions from list of nicks in channel." +(defun rcirc-complete () + "Cycle through completions from list of nicks in channel or IRC commands. +IRC command completion is performed only if '/' is the fisrt input char." (interactive) (if (eq last-command this-command) - (setq rcirc-nick-completions - (append (cdr rcirc-nick-completions) - (list (car rcirc-nick-completions)))) - (setq rcirc-nick-completion-start-offset + (setq rcirc-completions + (append (cdr rcirc-completions) + (list (car rcirc-completions)))) + (setq rcirc-completion-start-offset (- (save-excursion (if (re-search-backward " " rcirc-prompt-end-marker t) (1+ (point)) rcirc-prompt-end-marker)) rcirc-prompt-end-marker)) - (setq rcirc-nick-completions - (let ((completion-ignore-case t)) + (let ((completion-ignore-case t)) + (setq rcirc-completions (all-completions - (buffer-substring - (+ rcirc-prompt-end-marker - rcirc-nick-completion-start-offset) - (point)) - (mapcar (lambda (x) (cons x nil)) - (rcirc-channel-nicks (rcirc-buffer-process) - rcirc-target)))))) - (let ((completion (car rcirc-nick-completions))) + (buffer-substring + (+ rcirc-prompt-end-marker + rcirc-completion-start-offset) + (point)) + (if (and (zerop rcirc-completion-start-offset) + (char-after rcirc-prompt-end-marker) + (= (char-after rcirc-prompt-end-marker) ?/)) + (sort (delete-dups (append rcirc-client-commands + (copy-sequence rcirc-server-commands))) + 'string-lessp) + (mapcar (lambda (x) (cons x nil)) + (rcirc-channel-nicks (rcirc-buffer-process) + rcirc-target))))))) + (let ((completion (car rcirc-completions))) (when completion (delete-region (+ rcirc-prompt-end-marker - rcirc-nick-completion-start-offset) + rcirc-completion-start-offset) (point)) (insert (concat completion - (if (= (+ rcirc-prompt-end-marker - rcirc-nick-completion-start-offset) - rcirc-prompt-end-marker) - ": ")))))) + (if (or (= (aref completion 0) ?/) + (not (zerop rcirc-completion-start-offset))) + " " + ": ")))))) (defun set-rcirc-decode-coding-system (coding-system) "Set the decode coding system used in this channel." @@ -809,7 +816,7 @@ If SILENT is non-nil, do not print the message in any irc buffer." (define-key rcirc-mode-map (kbd "RET") 'rcirc-send-input) (define-key rcirc-mode-map (kbd "M-p") 'rcirc-insert-prev-input) (define-key rcirc-mode-map (kbd "M-n") 'rcirc-insert-next-input) -(define-key rcirc-mode-map (kbd "TAB") 'rcirc-complete-nick) +(define-key rcirc-mode-map (kbd "TAB") 'rcirc-complete) (define-key rcirc-mode-map (kbd "C-c C-b") 'rcirc-browse-url) (define-key rcirc-mode-map (kbd "C-c C-c") 'rcirc-edit-multiline) (define-key rcirc-mode-map (kbd "C-c C-j") 'rcirc-cmd-join) @@ -1947,17 +1954,36 @@ activity. Only run if the buffer is not visible and ;; the current buffer/channel/user, and ARGS, which is a string ;; containing the text following the /cmd. +(defvar rcirc-server-commands + '("/admin" "/away" "/connect" "/die" "/error" "/info" + "/invite" "/ison" "/join" "/kick" "/kill" "/links" + "/list" "/lusers" "/mode" "/motd" "/names" "/nick" + "/notice" "/oper" "/part" "/pass" "/ping" "/pong" + "/privmsg" "/quit" "/rehash" "/restart" "/service" "/servlist" + "/server" "/squery" "/squit" "/stats" "/summon" "/time" + "/topic" "/trace" "/user" "/userhost" "/users" "/version" + "/wallops" "/who" "/whois" "/whowas") + "A list of user commands by IRC server. +The value defaults to RFCs 1459 and 2812.") + +;; /me and /ctcp are not defined by `defun-rcirc-command'. +(defvar rcirc-client-commands '("/me" "/ctcp") + "A list of user commands defined by IRC client rcirc. +The list is updated automatically by `defun-rcirc-command'.") + (defmacro defun-rcirc-command (command argument docstring interactive-form &rest body) "Define a command." - `(defun ,(intern (concat "rcirc-cmd-" (symbol-name command))) - (,@argument &optional process target) - ,(concat docstring "\n\nNote: If PROCESS or TARGET are nil, the values given" - "\nby `rcirc-buffer-process' and `rcirc-target' will be used.") - ,interactive-form - (let ((process (or process (rcirc-buffer-process))) - (target (or target rcirc-target))) - ,@body))) + `(progn + (add-to-list 'rcirc-client-commands ,(concat "/" (symbol-name command))) + (defun ,(intern (concat "rcirc-cmd-" (symbol-name command))) + (,@argument &optional process target) + ,(concat docstring "\n\nNote: If PROCESS or TARGET are nil, the values given" + "\nby `rcirc-buffer-process' and `rcirc-target' will be used.") + ,interactive-form + (let ((process (or process (rcirc-buffer-process))) + (target (or target rcirc-target))) + ,@body)))) (defun-rcirc-command msg (message) "Send private MESSAGE to TARGET." -- 1.7.0.4 --=-=-= With best wishes, Leo --=-=-=--