1 ;;; erc-compat.el --- ERC compatibility code for XEmacs
3 ;; Copyright (C) 2002-2003, 2005-2011 Free Software Foundation, Inc.
5 ;; Author: Alex Schroeder <alex@gnu.org>
6 ;; URL: http://www.emacswiki.org/cgi-bin/wiki/ERC
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;; This mostly defines stuff that cannot be worked around easily.
29 (require 'format-spec
)
31 ;;;###autoload (autoload 'erc-define-minor-mode "erc-compat")
32 (defalias 'erc-define-minor-mode
'define-minor-mode
)
33 (put 'erc-define-minor-mode
'edebug-form-spec
'define-minor-mode
)
35 (defun erc-decode-coding-string (s coding-system
)
36 "Decode S using CODING-SYSTEM."
37 (decode-coding-string s coding-system t
))
39 (defun erc-encode-coding-string (s coding-system
)
40 "Encode S using CODING-SYSTEM.
41 Return the same string, if the encoding operation is trivial.
42 See `erc-encoding-coding-alist'."
43 (encode-coding-string s coding-system t
))
45 (defalias 'erc-propertize
'propertize
)
46 (defalias 'erc-view-mode-enter
'view-mode-enter
)
47 (autoload 'help-function-arglist
"help-fns")
48 (defalias 'erc-function-arglist
'help-function-arglist
)
49 (defalias 'erc-delete-dups
'delete-dups
)
50 (defalias 'erc-replace-regexp-in-string
'replace-regexp-in-string
)
52 (defun erc-set-write-file-functions (new-val)
53 (set (make-local-variable 'write-file-functions
) new-val
))
55 (defvar erc-emacs-build-time
56 (if (stringp emacs-build-time
)
58 (format-time-string "%Y-%m-%d" emacs-build-time
))
59 "Time at which Emacs was dumped out.")
61 ;; Emacs 21 and XEmacs do not have user-emacs-directory, but XEmacs
62 ;; has user-init-directory.
63 (defvar erc-user-emacs-directory
64 (cond ((boundp 'user-emacs-directory
)
66 ((boundp 'user-init-directory
)
69 "Directory beneath which additional per-user Emacs-specific files
71 Note that this should end with a directory separator.")
73 ;; XEmacs' `replace-match' does not replace matching subexpressions in strings.
74 (defun erc-replace-match-subexpression-in-string
75 (newtext string match subexp start
&optional fixedcase literal
)
76 "Replace the subexpression SUBEXP of the last match in STRING with NEWTEXT.
77 MATCH is the text which matched the subexpression (see `match-string').
78 START is the beginning position of the last match (see `match-beginning').
79 See `replace-match' for explanations of FIXEDCASE and LITERAL."
80 (cond ((featurep 'xemacs
)
81 (string-match match string start
)
82 (replace-match newtext fixedcase literal string
))
83 (t (replace-match newtext fixedcase literal string subexp
))))
85 (defalias 'erc-with-selected-window
'with-selected-window
)
86 (defalias 'erc-cancel-timer
'cancel-timer
)
87 (defalias 'erc-make-obsolete
'make-obsolete
)
88 (defalias 'erc-make-obsolete-variable
'make-obsolete-variable
)
90 ;; Provide a simpler replacement for `member-if'
91 (defun erc-member-if (predicate list
)
92 "Find the first item satisfying PREDICATE in LIST.
93 Return the sublist of LIST whose car matches."
97 (when (funcall predicate
(car ptr
))
99 (setq ptr
(cdr ptr
))))))
101 ;; Provide a simpler replacement for `delete-if'
102 (defun erc-delete-if (predicate seq
)
103 "Remove all items satisfying PREDICATE in SEQ.
104 This is a destructive function: it reuses the storage of SEQ
107 (while (when (funcall predicate
(car seq
))
108 (setq seq
(cdr seq
))))
113 (when (funcall predicate
(car next
))
114 (setcdr ptr
(if (consp next
)
118 (setq next
(cdr ptr
))))
121 ;; Provide a simpler replacement for `remove-if-not'
122 (defun erc-remove-if-not (predicate seq
)
123 "Remove all items not satisfying PREDICATE in SEQ.
124 This is a non-destructive function; it makes a copy of SEQ to
125 avoid corrupting the original SEQ."
128 (when (funcall predicate el
)
129 (setq newseq
(cons el newseq
))))
132 ;; Copied from cl-extra.el
133 (defun erc-subseq (seq start
&optional end
)
134 "Return the subsequence of SEQ from START to END.
135 If END is omitted, it defaults to the length of the sequence.
136 If START or END is negative, it counts from the end."
137 (if (stringp seq
) (substring seq start end
)
139 (and end
(< end
0) (setq end
(+ end
(setq len
(length seq
)))))
140 (if (< start
0) (setq start
(+ start
(or len
(setq len
(length seq
))))))
142 (if (> start
0) (setq seq
(nthcdr start seq
)))
145 (while (>= (setq end
(1- end
)) start
)
146 (push (pop seq
) res
))
148 (copy-sequence seq
)))
150 (or end
(setq end
(or len
(length seq
))))
151 (let ((res (make-vector (max (- end start
) 0) nil
))
154 (aset res i
(aref seq start
))
155 (setq i
(1+ i
) start
(1+ start
)))
158 (provide 'erc-compat
)
160 ;;; erc-compat.el ends here
163 ;; indent-tabs-mode: t