1 ;;; cvs-compat.el --- Compatibility functions for various Emacsen
3 ;; Copyright (C) 1999-2000 Free Software Foundation, Inc.
5 ;; Author: Stefan Monnier <monnier@cs.yale.edu>
6 ;; Keywords: compatibility
8 ;; Revision: cvs-compat.el,v 1.3 2000/03/05 21:32:21 monnier Exp
10 ;; This program 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 2 of the License, or
13 ;; (at your option) any later version.
15 ;; This program 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 this program; if not, write to the Free Software
22 ;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
33 ;;;; String Processing
36 ;; doesn't exist in Emacs < 20.1
37 (eval-when-compile (autoload 'string-split "string"))
38 (unless (fboundp 'split-string)
39 ;; define it in terms of elib's string's string-split
41 (defun split-string (str &optional sep)
42 ;; this is not quite correct since we should only eliminate
43 ;; a leading and a trailing empty string, but it's enough for our use.
44 (delete-if (lambda (str) (string= str "")) (string-split sep str))))
46 ;; too bad it's only provided by dired rather than by some "neutral" lib.
47 (unless (fboundp 'string-replace-match)
49 (if (fboundp 'dired-string-replace-match)
50 (defalias 'string-replace-match 'dired-string-replace-match)
54 ;;;; Buffer management
57 ;; doesn't exist in Emacs < 20.1
58 (unless (fboundp 'save-current-buffer)
59 (defmacro save-current-buffer (&rest body)
60 (let ((sym (make-symbol "curbuf")))
61 `(let ((,sym (current-buffer)))
62 (unwind-protect (progn ,@body) (set-buffer ,sym))))))
64 ;; doesn't exist in Emacs < 20.1
65 (unless (fboundp 'with-current-buffer)
66 (defmacro with-current-buffer (buf &rest body)
67 `(save-current-buffer (set-buffer ,buf) ,@body)))
73 ;; doesn't exist in Emacs < 20.1
74 (unless (fboundp 'set-keymap-parent)
75 (defun set-keymap-parent (keymap parent)
76 (unless (and (consp keymap) (eq 'keymap (car keymap)))
77 (error "Unknown keymap type"))
78 (setf (cdr (last keymap)) parent)))
80 ;; doesn't exist in Emacs
81 (unless (fboundp 'set-keymap-parents)
82 (defun set-keymap-parents (m parents)
83 (if (keymapp parents) (setq parents (list parents)))
87 (reduce (lambda (m1 m2)
88 (let ((m (copy-keymap m1)))
89 (set-keymap-parent m m2) m))
98 ;; doesn't exist in Emacs < 20.1
99 (unless (fboundp 'set-face-bold-p)
100 (defun set-face-bold-p (face v &optional f)
101 (when v (ignore-errors (make-face-bold face)))))
102 (unless (fboundp 'set-face-italic-p)
103 (defun set-face-italic-p (face v &optional f)
104 (when v (ignore-errors (make-face-italic face)))))
106 ;; doesn't exist in Emacs < 20.1
107 (ignore-errors (require 'custom))
108 (unless (fboundp 'defgroup)
109 (defmacro defgroup (&rest rest) ()))
110 (unless (fboundp 'defcustom)
111 (defmacro defcustom (sym val str &rest rest) `(defvar ,sym ,val ,str)))
112 (unless (fboundp 'defface)
113 (defmacro defface (sym val str &rest rest)
114 `(defvar ,sym (make-face ',sym) ,str)))
117 ;;;; missing functions in Emacs
120 ;; doesn't exist in Emacs
121 (unless (fboundp 'read-directory-name)
122 (defalias 'read-directory-name 'read-file-name))
125 (provide 'cvs-compat)
126 ;;; cvs-compat.el ends here