Commits

Anonymous committed 956f257

Don't use #'multiple-value-bind inappropriately, ERC

Comments (0)

Files changed (5)

+2009-08-13  Aidan Kehoe  <kehoea@parhasard.net>
+
+	* erc-compat.el (erc-destructuring-bind): New macro, like
+	#'destructuring-bind, but no error if EXPR doesn't give a result
+	fitting into ARGS. 
+	* erc-backend.el:
+	Use #'destructuring-bind instead of #'multiple-value-bind where we
+	know the result of EXPR will fit ARGS; use
+	#'erc-destructuring-bind where we know it won't. 
+	* erc-list.el (erc-chanlist-322):
+	Use #'erc-destructuring-bind, not #'multiple-value-bind. 
+	* erc.el (erc-banlist-store):
+	Use #'erc-destructuring-bind, not #'multiple-value-bind. 
+
 2009-07-22  Aidan Kehoe  <kehoea@parhasard.net>
 
 	* erc-log.el (erc-log-setup-logging): 
   nil
   (let ((target (first (erc-response.command-args parsed)))
         (chnl (erc-response.contents parsed)))
-    (multiple-value-bind (nick login host)
+    (destructuring-bind (nick login host)
         (erc-parse-user (erc-response.sender parsed))
       (setq erc-invitation chnl)
       (when (string= target (erc-current-nick))
   nil
   (let ((chnl (erc-response.contents parsed))
         (buffer nil))
-    (multiple-value-bind (nick login host)
+    (destructuring-bind (nick login host)
         (erc-parse-user (erc-response.sender parsed))
       ;; strip the stupid combined JOIN facility (IRC 2.9)
       (if (string-match "^\\(.*\\)?\^g.*$" chnl)
          (tgt (second (erc-response.command-args parsed)))
          (reason (erc-trim-string (erc-response.contents parsed)))
          (buffer (erc-get-buffer ch proc)))
-    (multiple-value-bind (nick login host)
+    (destructuring-bind (nick login host)
         (erc-parse-user (erc-response.sender parsed))
       (erc-remove-channel-member buffer tgt)
       (cond
   (let ((tgt (first (erc-response.command-args parsed)))
         (mode (mapconcat 'identity (cdr (erc-response.command-args parsed))
                          " ")))
-    (multiple-value-bind (nick login host)
+    (destructuring-bind (nick login host)
         (erc-parse-user (erc-response.sender parsed))
       (erc-log (format "MODE: %s -> %s: %s" nick tgt mode))
       ;; dirty hack
   "Handle nick change messages." nil
   (let ((nn (erc-response.contents parsed))
         bufs)
-    (multiple-value-bind (nick login host)
+    (destructuring-bind (nick login host)
         (erc-parse-user (erc-response.sender parsed))
       (setq bufs (erc-buffer-list-with-nick nick proc))
       (erc-log (format "NICK: %s -> %s" nick nn))
   (let* ((chnl (first (erc-response.command-args parsed)))
          (reason (erc-trim-string (erc-response.contents parsed)))
          (buffer (erc-get-buffer chnl proc)))
-    (multiple-value-bind (nick login host)
+    (destructuring-bind (nick login host)
         (erc-parse-user (erc-response.sender parsed))
       (erc-remove-channel-member buffer nick)
       (erc-display-message parsed 'notice buffer
   nil nil
   (let ((reason (erc-response.contents parsed))
         bufs)
-    (multiple-value-bind (nick login host)
+    (destructuring-bind (nick login host)
         (erc-parse-user (erc-response.sender parsed))
       (setq bufs (erc-buffer-list-with-nick nick proc))
       (erc-remove-user nick)
   (let* ((ch (first (erc-response.command-args parsed)))
          (topic (erc-trim-string (erc-response.contents parsed)))
          (time (format-time-string "%T %m/%d/%y" (current-time))))
-    (multiple-value-bind (nick login host)
+    (destructuring-bind (nick login host)
         (erc-parse-user (erc-response.sender parsed))
       (erc-update-channel-member ch nick nick nil nil nil host login)
       (erc-update-channel-topic ch (format "%s\C-o (%s, %s)" topic nick time))
 (define-erc-response-handler (WALLOPS)
   nil nil
   (let ((message (erc-response.contents parsed)))
-    (multiple-value-bind (nick login host)
+    (destructuring-bind (nick login host)
         (erc-parse-user (erc-response.sender parsed))
       (erc-display-message
        parsed 'notice nil
 
 (define-erc-response-handler (004)
   nil nil
-  (multiple-value-bind (server-name server-version)
+  (erc-destructuring-bind (server-name server-version)
       (cdr (erc-response.command-args parsed))
     (setq erc-server-version server-version)
     (setq erc-server-announced-name server-name)
   "WHOIS/WHOWAS notices." nil
   (let ((fname (erc-response.contents parsed))
         (catalog-entry (intern (format "s%s" (erc-response.command parsed)))))
-    (multiple-value-bind (nick user host)
+    (erc-destructuring-bind (nick user host)
         (cdr (erc-response.command-args parsed))
       (erc-update-user-nick nick nick host nil fname user)
       (erc-display-message
 
 (define-erc-response-handler (312)
   nil nil
-  (multiple-value-bind (nick server-host)
+  (erc-destructuring-bind (nick server-host)
       (cdr (erc-response.command-args parsed))
     (erc-display-message
      parsed 'notice 'active 's312
 
 (define-erc-response-handler (317)
   "IDLE notice." nil
-  (multiple-value-bind (nick seconds-idle on-since time)
+  (erc-destructuring-bind (nick seconds-idle on-since time)
       (cdr (erc-response.command-args parsed))
     (setq time (when on-since
                  (format-time-string "%T %Y/%m/%d"
 (define-erc-response-handler (322)
   "LIST notice." nil
   (let ((topic (erc-response.contents parsed)))
-    (multiple-value-bind (channel num-users)
+    (erc-destructuring-bind (channel num-users)
         (cdr (erc-response.command-args parsed))
       (add-to-list 'erc-channel-list (list channel))
       (erc-update-channel-topic channel topic)
 (define-erc-response-handler (333)
   ;; Who set the topic, and when
   nil nil
-  (multiple-value-bind (channel nick time)
+  (erc-destructuring-bind (channel nick time)
       (cdr (erc-response.command-args parsed))
     (setq time (format-time-string "%T %Y/%m/%d"
                                    (erc-string-to-emacs-time time)))
 (define-erc-response-handler (341)
   "Let user know when an INVITE attempt has been sent successfully."
   nil
-  (multiple-value-bind (nick channel)
+  (erc-destructuring-bind (nick channel)
       (cdr (erc-response.command-args parsed))
     (erc-display-message parsed 'notice (erc-get-buffer channel proc)
                          's341 ?n nick ?c channel)))
 
 (define-erc-response-handler (352)
   "WHO notice." nil
-  (multiple-value-bind (channel user host server nick away-flag)
+  (erc-destructuring-bind (channel user host server nick away-flag)
       (cdr (erc-response.command-args parsed))
     (let ((full-name (erc-response.contents parsed))
           hopcount)
 
 (define-erc-response-handler (367)
   "Channel ban list entries" nil
-  (multiple-value-bind (channel banmask setter time)
+  (erc-destructuring-bind (channel banmask setter time)
       (cdr (erc-response.command-args parsed))
     (erc-display-message parsed 'notice 'active 's367
                          ?c channel
   ;; FIXME: Yet more magic numbers in original code, I'm guessing this
   ;; command takes two arguments, and doesn't have any "contents". --
   ;; Lawrence 2004/05/10
-  (multiple-value-bind (from to)
+  (erc-destructuring-bind (from to)
       (cdr (erc-response.command-args parsed))
     (erc-display-message parsed 'notice 'active
                          's379 ?c from ?f to)))
 		 (setq i (1+ i) start (1+ start)))
 	       res))))))
 
+(defmacro erc-destructuring-bind (args expr &rest body)
+  "Like `destructuring-bind', but don't error if ARGS don't fit EXPR."
+  `(loop for ,args = ,expr return (progn ,@body)))
+
 (provide 'erc-compat)
 
 ;;; erc-compat.el ends here
 
 The message carries information about one channel for the LIST
 command."
-  (multiple-value-bind (channel num-users)
+  (erc-destructuring-bind (channel num-users)
       (cdr (erc-response.command-args parsed))
     (let ((topic (erc-response.contents parsed)))
       (with-current-buffer erc-chanlist-buffer
 
 (defun erc-banlist-store (proc parsed)
   "Record ban entries for a channel."
-  (multiple-value-bind (channel mask whoset)
+  (erc-destructuring-bind (channel mask whoset)
       (cdr (erc-response.command-args parsed))
     ;; Determine to which buffer the message corresponds
     (let ((buffer (erc-get-buffer channel proc)))