unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#6076: 23.1.96; [PATCH] rcirc-complete for nicks and commands
@ 2010-05-02  8:49 Leo
  2010-05-02  9:01 ` Leo
                   ` (3 more replies)
  0 siblings, 4 replies; 23+ messages in thread
From: Leo @ 2010-05-02  8:49 UTC (permalink / raw)
  To: 6076

[-- Attachment #1: Type: text/plain, Size: 363 bytes --]

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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-New-command-rcirc-complete-that-completes-both-nicks.patch --]
[-- Type: text/x-patch, Size: 6564 bytes --]

From 25bedc278df5376f24eff69f0dd48c19bc046e6f Mon Sep 17 00:00:00 2001
From: Leo <sdl.web@gmail.com>
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


[-- Attachment #3: Type: text/plain, Size: 23 bytes --]


With best wishes,
Leo

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* bug#6076: 23.1.96; [PATCH] rcirc-complete for nicks and commands
  2010-05-02  8:49 bug#6076: 23.1.96; [PATCH] rcirc-complete for nicks and commands Leo
@ 2010-05-02  9:01 ` Leo
  2010-05-04 13:41   ` Leo
  2010-05-03 16:37 ` Stefan Monnier
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 23+ messages in thread
From: Leo @ 2010-05-02  9:01 UTC (permalink / raw)
  To: 6076; +Cc: Ryan Yeske

[-- Attachment #1: Type: text/plain, Size: 562 bytes --]

Hello Ryan,

On 2010-05-02 09:49 +0100, Leo wrote:
> 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.
>
> With best wishes,
> Leo

Please review the attached patch instead which fixed compiler warnings
in the previous patch.

Thanks.
Leo

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-New-command-rcirc-complete-that-completes-both-nicks.patch --]
[-- Type: text/x-patch, Size: 6455 bytes --]

From e184aa733f1ecb4a77f0fef030f8657f2784755c Mon Sep 17 00:00:00 2001
From: Leo <sdl.web@gmail.com>
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 |   92 ++++++++++++++++++++++++++++++++++-------------------
 1 files changed, 59 insertions(+), 33 deletions(-)

diff --git a/lisp/net/rcirc.el b/lisp/net/rcirc.el
index 8d70415..ccc9ec5 100644
--- a/lisp/net/rcirc.el
+++ b/lisp/net/rcirc.el
@@ -756,42 +756,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 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 +833,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)
@@ -1950,14 +1974,16 @@ activity.  Only run if the buffer is not visible and
 (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


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* bug#6076: 23.1.96; [PATCH] rcirc-complete for nicks and commands
  2010-05-02  8:49 bug#6076: 23.1.96; [PATCH] rcirc-complete for nicks and commands Leo
  2010-05-02  9:01 ` Leo
@ 2010-05-03 16:37 ` Stefan Monnier
  2010-05-03 17:45   ` Leo
  2010-08-23 10:36 ` Leo
  2010-09-03 22:13 ` Ryan Yeske
  3 siblings, 1 reply; 23+ messages in thread
From: Stefan Monnier @ 2010-05-03 16:37 UTC (permalink / raw)
  To: Leo; +Cc: 6076

> The attached patch replaces rcirc-complete-nick with rcirc-complete that
> completes both nicks and user commands. User command completion is only
> done after '/'.

Please try and make it use completion-at-point-functions.


        Stefan






^ permalink raw reply	[flat|nested] 23+ messages in thread

* bug#6076: 23.1.96; [PATCH] rcirc-complete for nicks and commands
  2010-05-03 16:37 ` Stefan Monnier
@ 2010-05-03 17:45   ` Leo
  2010-05-04  2:32     ` Stefan Monnier
  0 siblings, 1 reply; 23+ messages in thread
From: Leo @ 2010-05-03 17:45 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 6076

On 2010-05-03 17:37 +0100, Stefan Monnier wrote:
>> The attached patch replaces rcirc-complete-nick with rcirc-complete that
>> completes both nicks and user commands. User command completion is only
>> done after '/'.
>
> Please try and make it use completion-at-point-functions.
>

I thought of this before making the patch.

rcirc has a very simple completion interface that doesn't get in the
way. It cycles through completions if any. No popup windows no
minibuffer messages etc. I have found that excellent for ircing. Do you
think we should force it into the completion at point framework?

>
>         Stefan


Leo






^ permalink raw reply	[flat|nested] 23+ messages in thread

* bug#6076: 23.1.96; [PATCH] rcirc-complete for nicks and commands
  2010-05-03 17:45   ` Leo
@ 2010-05-04  2:32     ` Stefan Monnier
  2010-05-04 16:18       ` Juri Linkov
  0 siblings, 1 reply; 23+ messages in thread
From: Stefan Monnier @ 2010-05-04  2:32 UTC (permalink / raw)
  To: Leo; +Cc: 6076

>>> The attached patch replaces rcirc-complete-nick with rcirc-complete that
>>> completes both nicks and user commands. User command completion is only
>>> done after '/'.
>> Please try and make it use completion-at-point-functions.
> I thought of this before making the patch.

> rcirc has a very simple completion interface that doesn't get in the
> way.  It cycles through completions if any.  No popup windows no
> minibuffer messages etc.  I have found that excellent for ircing.
> Do you think we should force it into the completion at
> point framework?

I guess the right solution is to improve completion-at-point so that it
can be told to use cycling (the functionality is already provided by the
minibuffer-force-complete command).

This relates to a larger question: how to provide "in-buffer" the
variety of completion commands seen in minibuffer completion.
I.e. minibuffer-completion-help, minibuffer-force-complete,
minibuffer-complete-word, icomplete-mode, ...


        Stefan






^ permalink raw reply	[flat|nested] 23+ messages in thread

* bug#6076: 23.1.96; [PATCH] rcirc-complete for nicks and commands
  2010-05-02  9:01 ` Leo
@ 2010-05-04 13:41   ` Leo
  0 siblings, 0 replies; 23+ messages in thread
From: Leo @ 2010-05-04 13:41 UTC (permalink / raw)
  To: bug-gnu-emacs

On 2010-05-02 10:01 +0100, Leo wrote:
> Please review the attached patch instead which fixed compiler warnings
> in the previous patch.
>
> Thanks.
> Leo

This patch make sures commands defined by rcirc are seen first before
server commands.

Leo

diff --git a/lisp/net/rcirc.el b/lisp/net/rcirc.el
index 2e5e7ac..9b58112 100644
--- a/lisp/net/rcirc.el
+++ b/lisp/net/rcirc.el
@@ -800,9 +800,9 @@ IRC command completion is performed only if '/' is the first input char."
              (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)
+                 (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)))))))









^ permalink raw reply related	[flat|nested] 23+ messages in thread

* bug#6076: 23.1.96; [PATCH] rcirc-complete for nicks and commands
  2010-05-04  2:32     ` Stefan Monnier
@ 2010-05-04 16:18       ` Juri Linkov
  2010-05-04 18:29         ` Stefan Monnier
  0 siblings, 1 reply; 23+ messages in thread
From: Juri Linkov @ 2010-05-04 16:18 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 6076, Leo

>>> Please try and make it use completion-at-point-functions.
>> I thought of this before making the patch.
>
>> rcirc has a very simple completion interface that doesn't get in the
>> way.  It cycles through completions if any.  No popup windows no
>> minibuffer messages etc.  I have found that excellent for ircing.
>> Do you think we should force it into the completion at
>> point framework?
>
> I guess the right solution is to improve completion-at-point so that it
> can be told to use cycling (the functionality is already provided by the
> minibuffer-force-complete command).

`flyspell-auto-correct-word' (bound to M-TAB) that cycles through
completions could use this as well.

> This relates to a larger question: how to provide "in-buffer" the
> variety of completion commands seen in minibuffer completion.
> I.e. minibuffer-completion-help, minibuffer-force-complete,
> minibuffer-complete-word, icomplete-mode, ...

Is the problem in the implementation of these commands or in choosing
key bindings for them available for "in-buffer" completion?

-- 
Juri Linkov
http://www.jurta.org/emacs/






^ permalink raw reply	[flat|nested] 23+ messages in thread

* bug#6076: 23.1.96; [PATCH] rcirc-complete for nicks and commands
  2010-05-04 16:18       ` Juri Linkov
@ 2010-05-04 18:29         ` Stefan Monnier
  2010-05-04 20:01           ` Juri Linkov
  0 siblings, 1 reply; 23+ messages in thread
From: Stefan Monnier @ 2010-05-04 18:29 UTC (permalink / raw)
  To: Juri Linkov; +Cc: 6076, Leo

>> I guess the right solution is to improve completion-at-point so that it
>> can be told to use cycling (the functionality is already provided by the
>> minibuffer-force-complete command).
> `flyspell-auto-correct-word' (bound to M-TAB) that cycles through
> completions could use this as well.

Even more so, yes, because the choice between completion and cycling
is not just a preference for this one.

>> This relates to a larger question: how to provide "in-buffer" the
>> variety of completion commands seen in minibuffer completion.
>> I.e. minibuffer-completion-help, minibuffer-force-complete,
>> minibuffer-complete-word, icomplete-mode, ...
> Is the problem in the implementation of these commands or in choosing
> key bindings for them available for "in-buffer" completion?

I'm not sure.  We could try and provide key bindings for all those
commands, but that would seem close to impossible: we're talking about
keybindings that would mostly need to be very short (single-key) to be
worthwhile, and we really don't have that many single-key available.

So, I see it as an implementation problem where we want to make
in-buffer completion modal to some extent: when in-buffer completion is
started you'd be put into a new "mode" (kind of like isearch, I guess),
where new completion commands become available.  The main problem is
how/when to leave this mode (it should be as seamless as possible).
Some other reason for such a change: we want to be able to run code when
completion is finished, e.g. to hide the *Completion* buffer.


        Stefan






^ permalink raw reply	[flat|nested] 23+ messages in thread

* bug#6076: 23.1.96; [PATCH] rcirc-complete for nicks and commands
  2010-05-04 18:29         ` Stefan Monnier
@ 2010-05-04 20:01           ` Juri Linkov
  2010-05-04 21:18             ` Stefan Monnier
  0 siblings, 1 reply; 23+ messages in thread
From: Juri Linkov @ 2010-05-04 20:01 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 6076, Leo

> So, I see it as an implementation problem where we want to make
> in-buffer completion modal to some extent: when in-buffer completion is
> started you'd be put into a new "mode" (kind of like isearch, I guess),
> where new completion commands become available.  The main problem is
> how/when to leave this mode (it should be as seamless as possible).
> Some other reason for such a change: we want to be able to run code when
> completion is finished, e.g. to hide the *Completion* buffer.

Isearch-like mode would be a good thing.  Typing a key not bound
in its mode map will leave this mode and hide the *Completions* buffer.

Also like in isearch, typing M-e could activate the minibuffer with
the current completion string and provide normal UI for completion.
Leaving this minibuffer should copy the completion string from the
minibuffer to the original buffer.

-- 
Juri Linkov
http://www.jurta.org/emacs/






^ permalink raw reply	[flat|nested] 23+ messages in thread

* bug#6076: 23.1.96; [PATCH] rcirc-complete for nicks and commands
  2010-05-04 20:01           ` Juri Linkov
@ 2010-05-04 21:18             ` Stefan Monnier
  2010-05-10 19:14               ` Juri Linkov
  0 siblings, 1 reply; 23+ messages in thread
From: Stefan Monnier @ 2010-05-04 21:18 UTC (permalink / raw)
  To: Juri Linkov; +Cc: 6076, Leo

> Isearch-like mode would be a good thing.  Typing a key not bound
> in its mode map will leave this mode and hide the *Completions* buffer.

Right.  But choosing which keys/events make it leave because we want it
to be very lightweight (i.e. we want to leave as soon as possible), but
we'd rather not leave when the user is still editing the completion.

So self-insert-command should not leave, but then SPC (and several
others likewise) probably should (even tho it's also
self-insert-command) and maybe DEL shouldn't either, but what about
C-f/C-b?  I was thinking maybe we should decide it based on the position
of point (whether it's still inside the completion text or not).


        Stefan






^ permalink raw reply	[flat|nested] 23+ messages in thread

* bug#6076: 23.1.96; [PATCH] rcirc-complete for nicks and commands
  2010-05-04 21:18             ` Stefan Monnier
@ 2010-05-10 19:14               ` Juri Linkov
  2010-05-11  1:14                 ` Stefan Monnier
  0 siblings, 1 reply; 23+ messages in thread
From: Juri Linkov @ 2010-05-10 19:14 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 6076, Leo

>> Isearch-like mode would be a good thing.  Typing a key not bound
>> in its mode map will leave this mode and hide the *Completions* buffer.
>
> Right.  But choosing which keys/events make it leave because we want it
> to be very lightweight (i.e. we want to leave as soon as possible), but
> we'd rather not leave when the user is still editing the completion.
>
> So self-insert-command should not leave, but then SPC (and several
> others likewise) probably should (even tho it's also
> self-insert-command) and maybe DEL shouldn't either, but what about
> C-f/C-b?  I was thinking maybe we should decide it based on the position
> of point (whether it's still inside the completion text or not).

This is something that in other programs is called "in-place editing".
Usually a field for editing is highlighted with a different background.
In terms of Emacs this could be called "in-place completion".  For its
implementation the most suitable feature is the `field' property.
When completion is activated, a field could be created in the buffer
and removed when completion is finished.  I suggest using the same
key to finish completion as in the minibuffer, i.e. RET.

-- 
Juri Linkov
http://www.jurta.org/emacs/





^ permalink raw reply	[flat|nested] 23+ messages in thread

* bug#6076: 23.1.96; [PATCH] rcirc-complete for nicks and commands
  2010-05-10 19:14               ` Juri Linkov
@ 2010-05-11  1:14                 ` Stefan Monnier
  2010-05-11 16:54                   ` Juri Linkov
  0 siblings, 1 reply; 23+ messages in thread
From: Stefan Monnier @ 2010-05-11  1:14 UTC (permalink / raw)
  To: Juri Linkov; +Cc: 6076, Leo

> This is something that in other programs is called "in-place editing".
> Usually a field for editing is highlighted with a different background.
> In terms of Emacs this could be called "in-place completion".  For its
> implementation the most suitable feature is the `field' property.
> When completion is activated, a field could be created in the buffer
> and removed when completion is finished.  I suggest using the same
> key to finish completion as in the minibuffer, i.e. RET.

Yes, completion-in-region already places a field, so that's indeed part
of the plan, but I'd like it to be slightly more lightweight than what
you suggest: RET should not be required to leave completion.


        Stefan





^ permalink raw reply	[flat|nested] 23+ messages in thread

* bug#6076: 23.1.96; [PATCH] rcirc-complete for nicks and commands
  2010-05-11  1:14                 ` Stefan Monnier
@ 2010-05-11 16:54                   ` Juri Linkov
  2010-05-11 19:52                     ` Stefan Monnier
  0 siblings, 1 reply; 23+ messages in thread
From: Juri Linkov @ 2010-05-11 16:54 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 6076, Leo

> Yes, completion-in-region already places a field, so that's indeed part
> of the plan, but I'd like it to be slightly more lightweight than what
> you suggest: RET should not be required to leave completion.

Then maybe leave completion when the property `point-left' calls its hook
when leaving the field?

-- 
Juri Linkov
http://www.jurta.org/emacs/





^ permalink raw reply	[flat|nested] 23+ messages in thread

* bug#6076: 23.1.96; [PATCH] rcirc-complete for nicks and commands
  2010-05-11 16:54                   ` Juri Linkov
@ 2010-05-11 19:52                     ` Stefan Monnier
  0 siblings, 0 replies; 23+ messages in thread
From: Stefan Monnier @ 2010-05-11 19:52 UTC (permalink / raw)
  To: Juri Linkov; +Cc: 6076, Leo

>> Yes, completion-in-region already places a field, so that's indeed part
>> of the plan, but I'd like it to be slightly more lightweight than what
>> you suggest: RET should not be required to leave completion.
> Then maybe leave completion when the property `point-left' calls its hook
> when leaving the field?

Yup, something like that (tho, with extra care since point-motion hooks
are evil).


        Stefan





^ permalink raw reply	[flat|nested] 23+ messages in thread

* bug#6076: 23.1.96; [PATCH] rcirc-complete for nicks and commands
  2010-05-02  8:49 bug#6076: 23.1.96; [PATCH] rcirc-complete for nicks and commands Leo
  2010-05-02  9:01 ` Leo
  2010-05-03 16:37 ` Stefan Monnier
@ 2010-08-23 10:36 ` Leo
  2010-09-03 22:13 ` Ryan Yeske
  3 siblings, 0 replies; 23+ messages in thread
From: Leo @ 2010-08-23 10:36 UTC (permalink / raw)
  To: 6076

[-- Attachment #1: Type: text/plain, Size: 594 bytes --]

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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-New-command-rcirc-complete-6076.patch --]
[-- Type: text/x-diff, Size: 6373 bytes --]

From af9423a2d099f615a3ff45c0bfa67ae58856681d Mon Sep 17 00:00:00 2001
From: Leo <sdl.web@gmail.com>
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


[-- Attachment #3: Type: text/plain, Size: 5 bytes --]


Leo

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* bug#6076: 23.1.96; [PATCH] rcirc-complete for nicks and commands
  2010-05-02  8:49 bug#6076: 23.1.96; [PATCH] rcirc-complete for nicks and commands Leo
                   ` (2 preceding siblings ...)
  2010-08-23 10:36 ` Leo
@ 2010-09-03 22:13 ` Ryan Yeske
  2010-09-04  8:24   ` Stefan Monnier
  3 siblings, 1 reply; 23+ messages in thread
From: Ryan Yeske @ 2010-09-03 22:13 UTC (permalink / raw)
  To: 6076; +Cc: Leo

I reviewed Leo's updated patch at http://debbugs.gnu.org/cgi/bugreport.cgi?bug=6076#47

I agree with Leo, we should install this patch and then look into
improvements using completion in region.

Ryan





^ permalink raw reply	[flat|nested] 23+ messages in thread

* bug#6076: 23.1.96; [PATCH] rcirc-complete for nicks and commands
  2010-09-03 22:13 ` Ryan Yeske
@ 2010-09-04  8:24   ` Stefan Monnier
  2010-09-04 10:21     ` Leo
  0 siblings, 1 reply; 23+ messages in thread
From: Stefan Monnier @ 2010-09-04  8:24 UTC (permalink / raw)
  To: Ryan Yeske; +Cc: 6076, Leo

> I reviewed Leo's updated patch at http://debbugs.gnu.org/cgi/bugreport.cgi?bug=6076#47
> I agree with Leo, we should install this patch and then look into
> improvements using completion in region.

I mostly agree, but I think the patch should first be restructured into
one or 2 functions suitable for completion-at-point-functions
(i.e. either one that provides the completion data for nicks and
commands, or one for nicks and one for commands), and then an
rcirc-complete command that uses these functions to do the completion
with the desired UI.

I.e. basically a refactoring of rcirc-complete such that it uses the
same interface between the completion data and the completion UI as the
one used by completion-at-point.

Then users can choose to use rcirc-complete or completion-at-point, and
when/if completion-at-point (i.e. completion-in-region) gets to the
point of being able to provide the same behavior as rcirc-complete, then
we can get rid of rcirc-complete.


        Stefan





^ permalink raw reply	[flat|nested] 23+ messages in thread

* bug#6076: 23.1.96; [PATCH] rcirc-complete for nicks and commands
  2010-09-04  8:24   ` Stefan Monnier
@ 2010-09-04 10:21     ` Leo
  2010-09-04 21:44       ` Stefan Monnier
  0 siblings, 1 reply; 23+ messages in thread
From: Leo @ 2010-09-04 10:21 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 6076, Ryan Yeske

[-- Attachment #1: Type: text/plain, Size: 1901 bytes --]

On 2010-09-04 09:24 +0100, Stefan Monnier wrote:
>> I reviewed Leo's updated patch at http://debbugs.gnu.org/cgi/bugreport.cgi?bug=6076#47
>> I agree with Leo, we should install this patch and then look into
>> improvements using completion in region.
>
> I mostly agree, but I think the patch should first be restructured into
> one or 2 functions suitable for completion-at-point-functions
> (i.e. either one that provides the completion data for nicks and
> commands, or one for nicks and one for commands), and then an
> rcirc-complete command that uses these functions to do the completion
> with the desired UI.
>
> I.e. basically a refactoring of rcirc-complete such that it uses the
> same interface between the completion data and the completion UI as the
> one used by completion-at-point.
>
> Then users can choose to use rcirc-complete or completion-at-point, and
> when/if completion-at-point (i.e. completion-in-region) gets to the
> point of being able to provide the same behavior as rcirc-complete, then
> we can get rid of rcirc-complete.
>
>
>         Stefan

Thanks, Stefan, for the comments.

I have recreated the patch against emacs-23 as suggested. I have also
briefly tested it. Seems to work as expected. M-TAB in rcirc-mode now
uses the new completion at point interface.

BTW, I just realise the macro defun-rcirc-command is better named
define-rcirc-command.

2010-09-04  Leo <sdl.web@gmail.com>

	* net/rcirc.el (rcirc-server-commands, rcirc-client-commands)
	(rcirc-completion-start): new variables.
	(rcirc-nick-completions): rename to rcirc-completions.
	(rcirc-nick-completion-start-offset): delete.
	(rcirc-completion-at-point): new function for constructing
	completion data for both nicks and irc commands. Add to
	completion-at-point-functions in rcirc mode.
	(rcirc-complete): use rcirc-completion-at-point.
	(defun-rcirc-command): update rcirc-client-commands.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: rcirc-complete.diff --]
[-- Type: text/x-diff, Size: 6469 bytes --]

diff --git a/lisp/net/rcirc.el b/lisp/net/rcirc.el
index ec67c3e..cade679 100644
--- a/lisp/net/rcirc.el
+++ b/lisp/net/rcirc.el
@@ -771,42 +771,63 @@ 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'.")
+
+(defun rcirc-completion-at-point ()
+  "Function used for `completion-at-point-functions' in `rcirc-mode'."
+  (let* ((beg (save-excursion
+		(if (re-search-backward " " rcirc-prompt-end-marker t)
+		    (1+ (point))
+		  rcirc-prompt-end-marker)))
+	 (table (if (and (eq beg rcirc-prompt-end-marker)
+			 (eq (char-after beg) ?/))
+		    (delete-dups
+		     (append (sort (copy-sequence rcirc-client-commands) 'string-lessp)
+			     (sort (copy-sequence rcirc-server-commands) 'string-lessp)))
+		  (rcirc-channel-nicks (rcirc-buffer-process) rcirc-target))))
+    (list beg (point) table)))
+
+(defvar rcirc-completions nil)
+(defvar rcirc-completion-start 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
-	     (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)))
+      (setq rcirc-completions
+	    (append (cdr rcirc-completions) (list (car rcirc-completions))))
+    (let ((completion-ignore-case t)
+	  (table (rcirc-completion-at-point)))
+      (setq rcirc-completion-start (car table))
+      (setq rcirc-completions
+	    (all-completions (buffer-substring rcirc-completion-start
+					       (cadr table))
+			     (nth 2 table)))))
+  (let ((completion (car rcirc-completions)))
     (when completion
-      (delete-region (+ rcirc-prompt-end-marker
-			rcirc-nick-completion-start-offset)
-		     (point))
-      (insert (concat completion
-                      (if (= (+ rcirc-prompt-end-marker
-                                rcirc-nick-completion-start-offset)
-                             rcirc-prompt-end-marker)
-                          ": "))))))
+      (delete-region rcirc-completion-start (point))
+      (insert
+       (concat completion
+	       (cond
+		((= (aref completion 0) ?/) " ")
+		((= rcirc-completion-start rcirc-prompt-end-marker) ": ")
+		(t "")))))))
 
 (defun set-rcirc-decode-coding-system (coding-system)
   "Set the decode coding system used in this channel."
@@ -824,7 +845,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)
@@ -944,6 +965,9 @@ This number is independent of the number of lines in the buffer.")
 				       rcirc-buffer-alist))))
     (rcirc-update-short-buffer-names))
 
+  (add-hook 'completion-at-point-functions
+            'rcirc-completion-at-point nil 'local)
+
   (run-hooks 'rcirc-mode-hook))
 
 (defun rcirc-update-prompt (&optional all)
@@ -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."

[-- Attachment #3: Type: text/plain, Size: 14 bytes --]


Regards,
Leo

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* bug#6076: 23.1.96; [PATCH] rcirc-complete for nicks and commands
  2010-09-04 10:21     ` Leo
@ 2010-09-04 21:44       ` Stefan Monnier
  2010-09-06 17:52         ` Leo
  0 siblings, 1 reply; 23+ messages in thread
From: Stefan Monnier @ 2010-09-04 21:44 UTC (permalink / raw)
  To: Leo; +Cc: 6076, Ryan Yeske

> I have recreated the patch against emacs-23 as suggested. I have also
> briefly tested it. Seems to work as expected. M-TAB in rcirc-mode now
> uses the new completion at point interface.

Looks goot to me,


        Stefan





^ permalink raw reply	[flat|nested] 23+ messages in thread

* bug#6076: 23.1.96; [PATCH] rcirc-complete for nicks and commands
  2010-09-04 21:44       ` Stefan Monnier
@ 2010-09-06 17:52         ` Leo
  2010-09-11 12:55           ` Stefan Monnier
  0 siblings, 1 reply; 23+ messages in thread
From: Leo @ 2010-09-06 17:52 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 6076, Ryan Yeske

On 2010-09-04 22:44 +0100, Stefan Monnier wrote:
>> I have recreated the patch against emacs-23 as suggested. I have also
>> briefly tested it. Seems to work as expected. M-TAB in rcirc-mode now
>> uses the new completion at point interface.
>
> Looks goot to me,
>
>
>         Stefan

I have been using it over the weekend and nothing abnormal found. But
maybe apply the following minor tweaks on top of the previous patch.

diff --git a/lisp/net/rcirc.el b/lisp/net/rcirc.el
index cade679..7a43678 100644
--- a/lisp/net/rcirc.el
+++ b/lisp/net/rcirc.el
@@ -794,11 +794,12 @@ The list is updated automatically by `defun-rcirc-command'.")
 		(if (re-search-backward " " rcirc-prompt-end-marker t)
 		    (1+ (point))
 		  rcirc-prompt-end-marker)))
-	 (table (if (and (eq beg rcirc-prompt-end-marker)
+	 (table (if (and (= beg rcirc-prompt-end-marker)
 			 (eq (char-after beg) ?/))
 		    (delete-dups
-		     (append (sort (copy-sequence rcirc-client-commands) 'string-lessp)
-			     (sort (copy-sequence rcirc-server-commands) 'string-lessp)))
+		     (nconc
+		      (sort (copy-sequence rcirc-client-commands) 'string-lessp)
+		      (sort (copy-sequence rcirc-server-commands) 'string-lessp)))
 		  (rcirc-channel-nicks (rcirc-buffer-process) rcirc-target))))
     (list beg (point) table)))

  Leo





^ permalink raw reply related	[flat|nested] 23+ messages in thread

* bug#6076: 23.1.96; [PATCH] rcirc-complete for nicks and commands
  2010-09-06 17:52         ` Leo
@ 2010-09-11 12:55           ` Stefan Monnier
  2010-09-11 13:03             ` Leo
  0 siblings, 1 reply; 23+ messages in thread
From: Stefan Monnier @ 2010-09-11 12:55 UTC (permalink / raw)
  To: Leo; +Cc: 6076, Ryan Yeske

>>> I have recreated the patch against emacs-23 as suggested. I have also
>>> briefly tested it. Seems to work as expected. M-TAB in rcirc-mode now
>>> uses the new completion at point interface.
>> Looks good to me,
> I have been using it over the weekend and nothing abnormal found. But
> maybe apply the following minor tweaks on top of the previous patch.

Can you post a final patch to install?


        Stefan





^ permalink raw reply	[flat|nested] 23+ messages in thread

* bug#6076: 23.1.96; [PATCH] rcirc-complete for nicks and commands
  2010-09-11 12:55           ` Stefan Monnier
@ 2010-09-11 13:03             ` Leo
  2010-09-12 11:11               ` Stefan Monnier
  0 siblings, 1 reply; 23+ messages in thread
From: Leo @ 2010-09-11 13:03 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 6076, Ryan Yeske

[-- Attachment #1: Type: text/plain, Size: 1056 bytes --]

On 2010-09-11 13:55 +0100, Stefan Monnier wrote:
>>>> I have recreated the patch against emacs-23 as suggested. I have also
>>>> briefly tested it. Seems to work as expected. M-TAB in rcirc-mode now
>>>> uses the new completion at point interface.
>>> Looks good to me,
>> I have been using it over the weekend and nothing abnormal found. But
>> maybe apply the following minor tweaks on top of the previous patch.
>
> Can you post a final patch to install?
>
>
>         Stefan

Attached.

The ChangeLog entry could looks something like this:

	* net/rcirc.el (rcirc-server-commands, rcirc-client-commands)
	(rcirc-completion-start): new variables.
	(rcirc-nick-completions): rename to rcirc-completions.
	(rcirc-nick-completion-start-offset): delete.
	(rcirc-completion-at-point): new function for constructing
	completion data for both nicks and irc commands. Add to
	completion-at-point-functions in rcirc mode.
	(rcirc-complete): rename from rcirc-nick-complete; use
	rcirc-completion-at-point.
	(defun-rcirc-command): update rcirc-client-commands.



[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: rcirc-complete.diff --]
[-- Type: text/x-diff, Size: 6476 bytes --]

diff --git a/lisp/net/rcirc.el b/lisp/net/rcirc.el
index ec67c3e..7a43678 100644
--- a/lisp/net/rcirc.el
+++ b/lisp/net/rcirc.el
@@ -771,42 +771,64 @@ 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'.")
+
+(defun rcirc-completion-at-point ()
+  "Function used for `completion-at-point-functions' in `rcirc-mode'."
+  (let* ((beg (save-excursion
+		(if (re-search-backward " " rcirc-prompt-end-marker t)
+		    (1+ (point))
+		  rcirc-prompt-end-marker)))
+	 (table (if (and (= beg rcirc-prompt-end-marker)
+			 (eq (char-after beg) ?/))
+		    (delete-dups
+		     (nconc
+		      (sort (copy-sequence rcirc-client-commands) 'string-lessp)
+		      (sort (copy-sequence rcirc-server-commands) 'string-lessp)))
+		  (rcirc-channel-nicks (rcirc-buffer-process) rcirc-target))))
+    (list beg (point) table)))
+
+(defvar rcirc-completions nil)
+(defvar rcirc-completion-start 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
-	     (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)))
+      (setq rcirc-completions
+	    (append (cdr rcirc-completions) (list (car rcirc-completions))))
+    (let ((completion-ignore-case t)
+	  (table (rcirc-completion-at-point)))
+      (setq rcirc-completion-start (car table))
+      (setq rcirc-completions
+	    (all-completions (buffer-substring rcirc-completion-start
+					       (cadr table))
+			     (nth 2 table)))))
+  (let ((completion (car rcirc-completions)))
     (when completion
-      (delete-region (+ rcirc-prompt-end-marker
-			rcirc-nick-completion-start-offset)
-		     (point))
-      (insert (concat completion
-                      (if (= (+ rcirc-prompt-end-marker
-                                rcirc-nick-completion-start-offset)
-                             rcirc-prompt-end-marker)
-                          ": "))))))
+      (delete-region rcirc-completion-start (point))
+      (insert
+       (concat completion
+	       (cond
+		((= (aref completion 0) ?/) " ")
+		((= rcirc-completion-start rcirc-prompt-end-marker) ": ")
+		(t "")))))))
 
 (defun set-rcirc-decode-coding-system (coding-system)
   "Set the decode coding system used in this channel."
@@ -824,7 +846,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)
@@ -944,6 +966,9 @@ This number is independent of the number of lines in the buffer.")
 				       rcirc-buffer-alist))))
     (rcirc-update-short-buffer-names))
 
+  (add-hook 'completion-at-point-functions
+            'rcirc-completion-at-point nil 'local)
+
   (run-hooks 'rcirc-mode-hook))
 
 (defun rcirc-update-prompt (&optional all)
@@ -1962,16 +1987,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."

[-- Attachment #3: Type: text/plain, Size: 5 bytes --]


Leo

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* bug#6076: 23.1.96; [PATCH] rcirc-complete for nicks and commands
  2010-09-11 13:03             ` Leo
@ 2010-09-12 11:11               ` Stefan Monnier
  0 siblings, 0 replies; 23+ messages in thread
From: Stefan Monnier @ 2010-09-12 11:11 UTC (permalink / raw)
  To: Leo; +Cc: Ryan Yeske

> The ChangeLog entry could looks something like this:

> 	* net/rcirc.el (rcirc-server-commands, rcirc-client-commands)
> 	(rcirc-completion-start): new variables.
> 	(rcirc-nick-completions): rename to rcirc-completions.
> 	(rcirc-nick-completion-start-offset): delete.
> 	(rcirc-completion-at-point): new function for constructing
> 	completion data for both nicks and irc commands. Add to
> 	completion-at-point-functions in rcirc mode.
> 	(rcirc-complete): rename from rcirc-nick-complete; use
> 	rcirc-completion-at-point.
> 	(defun-rcirc-command): update rcirc-client-commands.

Looks fine, except that we capitalize after the ":".
Installed, thank you,


        Stefan





^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2010-09-12 11:11 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-05-02  8:49 bug#6076: 23.1.96; [PATCH] rcirc-complete for nicks and commands Leo
2010-05-02  9:01 ` Leo
2010-05-04 13:41   ` Leo
2010-05-03 16:37 ` Stefan Monnier
2010-05-03 17:45   ` Leo
2010-05-04  2:32     ` Stefan Monnier
2010-05-04 16:18       ` Juri Linkov
2010-05-04 18:29         ` Stefan Monnier
2010-05-04 20:01           ` Juri Linkov
2010-05-04 21:18             ` Stefan Monnier
2010-05-10 19:14               ` Juri Linkov
2010-05-11  1:14                 ` Stefan Monnier
2010-05-11 16:54                   ` Juri Linkov
2010-05-11 19:52                     ` Stefan Monnier
2010-08-23 10:36 ` Leo
2010-09-03 22:13 ` Ryan Yeske
2010-09-04  8:24   ` Stefan Monnier
2010-09-04 10:21     ` Leo
2010-09-04 21:44       ` Stefan Monnier
2010-09-06 17:52         ` Leo
2010-09-11 12:55           ` Stefan Monnier
2010-09-11 13:03             ` Leo
2010-09-12 11:11               ` Stefan Monnier

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).