changeset 75260:864a6f6648e2

Merge from erc--main--0 Backport additional functions and macros that erc-capab.el needs. Revision: emacs@sv.gnu.org/emacs--devo--0--patch-600 Creator: Michael Olson <mwolson@gnu.org>
author Miles Bader <miles@gnu.org>
date Wed, 17 Jan 2007 18:17:35 +0000
parents f45c5edf0be4
children c20709d49a63
files lisp/erc/ChangeLog lisp/erc/erc.el
diffstat 2 files changed, 29 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/erc/ChangeLog	Wed Jan 17 18:17:25 2007 +0000
+++ b/lisp/erc/ChangeLog	Wed Jan 17 18:17:35 2007 +0000
@@ -387,6 +387,16 @@
 	(erc-make-mode-line-buffer-name): Add help-echo and mouse-face
 	properties to channel name.
 
+2006-08-20  Michael Olson  <mwolson@gnu.org>
+
+	* erc.el (erc-with-server-buffer): New macro that switches to the
+	current ERC server buffer and runs some code.  If no server buffer
+	is available, return nil.  This is a useful way to access
+	variables in the server buffer.
+	(erc-open-server-buffer-p): New function that returns non-nil if
+	the given buffer is an ERC server buffer that has an open IRC
+	process.
+
 2006-08-14  Diane Murray  <disumu@x3y2z1.net>
 
 	* erc-menu.el: Updated copyright years.  Removed EmacsWiki URL.
--- a/lisp/erc/erc.el	Wed Jan 17 18:17:25 2007 +0000
+++ b/lisp/erc/erc.el	Wed Jan 17 18:17:35 2007 +0000
@@ -355,6 +355,17 @@
 	      (cdr (assq (aref s (match-beginning 0)) c)))))
     s))
 
+(defmacro erc-with-server-buffer (&rest body)
+  "Execute BODY in the current ERC server buffer.
+If no server buffer exists, return nil."
+  (let ((buffer (make-symbol "buffer")))
+    `(let ((,buffer (erc-server-buffer)))
+       (when (buffer-live-p ,buffer)
+	 (with-current-buffer ,buffer
+	   ,@body)))))
+(put 'erc-with-server-buffer 'lisp-indent-function 0)
+(put 'erc-with-server-buffer 'edebug-form-spec '(body))
+
 (defstruct (erc-server-user (:type vector) :named)
   ;; User data
   nickname host login full-name info
@@ -1339,6 +1350,14 @@
     (and (eq major-mode 'erc-mode)
 	 (null (erc-default-target)))))
 
+(defun erc-open-server-buffer-p (&optional buffer)
+  "Return non-nil if argument BUFFER is an ERC server buffer that
+has an open IRC process.
+
+If BUFFER is nil, the current buffer is used."
+  (and (erc-server-buffer-p)
+       (erc-server-process-alive)))
+
 (defun erc-query-buffer-p (&optional buffer)
   "Return non-nil if BUFFER is an ERC query buffer.
 If BUFFER is nil, the current buffer is used."