diff lisp/erc/erc.el @ 75259:f45c5edf0be4

Merge from erc--main--0 Highlights: - Display messages starting with "/" but are not commands correctly. - Add erc-capab.el file, with capab-identify module. - Fix various ERC menu bugs and add "Current channel" submenu. - Make header-line display look nicer. - Fix warning when auto-authenticating to bitlbee. - New option erc-system-name allows the hostname next to your nick to be customized. Revision: emacs@sv.gnu.org/emacs--devo--0--patch-599 Creator: Michael Olson <mwolson@gnu.org>
author Miles Bader <miles@gnu.org>
date Wed, 17 Jan 2007 18:17:25 +0000
parents e566d4fc8dd2
children 864a6f6648e2
line wrap: on
line diff
--- a/lisp/erc/erc.el	Wed Jan 17 13:20:47 2007 +0000
+++ b/lisp/erc/erc.el	Wed Jan 17 18:17:25 2007 +0000
@@ -1,7 +1,7 @@
 ;; erc.el --- An Emacs Internet Relay Chat client
 
 ;; Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
-;;   2006 Free Software Foundation, Inc.
+;;   2006, 2007 Free Software Foundation, Inc.
 
 ;; Author: Alexander L. Belikoff (alexander@belikoff.net)
 ;; Contributors: Sergey Berezin (sergey.berezin@cs.cmu.edu),
@@ -74,7 +74,6 @@
 (require 'pp)
 (require 'thingatpt)
 (require 'erc-compat)
-(require 'erc-menu)
 
 (defvar erc-official-location
   "http://emacswiki.org/cgi-bin/wiki/ERC (mailing list: erc-discuss@gnu.org)"
@@ -782,6 +781,13 @@
   :group 'erc
   :type 'string)
 
+(defcustom erc-system-name nil
+  "Use this as the name of your system.
+If nil, ERC will call `system-name' to get this information."
+  :group 'erc
+  :type '(choice (const :tag "Default system name" nil)
+		 string))
+
 (defcustom erc-ignore-list nil
   "*List of regexps matching user identifiers to ignore.
 
@@ -1764,7 +1770,7 @@
 
 (defcustom erc-modules '(netsplit fill button match track completion readonly
 				  ring autojoin noncommands irccontrols
-				  stamp)
+				  stamp menu)
   "A list of modules which ERC should enable.
 If you set the value of this without using `customize' remember to call
 \(erc-update-modules) after you change it.  When using `customize', modules
@@ -1791,17 +1797,21 @@
     (const :tag "Set away status automatically" autoaway)
     (const :tag "Join channels automatically" autojoin)
     (const :tag "Buttonize URLs, nicknames, and other text" button)
+    (const
+     :tag
+     "Mark unidentified users on freenode and other servers supporting CAPAB"
+     capab-identify)
     (const :tag "Wrap long lines" fill)
     (const :tag "Launch an identd server on port 8113" identd)
     (const :tag "Highlight or remove IRC control characters"
 	   irccontrols)
     (const :tag "Save buffers in logs" log)
     (const :tag "Highlight pals, fools, and other keywords" match)
+    (const :tag "Display a menu in ERC buffers" menu)
     (const :tag "Detect netsplits" netsplit)
     (const :tag "Don't display non-IRC commands after evaluation"
 	   noncommands)
-    (const :tag
-	   "Notify when the online status of certain users changes"
+    (const :tag "Notify when the online status of certain users changes"
 	   notify)
     (const :tag "Complete nicknames and commands (programmable)"
 	   completion)
@@ -1831,6 +1841,8 @@
       (setq req (concat "erc-" (symbol-name mod)))
       (cond
        ;; yuck. perhaps we should bring the filenames into sync?
+       ((string= req "erc-capab-identify")
+	(setq req "erc-capab"))
        ((string= req "erc-completion")
 	(setq req "erc-pcomplete"))
        ((string= req "erc-pcomplete")
@@ -1891,6 +1903,7 @@
 	(old-buffer (current-buffer))
 	old-point
 	continued-session)
+    (when connect (run-hook-with-args 'erc-before-connect server port nick))
     (erc-update-modules)
     (set-buffer buffer)
     (setq old-point (point))
@@ -2104,8 +2117,6 @@
 `erc-compute-port', `erc-compute-nick' and `erc-compute-full-name' will
 be invoked for the values of the other parameters."
   (interactive (erc-select-read-args))
-
-  (run-hook-with-args 'erc-before-connect server port nick)
   (erc-open server port nick full-name t password))
 
 (defalias 'erc-select 'erc)
@@ -4300,8 +4311,10 @@
   nil)
 
 (defun erc-process-away (proc away-p)
-  ;; FIXME: This docstring is AWFUL -- Lawrence 2004-01-08
-  "Process the user being away, or returning from an away break."
+  "Toggle the away status of the user depending on the value of AWAY-P.
+
+If nil, set the user as away.
+If non-nil, return from being away."
   (let ((sessionbuf (process-buffer proc)))
     (when sessionbuf
       (with-current-buffer sessionbuf
@@ -4881,6 +4894,9 @@
    erc-input-marker
    (erc-end-of-input-line)))
 
+(defvar erc-command-regexp "^/\\([A-Za-z]+\\)\\(\\s-+.*\\|\\s-*\\)$"
+  "Regular expression used for matching commands in ERC.")
+
 (defun erc-send-input (input)
   "Treat INPUT as typed in by the user. It is assumed that the input
 and the prompt is already deleted.
@@ -4902,7 +4918,7 @@
       (run-hook-with-args 'erc-send-pre-hook input)
       (when erc-send-this
 	(if (or (string-match "\n" str)
-		(not (char-equal (aref str 0) ?/)))
+		(not (string-match erc-command-regexp str)))
 	    (mapc
 	     (lambda (line)
 	       (mapc
@@ -4967,7 +4983,7 @@
   "Extract command and args from the input LINE.
 If no command was given, return nil.  If command matches, return a
 list of the form: (command args) where both elements are strings."
-  (when (string-match "^/\\([A-Za-z]+\\)\\(\\s-+.*\\|\\s-*\\)$" line)
+  (when (string-match erc-command-regexp line)
     (let* ((cmd (erc-command-symbol (match-string 1 line)))
 	   ;; note: return is nil, we apply this simply for side effects
 	   (canon-defun (while (and cmd (symbolp (symbol-function cmd)))
@@ -5406,7 +5422,7 @@
   (erc-log (format "login: nick: %s, user: %s %s %s :%s"
 		   (erc-current-nick)
 		   (user-login-name)
-		   (system-name)
+		   (or erc-system-name (system-name))
 		   erc-session-server
 		   erc-session-user-full-name))
   (if erc-session-password
@@ -5655,6 +5671,7 @@
 
 The following characters are replaced:
 %a: String indicating away status or \"\" if you are not away
+%l: The estimated lag time to the server
 %m: The modes of the channel
 %n: The current nick name
 %o: The topic of the channel
@@ -5666,9 +5683,9 @@
   :group 'erc-mode-line-and-header
   :type 'string)
 
-(defcustom erc-header-line-format "[IRC] %n on %t %m %o"
+(defcustom erc-header-line-format "%n on %t (%m,%l) %o"
   "A string to be formatted and shown in the header-line in `erc-mode'.
-Only used in Emacs 21.
+Only used starting in Emacs 21.
 
 See `erc-mode-line-format' for which characters are can be used."
   :group 'erc-mode-line-and-header
@@ -5758,33 +5775,37 @@
       "")))
 
 (defun erc-format-channel-modes ()
-  "Return the current channel's modes and the estimated lag."
+  "Return the current channel's modes."
+  (concat (apply 'concat
+		 "+" erc-channel-modes)
+	  (cond ((and erc-channel-user-limit erc-channel-key)
+		 (if erc-show-channel-key-p
+		     (format "lk %.0f %s" erc-channel-user-limit
+			     erc-channel-key)
+		   (format "kl %.0f" erc-channel-user-limit)))
+		(erc-channel-user-limit
+		 ;; Emacs has no bignums
+		 (format "l %.0f" erc-channel-user-limit))
+		(erc-channel-key
+		 (if erc-show-channel-key-p
+		     (format "k %s" erc-channel-key)
+		   "k"))
+		(t nil))))
+
+(defun erc-format-lag-time ()
+  "Return the estimated lag time to server, `erc-server-lag'."
   (let ((lag (when (erc-server-buffer-live-p)
 	       (with-current-buffer (process-buffer erc-server-process)
 		 erc-server-lag))))
-    (concat (apply 'concat
-		   "(+" erc-channel-modes)
-	    (cond ((and erc-channel-user-limit erc-channel-key)
-		   (if erc-show-channel-key-p
-		       (format "lk %.0f %s" erc-channel-user-limit
-			       erc-channel-key)
-		     (format "kl %.0f" erc-channel-user-limit)))
-		  (erc-channel-user-limit
-		   ;; Emacs has no bignums
-		   (format "l %.0f" erc-channel-user-limit))
-		  (erc-channel-key
-		   (if erc-show-channel-key-p
-		       (format "k %s" erc-channel-key)
-		     "k"))
-		  (t ""))
-	    (if lag (format ",lag:%.0f" lag) "")
-	    ")")))
+    (cond (lag (format "lag:%.0f" lag))
+	  (t ""))))
 
 (defun erc-update-mode-line-buffer (buffer)
   "Update the mode line in a single ERC buffer BUFFER."
   (with-current-buffer buffer
     (let ((spec (format-spec-make
 		 ?a (erc-format-away-status)
+		 ?l (erc-format-lag-time)
 		 ?m (erc-format-channel-modes)
 		 ?n (or (erc-current-nick) "")
 		 ?o (erc-controls-strip erc-channel-topic)
@@ -5831,7 +5852,10 @@
 			      (erc-propertize header 'help-echo help-echo
 					      'face face)
 			    (erc-propertize header 'help-echo help-echo))))))
-		(t (setq header-line-format header))))))
+		(t (setq header-line-format
+			 (if face
+			     (erc-propertize header 'face face)
+			   header)))))))
     (if (featurep 'xemacs)
 	(redraw-modeline)
       (force-mode-line-update))))
@@ -6185,6 +6209,10 @@
 
 ;;; Dealing with `erc-parsed'
 
+(defun erc-find-parsed-property ()
+  "Find the next occurrence of the `erc-parsed' text property."
+  (text-property-not-all (point-min) (point-max) 'erc-parsed nil))
+
 (defun erc-get-parsed-vector (point)
   "Return the whole parsed vector on POINT."
   (get-text-property point 'erc-parsed))