]> git.eshelyaron.com Git - emacs.git/commitdiff
Merge from erc--main--0
authorMiles Bader <miles@gnu.org>
Wed, 17 Jan 2007 18:17:35 +0000 (18:17 +0000)
committerMiles Bader <miles@gnu.org>
Wed, 17 Jan 2007 18:17:35 +0000 (18:17 +0000)
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>

lisp/erc/ChangeLog
lisp/erc/erc.el

index 79ab94269baea375a039d6ad225e8f4e6950acf9..9b7b17ceec480350880dd49185ab22020e751efe 100644 (file)
        (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.
index 350a77b8210b8a52dd986fa5e30a1cb148ca1b86..927dce02d64b5138dd0439eae58608bd9c47a786 100644 (file)
@@ -355,6 +355,17 @@ nicknames with erc-server-user struct instances.")
              (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 @@ If BUFFER is nil, the current buffer is used."
     (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."