]> code.delx.au - gnu-emacs/blobdiff - lisp/erc/erc-pcomplete.el
Update docs for `customize-mode'
[gnu-emacs] / lisp / erc / erc-pcomplete.el
index 355770c5dcce59d77919398692533a9fe62cfb4c..9f572396de81b344c24e1551358cfa2286d638ee 100644 (file)
@@ -1,8 +1,9 @@
 ;;; erc-pcomplete.el --- Provides programmable completion for ERC
 
-;; Copyright (C) 2002-2004, 2006-2011 Free Software Foundation, Inc.
+;; Copyright (C) 2002-2004, 2006-2016 Free Software Foundation, Inc.
 
 ;; Author: Sacha Chua <sacha@free.net.ph>
+;; Maintainer: emacs-devel@gnu.org
 ;; Keywords: comm, convenience
 ;; URL: http://www.emacswiki.org/cgi-bin/wiki.pl?ErcCompletion
 
@@ -32,7 +33,7 @@
 ;;
 ;; If you want nickname completions ordered such that the most recent
 ;; speakers are listed first, set
-;; `erc-pcomplete-order-nickname-completions' to `t'.
+;; `erc-pcomplete-order-nickname-completions' to t.
 ;;
 ;; See CREDITS for other contributors.
 ;;
 (require 'erc)
 (require 'erc-compat)
 (require 'time-date)
-(eval-when-compile (require 'cl))
 
 (defgroup erc-pcomplete nil
   "Programmable completion for ERC"
   :group 'erc)
 
-(defcustom erc-pcomplete-nick-postfix ": "
-  "*When `pcomplete' is used in the first word after the prompt,
+(defcustom erc-pcomplete-nick-postfix ":"
+  "When `pcomplete' is used in the first word after the prompt,
 add this string to nicks completed."
   :group 'erc-pcomplete
   :type 'string)
@@ -64,20 +64,27 @@ the most recent speakers are listed first."
 (define-erc-module pcomplete Completion
   "In ERC Completion mode, the TAB key does completion whenever possible."
   ((add-hook 'erc-mode-hook 'pcomplete-erc-setup)
-   (add-hook 'erc-complete-functions 'erc-pcomplete)
+   (add-hook 'erc-complete-functions 'erc-pcompletions-at-point)
    (erc-buffer-list #'pcomplete-erc-setup))
   ((remove-hook 'erc-mode-hook 'pcomplete-erc-setup)
-   (remove-hook 'erc-complete-functions 'erc-pcomplete)))
+   (remove-hook 'erc-complete-functions 'erc-pcompletions-at-point)))
+
+(defun erc-pcompletions-at-point ()
+  "ERC completion data from pcomplete.
+for use on `completion-at-point-function'."
+  (when (> (point) (erc-beg-of-input-line))
+    (or (let ((pcomplete-default-completion-function #'ignore))
+          (pcomplete-completions-at-point))
+        (let ((c (pcomplete-completions-at-point)))
+          (if c (nconc c '(:exclusive no)))))))
 
 (defun erc-pcomplete ()
   "Complete the nick before point."
+  (declare (obsolete completion-at-point "25.1"))
   (interactive)
   (when (> (point) (erc-beg-of-input-line))
-    (let ((last-command (if (eq last-command 'erc-complete-word)
-                            'pcomplete
-                          last-command)))
-      (call-interactively 'pcomplete))
-    t))
+    (let ((completion-at-point-functions '(erc-pcompletions-at-point)))
+      (completion-at-point))))
 
 ;;; Setup function
 
@@ -87,10 +94,8 @@ the most recent speakers are listed first."
        t)
   (set (make-local-variable 'pcomplete-use-paring)
        nil)
-  (set (make-local-variable 'pcomplete-suffix-list)
-       '(?  ?:))
   (set (make-local-variable 'pcomplete-parse-arguments-function)
-       'pcomplete-parse-erc-arguments)
+       'pcomplete-erc-parse-arguments)
   (set (make-local-variable 'pcomplete-command-completion-function)
        'pcomplete/erc-mode/complete-command)
   (set (make-local-variable 'pcomplete-command-name-function)
@@ -220,9 +225,10 @@ If optional argument IGNORE-SELF is non-nil, don't return the current nick."
                  (erc-get-channel-user-list)))
         (nicks nil))
     (dolist (user users)
-      (unless (and ignore-self
-                   (string= (erc-server-user-nickname (car user))
-                            (erc-current-nick)))
+      (unless (or (not user) 
+                  (and ignore-self
+                       (string= (erc-server-user-nickname (car user))
+                                (erc-current-nick))))
         (setq nicks (cons (concat (erc-server-user-nickname (car user))
                                   postfix)
                           nicks))))
@@ -232,10 +238,12 @@ If optional argument IGNORE-SELF is non-nil, don't return the current nick."
   "Returns a list of all nicks on the current server."
   (let (nicks)
     (erc-with-server-buffer
-      (maphash (lambda (nick user)
-                 (setq nicks (cons (concat nick postfix) nicks)))
+      (maphash (lambda (_nick user)
+                 (setq nicks (cons
+                              (concat (erc-server-user-nickname user) postfix)
+                              nicks)))
                erc-server-users))
-      nicks))
+    nicks))
 
 (defun pcomplete-erc-channels ()
   "Returns a list of channels associated with the current server."
@@ -250,7 +258,7 @@ If optional argument IGNORE-SELF is non-nil, don't return the current nick."
       (upcase (substring (pcomplete-arg 'first) 1))
     "SAY"))
 
-(defun pcomplete-parse-erc-arguments ()
+(defun pcomplete-erc-parse-arguments ()
   "Returns a list of parsed whitespace-separated arguments.
 These are the words from the beginning of the line after the prompt
 up to where point is right now."