[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
erc-pcomplete.el
From: |
Sacha Chua |
Subject: |
erc-pcomplete.el |
Date: |
04 Sep 2002 23:20:24 +0800 |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50 |
Here's erc-pcomplete.el. Many of the other functions haven't been
tested thoroughly, but bugs should be easy to track down, and I've
been having a lot of fun with it. Please try it out and send your
suggestions/comments/violent reactions to address@hidden . =)
Making ERC and Emacs just a little bit more fun... <g>
;;; erc-pcomplete.el --- Provides programmable completion for ERC
;;
;; Author: Sacha Chua <address@hidden>
;;
;; This file is not part of GNU Emacs, but the same license applies.
;;
;; To use erc-pcomplete, simply do:
;;
;; (require 'erc-pcomplete)
(require 'pcomplete)
(defcustom erc-pcomplete-nick-postfix ": "
"*When `pcomplete' is used in the first word after the prompt,
add this string to nicks completed."
:group 'erc
:type 'string)
(add-hook 'erc-mode-hook 'pcomplete-erc-setup)
(define-key erc-mode-map "\t" 'pcomplete)
;;; Setup function
(defun pcomplete-erc-setup ()
"Setup erc-mode to use pcomplete."
(set (make-local-variable 'pcomplete-suffix-list)
'(? ?:))
(set (make-local-variable 'pcomplete-parse-arguments-function)
'pcomplete-parse-erc-arguments)
(set (make-local-variable 'pcomplete-command-completion-function)
'pcomplete/erc-mode/complete-command)
(set (make-local-variable 'pcomplete-command-name-function)
'pcomplete-erc-command-name)
(set (make-local-variable 'pcomplete-default-completion-function)
(lambda () (pcomplete-here (pcomplete-erc-nicks))))
)
;;; Programmable completion logic
(defun pcomplete/erc-mode/complete-command ()
(pcomplete-here
(append
(pcomplete-erc-commands)
(pcomplete-erc-nicks erc-pcomplete-nick-postfix)
)))
(defun pcomplete/erc-mode/APPENDTOPIC ()
(pcomplete-here (pcomplete-erc-channels)))
(defun pcomplete/erc-mode/CLEARTOPIC ()
(pcomplete-here (pcomplete-erc-channels)))
(defun pcomplete/erc-mode/DEOP ()
(pcomplete-here (append (pcomplete-erc-ops) (pcomplete-erc-channels)))
(while (pcomplete-here (pcomplete-erc-ops))))
(defun pcomplete/erc-mode/DESCRIBE ()
(pcomplete-here (pcomplete-erc-nicks)))
(defun pcomplete/erc-mode/KICK ()
(pcomplete-here (pcomplete-erc-channels))
(pcomplete-here (pcomplete-erc-nicks)))
(defun pcomplete/erc-mode/LOAD ()
(pcomplete-here (pcomplete-entries)))
(defun pcomplete/erc-mode/SOUND ()
(pcomplete-here (pcomplete-entries)))
(defun pcomplete/erc-mode/MSG ()
(pcomplete-here (append (pcomplete-erc-nicks)
(pcomplete-erc-channels)))
(while (pcomplete-here (pcomplete-erc-nicks))))
(defun pcomplete/erc-mode/NOTICE ()
(pcomplete-here (append (pcomplete-erc-nicks)
(pcomplete-erc-channels)))
(while (pcomplete-here (pcomplete-erc-nicks))))
(defun pcomplete/erc-mode/NAMES ()
(pcomplete-here (pcomplete-erc-channels)))
(defun pcomplete/erc-mode/OP ()
(pcomplete-here (append (pcomplete-erc-not-ops) (pcomplete-erc-channels)))
(while (pcomplete-here (pcomplete-erc-not-ops))))
(defun pcomplete/erc-mode/PART ()
(pcomplete-here (pcomplete-erc-channels)))
(defun pcomplete/erc-mode/QUERY ()
(pcomplete-here (append (pcomplete-erc-nicks)
(pcomplete-erc-channels)))
(while (pcomplete-here (pcomplete-erc-nicks))))
(defun pcomplete/erc-mode/TOPIC ()
(pcomplete-here (pcomplete-erc-channels)))
(defun pcomplete/erc-mode/WHOIS ()
(pcomplete-here (pcomplete-erc-nicks)))
;;; Functions that provide possible completions.
(defun pcomplete-erc-commands ()
"Returns a list of strings of the defined user commands."
(let ((case-fold-search nil))
(mapcar (lambda (x)
(concat "/" (downcase (substring (symbol-name x) 8))))
(apropos-internal "erc-cmd-[A-Z]+")))
)
(defun pcomplete-erc-ops ()
"Returns a list of nicks with ops."
(mapcar (lambda (x)
(if (car (cdr x)) (car x))) channel-members)
)
(defun pcomplete-erc-not-ops ()
"Returns a list of nicks without ops."
(mapcar (lambda (x)
(if (not (car (cdr x))) (car x))) channel-members)
)
(defun pcomplete-erc-nicks (&optional postfix)
"Returns a list of nicks in the current channel."
(mapcar (lambda (x)
(if (car x)
(concat (car x) postfix)
))
channel-members)
)
(defun pcomplete-erc-channels ()
"Returns a list of channels associated with the current server."
(mapcar (lambda (x) (buffer-name x))
(erc-channel-list erc-process))
)
;;; Functions for parsing
(defun pcomplete-erc-command-name ()
"Returns the command name of the first argument."
(if (eq (elt (pcomplete-arg 'first) 0) ?/)
(upcase (substring (pcomplete-arg 'first) 1))
"MSG"
)
)
(defun pcomplete-parse-erc-arguments ()
"Returns a list of parsed whitespace-separated arguments in the current line."
(let (begins args)
(save-excursion
(erc-bol)
(while (< (point) (line-end-position))
(skip-chars-forward " \t\n")
(setq begins (cons (point) begins))
(skip-chars-forward "^ \t\n")
(setq args (cons (buffer-substring-no-properties
(car begins) (point))
args)))
(cons (reverse args) (reverse begins)))))
(provide 'erc-pcomplete)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- erc-pcomplete.el,
Sacha Chua <=
- Next by Date:
您是老師嗎
- Next by thread:
您是老師嗎
- Index(es):