Fix last ChangeLog entry.
[emacs.git] / lisp / erc / erc-compat.el
blobca4df66d46b44490f5202dca72c9bcb7e9c948e6
1 ;;; erc-compat.el --- ERC compatibility code for XEmacs
3 ;; Copyright (C) 2002-2003, 2005-2014 Free Software Foundation, Inc.
5 ;; Author: Alex Schroeder <alex@gnu.org>
6 ;; Maintainer: emacs-devel@gnu.org
7 ;; URL: http://www.emacswiki.org/cgi-bin/wiki/ERC
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24 ;;; Commentary:
26 ;; This mostly defines stuff that cannot be worked around easily.
28 ;;; Code:
30 (require 'format-spec)
32 ;;;###autoload (autoload 'erc-define-minor-mode "erc-compat")
33 (defalias 'erc-define-minor-mode 'define-minor-mode)
34 (put 'erc-define-minor-mode 'edebug-form-spec 'define-minor-mode)
36 (defun erc-decode-coding-string (s coding-system)
37 "Decode S using CODING-SYSTEM."
38 (decode-coding-string s coding-system t))
40 (defun erc-encode-coding-string (s coding-system)
41 "Encode S using CODING-SYSTEM.
42 Return the same string, if the encoding operation is trivial.
43 See `erc-encoding-coding-alist'."
44 (encode-coding-string s coding-system t))
46 (defalias 'erc-propertize 'propertize)
47 (defalias 'erc-view-mode-enter 'view-mode-enter)
48 (autoload 'help-function-arglist "help-fns")
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)
58 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)
66 user-emacs-directory)
67 ((boundp 'user-init-directory)
68 user-init-directory)
69 (t "~/.emacs.d/"))
70 "Directory beneath which additional per-user Emacs-specific files
71 are placed.
72 Note that this should end with a directory separator.")
74 ;; XEmacs's `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."
95 (let ((ptr list))
96 (catch 'found
97 (while ptr
98 (when (funcall predicate (car ptr))
99 (throw 'found 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
106 whenever possible."
107 ;; remove from car
108 (while (when (funcall predicate (car seq))
109 (setq seq (cdr seq))))
110 ;; remove from cdr
111 (let ((ptr seq)
112 (next (cdr seq)))
113 (while next
114 (when (funcall predicate (car next))
115 (setcdr ptr (if (consp next)
116 (cdr next)
117 nil)))
118 (setq ptr (cdr ptr))
119 (setq next (cdr ptr))))
120 seq)
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."
127 (let (newseq)
128 (dolist (el seq)
129 (when (funcall predicate el)
130 (setq newseq (cons el newseq))))
131 (nreverse 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)
139 (let (len)
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))))))
142 (cond ((listp seq)
143 (if (> start 0) (setq seq (nthcdr start seq)))
144 (if end
145 (let ((res nil))
146 (while (>= (setq end (1- end)) start)
147 (push (pop seq) res))
148 (nreverse res))
149 (copy-sequence seq)))
151 (or end (setq end (or len (length seq))))
152 (let ((res (make-vector (max (- end start) 0) nil))
153 (i 0))
154 (while (< start end)
155 (aset res i (aref seq start))
156 (setq i (1+ i) start (1+ start)))
157 res))))))
159 (provide 'erc-compat)
161 ;;; erc-compat.el ends here
163 ;; Local Variables:
164 ;; indent-tabs-mode: t
165 ;; tab-width: 8
166 ;; End: