guile feature
[bpt/emacs.git] / lisp / erc / erc-compat.el
CommitLineData
597993cf
MB
1;;; erc-compat.el --- ERC compatibility code for XEmacs
2
ba318903 3;; Copyright (C) 2002-2003, 2005-2014 Free Software Foundation, Inc.
597993cf
MB
4
5;; Author: Alex Schroeder <alex@gnu.org>
34dc21db 6;; Maintainer: emacs-devel@gnu.org
83dc6995 7;; URL: http://www.emacswiki.org/cgi-bin/wiki/ERC
597993cf
MB
8
9;; This file is part of GNU Emacs.
10
4ee57b2a 11;; GNU Emacs is free software: you can redistribute it and/or modify
597993cf 12;; it under the terms of the GNU General Public License as published by
4ee57b2a
GM
13;; the Free Software Foundation, either version 3 of the License, or
14;; (at your option) any later version.
597993cf
MB
15
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.
20
21;; You should have received a copy of the GNU General Public License
4ee57b2a 22;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
597993cf
MB
23
24;;; Commentary:
25
26;; This mostly defines stuff that cannot be worked around easily.
27
28;;; Code:
29
30(require 'format-spec)
31
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)
35
36(defun erc-decode-coding-string (s coding-system)
37 "Decode S using CODING-SYSTEM."
38 (decode-coding-string s coding-system t))
39
40(defun erc-encode-coding-string (s coding-system)
41 "Encode S using CODING-SYSTEM.
42Return the same string, if the encoding operation is trivial.
43See `erc-encoding-coding-alist'."
44 (encode-coding-string s coding-system t))
45
46(defalias 'erc-propertize 'propertize)
47(defalias 'erc-view-mode-enter 'view-mode-enter)
688d0744 48(autoload 'help-function-arglist "help-fns")
597993cf
MB
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)
52
88406d6e
MO
53(defun erc-set-write-file-functions (new-val)
54 (set (make-local-variable 'write-file-functions) new-val))
55
597993cf
MB
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.")
61
526dc846
MO
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
71are placed.
72Note that this should end with a directory separator.")
73
44e97401 74;; XEmacs's `replace-match' does not replace matching subexpressions in strings.
597993cf
MB
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.
78MATCH is the text which matched the subexpression (see `match-string').
79START is the beginning position of the last match (see `match-beginning').
80See `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))))
85
526dc846 86(defalias 'erc-with-selected-window 'with-selected-window)
597993cf
MB
87(defalias 'erc-cancel-timer 'cancel-timer)
88(defalias 'erc-make-obsolete 'make-obsolete)
89(defalias 'erc-make-obsolete-variable 'make-obsolete-variable)
90
597993cf
MB
91;; Provide a simpler replacement for `member-if'
92(defun erc-member-if (predicate list)
93 "Find the first item satisfying PREDICATE in LIST.
94Return 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))))))
101
102;; Provide a simpler replacement for `delete-if'
103(defun erc-delete-if (predicate seq)
104 "Remove all items satisfying PREDICATE in SEQ.
105This is a destructive function: it reuses the storage of SEQ
106whenever 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)
121
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.
125This is a non-destructive function; it makes a copy of SEQ to
126avoid 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)))
132
597993cf
MB
133;; Copied from cl-extra.el
134(defun erc-subseq (seq start &optional end)
135 "Return the subsequence of SEQ from START to END.
136If END is omitted, it defaults to the length of the sequence.
137If 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)))
150 (t
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))))))
158
159(provide 'erc-compat)
160
161;;; erc-compat.el ends here
162;;
163;; Local Variables:
164;; indent-tabs-mode: t
165;; tab-width: 8
166;; End:
167