]> code.delx.au - gnu-emacs/blobdiff - lisp/erc/erc.el
erc.el (erc-rename-buffers): Use defcustom instead of defvar.
[gnu-emacs] / lisp / erc / erc.el
index 8d2ea62b2311f0053444c95fe6526747b2007e16..2825481c2a1d58081288d5ac0acd936cf1915076 100644 (file)
@@ -9,10 +9,10 @@
 ;;               Andreas Fuchs (afs@void.at)
 ;;               Gergely Nagy (algernon@midgard.debian.net)
 ;;               David Edmondson (dme@dme.org)
-;;               Kelvin White <kelvin.white77@gmail.com>
+;;               Kelvin White (kwhite@gnu.org)
 ;; Maintainer: emacs-devel@gnu.org
 ;; Keywords: IRC, chat, client, Internet
-;; Version: 5.3
+
 
 ;; This file is part of GNU Emacs.
 
 ;;; History:
 ;;
 
-;;; Code:
-
-(defconst erc-version-string "Version 5.3"
+(defconst erc-version-string (format "\C-bERC\C-b (IRC client for Emacs %s)" emacs-version)
   "ERC version.  This is used by function `erc-version'.")
 
+;;; Code:
+
 (eval-when-compile (require 'cl-lib))
 (require 'font-lock)
 (require 'pp)
@@ -196,6 +196,11 @@ parameters and authentication."
   :set (lambda (sym val)
          (set sym (if (functionp val) (funcall val) val))))
 
+(defcustom erc-rename-buffers nil
+  "When this is set to t, buffers will be renamed to network name if available"
+  :group 'erc
+  :type 'boolean)
+
 (defvar erc-password nil
   "Password to use when authenticating to an IRC server.
 It is not strictly necessary to provide this, since ERC will
@@ -2797,7 +2802,8 @@ VALUE is computed by evaluating the rest of LINE in Lisp."
                                (concat "\n" (pp-to-string val))
                              (format " %S\n" val)))))
                (apropos-internal "^erc-" 'custom-variable-p))))
-     (current-buffer)) t)
+     (current-buffer))
+    t)
    (t nil)))
 (defalias 'erc-cmd-VAR 'erc-cmd-SET)
 (defalias 'erc-cmd-VARIABLE 'erc-cmd-SET)
@@ -3379,14 +3385,16 @@ If USER is omitted, close the current query buffer if one exists
       (signal 'wrong-number-of-arguments ""))))
 (defalias 'erc-cmd-Q 'erc-cmd-QUERY)
 
+(defun erc-quit/part-reason-default ()
+  "Default quit/part message."
+  (format "\C-bERC\C-b (IRC client for Emacs %s)" emacs-version))
+
+
 (defun erc-quit-reason-normal (&optional s)
   "Normal quit message.
 
 If S is non-nil, it will be used as the quit reason."
-  (or s
-      (format "\C-bERC\C-b %s (IRC client for Emacs)"; - \C-b%s\C-b"
-              erc-version-string) ; erc-official-location)
-      ))
+  (or s (erc-quit/part-reason-default)))
 
 (defun erc-quit-reason-zippy (&optional s)
   "Zippy quit message.
@@ -3395,7 +3403,7 @@ If S is non-nil, it will be used as the quit reason."
   (or s
       (if (fboundp 'yow)
           (erc-replace-regexp-in-string "\n" "" (yow))
-        (erc-quit-reason-normal))))
+        (erc-quit/part-reason-default))))
 
 (make-obsolete 'erc-quit-reason-zippy "it will be removed." "24.4")
 
@@ -3408,16 +3416,13 @@ If S is non-nil, it will be used as the quit reason."
      ((functionp res) (funcall res))
      ((stringp res) res)
      (s s)
-     (t (erc-quit-reason-normal)))))
+     (t (erc-quit/part-reason-default)))))
 
 (defun erc-part-reason-normal (&optional s)
   "Normal part message.
 
-If S is non-nil, it will be used as the quit reason."
-  (or s
-      (format "\C-bERC\C-b %s (IRC client for Emacs)"; - \C-b%s\C-b"
-              erc-version-string) ; erc-official-location)
-      ))
+If S is non-nil, it will be used as the part reason."
+  (or s (erc-quit/part-reason-default)))
 
 (defun erc-part-reason-zippy (&optional s)
   "Zippy part message.
@@ -3426,7 +3431,7 @@ If S is non-nil, it will be used as the quit reason."
   (or s
       (if (fboundp 'yow)
           (erc-replace-regexp-in-string "\n" "" (yow))
-        (erc-part-reason-normal))))
+        (erc-quit/part-reason-default))))
 
 (make-obsolete 'erc-part-reason-zippy "it will be removed." "24.4")
 
@@ -3439,7 +3444,7 @@ If S is non-nil, it will be used as the quit reason."
      ((functionp res) (funcall res))
      ((stringp res) res)
      (s s)
-     (t (erc-part-reason-normal)))))
+     (t (erc-quit/part-reason-default)))))
 
 (defun erc-cmd-QUIT (reason)
   "Disconnect from the current server.
@@ -3533,8 +3538,7 @@ the message given by REASON."
 
 (defun erc-cmd-SV ()
   "Say the current ERC and Emacs version into channel."
-  (erc-send-message (format "I'm using ERC %s with %s %s (%s%s) of %s."
-                            erc-version-string
+  (erc-send-message (format "I'm using ERC with %s %s (%s%s) of %s."
                             (if (featurep 'xemacs) "XEmacs" "GNU Emacs")
                             emacs-version
                             system-configuration
@@ -3874,7 +3878,8 @@ If FACE is non-nil, it will be used to propertize the prompt.  If it is nil,
     (insert (read-from-minibuffer "Message: "
                                   (string (if (featurep 'xemacs)
                                               last-command-char
-                                            last-command-event)) read-map))
+                                            last-command-event))
+                                 read-map))
     (erc-send-current-line)))
 
 (defvar erc-action-history-list ()
@@ -4106,10 +4111,12 @@ E.g. \"Read error to Nick [user@some.host]: 110\" would be shortened to
         host (regexp-quote host))
   (or (when (string-match (concat "^\\(Read error\\) to "
                                   nick "\\[" host "\\]: "
-                                  "\\(.+\\)$") reason)
+                                  "\\(.+\\)$")
+                         reason)
         (concat (match-string 1 reason) ": " (match-string 2 reason)))
       (when (string-match (concat "^\\(Ping timeout\\) for "
-                                  nick "\\[" host "\\]$") reason)
+                                  nick "\\[" host "\\]$")
+                         reason)
         (match-string 1 reason))
       reason))
 
@@ -4223,10 +4230,7 @@ and as second argument the event parsed as a vector."
 (defun erc-format-nick (&optional user _channel-data)
   "Return the nickname of USER.
 See also `erc-format-nick-function'."
-  (let ((nick (erc-server-user-nickname user)))
-    (concat (erc-propertize
-             (erc-get-user-mode-prefix nick)
-             'face 'erc-nick-prefix-face) nick)))
+  (when user (erc-server-user-nickname user)))
 
 (defun erc-get-user-mode-prefix (user)
   (when user
@@ -4252,7 +4256,8 @@ also `erc-format-nick-function'."
     (let ((nick (erc-server-user-nickname user)))
       (concat (erc-propertize
                (erc-get-user-mode-prefix nick)
-               'face 'erc-nick-prefix-face) nick nick))))
+               'face 'erc-nick-prefix-face)
+             nick))))
 
 (defun erc-format-my-nick ()
   "Return the beginning of this user's message, correctly propertized."
@@ -4588,8 +4593,8 @@ See also `erc-display-message'."
   (unless erc-disable-ctcp-replies
     (erc-send-ctcp-notice
      nick (format
-           "VERSION \C-bERC\C-b %s - an IRC client for emacs (\C-b%s\C-b)"
-           erc-version-string
+           "VERSION \C-bERC\C-b - an IRC client for Emacs %s (\C-b%s\C-b)"
+           emacs-version
            erc-official-location)))
   nil)
 
@@ -4772,24 +4777,16 @@ channel."
         (let ((updatep t))
           (setq name item op 'off voice 'off halfop 'off admin 'off owner 'off)
           (if (rassq (elt item 0) prefix)
-              (cond ((= (length item) 1)
-                     (setq updatep nil))
-                    ((eq (elt item 0) voice-ch)
-                     (setq name (substring item 1)
-                           voice 'on))
-                    ((eq (elt item 0) hop-ch)
-                     (setq name (substring item 1)
-                           halfop 'on))
-                    ((eq (elt item 0) op-ch)
-                     (setq name (substring item 1)
-                           op 'on))
-                    ((eq (elt item 0) adm-ch)
-                     (setq name (substring item 1)
-                           admin 'on))
-                    ((eq (elt item 0) own-ch)
-                     (setq name (substring item 1)
-                           owner 'on))
-                    (t (setq name (substring item 1)))))
+              (if (= (length item) 1)
+                 (setq updatep nil)
+               (setq name (substring item 1))
+               (setf (pcase (aref item 0)
+                       ((pred (eq voice-ch)) voice)
+                       ((pred (eq hop-ch))   halfop)
+                       ((pred (eq op-ch))    op)
+                       ((pred (eq adm-ch))   admin)
+                       ((pred (eq own-ch))   owner))
+                     'on)))
           (when updatep
             (puthash (erc-downcase name) t
                      erc-channel-new-member-names)
@@ -5379,8 +5376,6 @@ This returns non-nil only if we actually send anything."
                 (or (and erc-flood-protect (erc-split-line line))
                     (list line))))
              (split-string str "\n"))
-          ;; Insert the prompt along with the command.
-          (erc-display-command str)
           (erc-process-input-line (concat str "\n") t nil))
         t)))))
 
@@ -6088,7 +6083,7 @@ entry of `channel-members'."
                  nick login host
                  (if full-name (format " (%s)" full-name) "")
                  (if (or voice halfop op admin owner)
-                     (format " and is +%s%s on %s"
+                     (format " and is +%s%s%s%s%s on %s"
                              (if voice "v" "")
                              (if halfop "h" "")
                              (if op "o" "")
@@ -6235,7 +6230,11 @@ shortened server name instead."
     (cond ((erc-default-target)
            (concat (erc-string-no-properties (erc-default-target))
                    "@" network-name))
-          (network-name network-name)
+          ((and network-name
+                (not (get-buffer network-name)))
+           (when erc-rename-buffers
+            (rename-buffer network-name))
+           network-name)
           (t (buffer-name (current-buffer))))))
 
 (defun erc-format-away-status ()
@@ -6374,7 +6373,7 @@ P may be an integer or a service name."
 If optional argument HERE is non-nil, insert version number at point."
   (interactive "P")
   (let ((version-string
-         (format "ERC %s (GNU Emacs %s)" erc-version-string emacs-version)))
+         (format "ERC (IRC client for Emacs %s)" emacs-version)))
     (if here
         (insert version-string)
       (if (called-interactively-p 'interactive)