Mercurial > emacs
comparison lisp/erc/erc-compat.el @ 87952:b8f89dd3680d
ERC: Sync version 5.3, release candidate 1.
author | Michael Olson <mwolson@gnu.org> |
---|---|
date | Fri, 25 Jan 2008 03:28:10 +0000 |
parents | 107ccd98fa12 |
children | 2a734255bcc7 |
comparison
equal
deleted
inserted
replaced
87951:0c208f9e2445 | 87952:b8f89dd3680d |
---|---|
86 (defalias 'erc-with-selected-window 'with-selected-window) | 86 (defalias 'erc-with-selected-window 'with-selected-window) |
87 (defalias 'erc-cancel-timer 'cancel-timer) | 87 (defalias 'erc-cancel-timer 'cancel-timer) |
88 (defalias 'erc-make-obsolete 'make-obsolete) | 88 (defalias 'erc-make-obsolete 'make-obsolete) |
89 (defalias 'erc-make-obsolete-variable 'make-obsolete-variable) | 89 (defalias 'erc-make-obsolete-variable 'make-obsolete-variable) |
90 | 90 |
91 ;; Provde an equivalent of `assert', based on the code from cl-macs.el | |
92 (defun erc-const-expr-p (x) | |
93 (cond ((consp x) | |
94 (or (eq (car x) 'quote) | |
95 (and (memq (car x) '(function function*)) | |
96 (or (symbolp (nth 1 x)) | |
97 (and (eq (and (consp (nth 1 x)) | |
98 (car (nth 1 x))) 'lambda) 'func))))) | |
99 ((symbolp x) (and (memq x '(nil t)) t)) | |
100 (t t))) | |
101 | |
102 (put 'erc-assertion-failed 'error-conditions '(error)) | |
103 (put 'erc-assertion-failed 'error-message "Assertion failed") | |
104 | |
105 (defun erc-list* (arg &rest rest) | |
106 "Return a new list with specified args as elements, cons'd to last arg. | |
107 Thus, `(list* A B C D)' is equivalent to `(nconc (list A B C) D)', or to | |
108 `(cons A (cons B (cons C D)))'." | |
109 (cond ((not rest) arg) | |
110 ((not (cdr rest)) (cons arg (car rest))) | |
111 (t (let* ((n (length rest)) | |
112 (copy (copy-sequence rest)) | |
113 (last (nthcdr (- n 2) copy))) | |
114 (setcdr last (car (cdr last))) | |
115 (cons arg copy))))) | |
116 | |
117 (defmacro erc-assert (form &optional show-args string &rest args) | |
118 "Verify that FORM returns non-nil; signal an error if not. | |
119 Second arg SHOW-ARGS means to include arguments of FORM in message. | |
120 Other args STRING and ARGS... are arguments to be passed to `error'. | |
121 They are not evaluated unless the assertion fails. If STRING is | |
122 omitted, a default message listing FORM itself is used." | |
123 (let ((sargs | |
124 (and show-args | |
125 (delq nil (mapcar | |
126 (function | |
127 (lambda (x) | |
128 (and (not (erc-const-expr-p x)) x))) | |
129 (cdr form)))))) | |
130 (list 'progn | |
131 (list 'or form | |
132 (if string | |
133 (erc-list* 'error string (append sargs args)) | |
134 (list 'signal '(quote erc-assertion-failed) | |
135 (erc-list* 'list (list 'quote form) sargs)))) | |
136 nil))) | |
137 | |
138 ;; Provide a simpler replacement for `member-if' | 91 ;; Provide a simpler replacement for `member-if' |
139 (defun erc-member-if (predicate list) | 92 (defun erc-member-if (predicate list) |
140 "Find the first item satisfying PREDICATE in LIST. | 93 "Find the first item satisfying PREDICATE in LIST. |
141 Return the sublist of LIST whose car matches." | 94 Return the sublist of LIST whose car matches." |
142 (let ((ptr list)) | 95 (let ((ptr list)) |