1 ;;; erc-compat.el --- ERC compatibility code for XEmacs
3 ;; Copyright (C) 2002, 2003, 2005, 2006, 2007, 2008 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, or (at your option)
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; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 ;; Boston, MA 02110-1301, USA.
27 ;; This mostly defines stuff that cannot be worked around easily.
31 (require 'format-spec
)
33 ;;;###autoload (autoload 'erc-define-minor-mode "erc-compat")
34 (defalias 'erc-define-minor-mode
'define-minor-mode
)
35 (put 'erc-define-minor-mode
'edebug-form-spec
'define-minor-mode
)
37 (defun erc-decode-coding-string (s coding-system
)
38 "Decode S using CODING-SYSTEM."
39 (decode-coding-string s coding-system t
))
41 (defun erc-encode-coding-string (s coding-system
)
42 "Encode S using CODING-SYSTEM.
43 Return the same string, if the encoding operation is trivial.
44 See `erc-encoding-coding-alist'."
45 (encode-coding-string s coding-system t
))
47 (defalias 'erc-propertize
'propertize
)
48 (defalias 'erc-view-mode-enter
'view-mode-enter
)
49 (defalias 'erc-function-arglist
'help-function-arglist
)
50 (defalias 'erc-delete-dups
'delete-dups
)
51 (defalias 'erc-replace-regexp-in-string
'replace-regexp-in-string
)
53 (defun erc-set-write-file-functions (new-val)
54 (set (make-local-variable 'write-file-functions
) new-val
))
56 (defvar erc-emacs-build-time
57 (if (stringp emacs-build-time
)
59 (format-time-string "%Y-%m-%d" emacs-build-time
))
60 "Time at which Emacs was dumped out.")
62 ;; Emacs 21 and XEmacs do not have user-emacs-directory, but XEmacs
63 ;; has user-init-directory.
64 (defvar erc-user-emacs-directory
65 (cond ((boundp 'user-emacs-directory
)
67 ((boundp 'user-init-directory
)
70 "Directory beneath which additional per-user Emacs-specific files
72 Note that this should end with a directory separator.")
74 ;; XEmacs' `replace-match' does not replace matching subexpressions in strings.
75 (defun erc-replace-match-subexpression-in-string
76 (newtext string match subexp start
&optional fixedcase literal
)
77 "Replace the subexpression SUBEXP of the last match in STRING with NEWTEXT.
78 MATCH is the text which matched the subexpression (see `match-string').
79 START is the beginning position of the last match (see `match-beginning').
80 See `replace-match' for explanations of FIXEDCASE and LITERAL."
81 (cond ((featurep 'xemacs
)
82 (string-match match string start
)
83 (replace-match newtext fixedcase literal string
))
84 (t (replace-match newtext fixedcase literal string subexp
))))
86 (defalias 'erc-with-selected-window
'with-selected-window
)
87 (defalias 'erc-cancel-timer
'cancel-timer
)
88 (defalias 'erc-make-obsolete
'make-obsolete
)
89 (defalias 'erc-make-obsolete-variable
'make-obsolete-variable
)
91 ;; Provide a simpler replacement for `member-if'
92 (defun erc-member-if (predicate list
)
93 "Find the first item satisfying PREDICATE in LIST.
94 Return the sublist of LIST whose car matches."
98 (when (funcall predicate
(car ptr
))
100 (setq ptr
(cdr ptr
))))))
102 ;; Provide a simpler replacement for `delete-if'
103 (defun erc-delete-if (predicate seq
)
104 "Remove all items satisfying PREDICATE in SEQ.
105 This is a destructive function: it reuses the storage of SEQ
108 (while (when (funcall predicate
(car seq
))
109 (setq seq
(cdr seq
))))
114 (when (funcall predicate
(car next
))
115 (setcdr ptr
(if (consp next
)
119 (setq next
(cdr ptr
))))
122 ;; Provide a simpler replacement for `remove-if-not'
123 (defun erc-remove-if-not (predicate seq
)
124 "Remove all items not satisfying PREDICATE in SEQ.
125 This is a non-destructive function; it makes a copy of SEQ to
126 avoid corrupting the original SEQ."
129 (when (funcall predicate el
)
130 (setq newseq
(cons el newseq
))))
133 ;; Copied from cl-extra.el
134 (defun erc-subseq (seq start
&optional end
)
135 "Return the subsequence of SEQ from START to END.
136 If END is omitted, it defaults to the length of the sequence.
137 If START or END is negative, it counts from the end."
138 (if (stringp seq
) (substring seq start end
)
140 (and end
(< end
0) (setq end
(+ end
(setq len
(length seq
)))))
141 (if (< start
0) (setq start
(+ start
(or len
(setq len
(length seq
))))))
143 (if (> start
0) (setq seq
(nthcdr start seq
)))
146 (while (>= (setq end
(1- end
)) start
)
147 (push (pop seq
) res
))
149 (copy-sequence seq
)))
151 (or end
(setq end
(or len
(length seq
))))
152 (let ((res (make-vector (max (- end start
) 0) nil
))
155 (aset res i
(aref seq start
))
156 (setq i
(1+ i
) start
(1+ start
)))
159 (provide 'erc-compat
)
161 ;;; erc-compat.el ends here
164 ;; indent-tabs-mode: t
168 ;; arch-tag: 8948ffe0-aff8-4ad8-a196-368ebbfd58ff