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: Mon, 23 Aug 2010 11:36:25 +0100 Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: dough.gmane.org 1282560276 23572 80.91.229.12 (23 Aug 2010 10:44:36 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 23 Aug 2010 10:44:36 +0000 (UTC) To: 6076@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Aug 23 12:44:35 2010 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 1OnUW2-0001qp-N7 for geb-bug-gnu-emacs@m.gmane.org; Mon, 23 Aug 2010 12:44:35 +0200 Original-Received: from localhost ([127.0.0.1]:40359 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OnUW1-0004kU-8j for geb-bug-gnu-emacs@m.gmane.org; Mon, 23 Aug 2010 06:44:33 -0400 Original-Received: from [140.186.70.92] (port=39521 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OnUQs-0002Wy-H4 for bug-gnu-emacs@gnu.org; Mon, 23 Aug 2010 06:39:15 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OnUQr-0007N6-75 for bug-gnu-emacs@gnu.org; Mon, 23 Aug 2010 06:39:14 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:43252) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OnUQr-0007N2-5C for bug-gnu-emacs@gnu.org; Mon, 23 Aug 2010 06:39:13 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.69) (envelope-from ) id 1OnUNm-0006Ic-Ie; Mon, 23 Aug 2010 06:36:02 -0400 X-Loop: help-debbugs@gnu.org In-Reply-To: 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: Mon, 23 Aug 2010 10:36:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 6076 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 6076-submit@debbugs.gnu.org id=B6076.128255971524134 (code B ref 6076); Mon, 23 Aug 2010 10:36:02 +0000 Original-Received: (at 6076) by debbugs.gnu.org; 23 Aug 2010 10:35:15 +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 1OnUN0-0006HC-KG for submit@debbugs.gnu.org; Mon, 23 Aug 2010 06:35:14 -0400 Original-Received: from ppsw-33.csi.cam.ac.uk ([131.111.8.133]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OnUMw-0006H4-T7 for 6076@debbugs.gnu.org; Mon, 23 Aug 2010 06:35:11 -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.5-4.cable.virginmedia.com ([86.9.122.85]:63914 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 1OnUOB-0001Jh-gH (Exim 4.72) (return-path ); Mon, 23 Aug 2010 11:36:27 +0100 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (Mac OS X 10.6.4) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list Resent-Date: Mon, 23 Aug 2010 06:36:02 -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:39720 Archived-At: --=-=-= I have regenerated the patch against emacs-23 branch with a small tweak that is nick completion no longer inserts a space (same as in the original completion) if it is in the middle of an input. I wonder if it is possible to apply this patch first and then think about using the new completion-in-region-functions. I think this is a safer step. completion-in-region-functions can be problematic when more than one mode customise it though I haven't looked into this in full. But I currently have TeX and a minor mode uses completion-in-region-functions and I have been surprised a few times. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-New-command-rcirc-complete-6076.patch Content-Description: 0001-New-command-rcirc-complete-6076.patch >From af9423a2d099f615a3ff45c0bfa67ae58856681d Mon Sep 17 00:00:00 2001 From: Leo Date: Mon, 23 Aug 2010 11:14:05 +0100 Subject: [PATCH] New command rcirc-complete (#6076) which completes both nicks and irc commands. --- lisp/net/rcirc.el | 100 +++++++++++++++++++++++++++++++++------------------- 1 files changed, 63 insertions(+), 37 deletions(-) diff --git a/lisp/net/rcirc.el b/lisp/net/rcirc.el index ec67c3e..373e1b3 100644 --- a/lisp/net/rcirc.el +++ b/lisp/net/rcirc.el @@ -771,42 +771,66 @@ 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) - -(defun rcirc-complete-nick () - "Cycle through nick completions from list of nicks in channel." +(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'.") + +(defvar rcirc-completions nil) +(defvar rcirc-completion-start-offset nil) + +(defun rcirc-complete () + "Cycle through completions from list of nicks in channel or IRC commands. +IRC command completion is performed only if '/' is the first 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 - (- (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)) - (all-completions + (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)) + (let ((completion-ignore-case t)) + (setq rcirc-completions + (all-completions (buffer-substring (+ rcirc-prompt-end-marker - rcirc-nick-completion-start-offset) + rcirc-completion-start-offset) (point)) - (mapcar (lambda (x) (cons x nil)) - (rcirc-channel-nicks (rcirc-buffer-process) - rcirc-target)))))) - (let ((completion (car rcirc-nick-completions))) + (if (and (zerop rcirc-completion-start-offset) + (char-after rcirc-prompt-end-marker) + (= (char-after rcirc-prompt-end-marker) ?/)) + (delete-dups + (append (sort (copy-sequence rcirc-client-commands) 'string-lessp) + (sort (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) - ": ")))))) + (cond + ((= (aref completion 0) ?/) " ") + ((zerop rcirc-completion-start-offset) ": ") + (t ""))))))) (defun set-rcirc-decode-coding-system (coding-system) "Set the decode coding system used in this channel." @@ -824,7 +848,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) @@ -1962,16 +1986,18 @@ activity. Only run if the buffer is not visible and ;; containing the text following the /cmd. (defmacro defun-rcirc-command (command argument docstring interactive-form - &rest body) + &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.2 --=-=-= Leo --=-=-=--