1 ;;; liece-compat.el --- Provide compatibility for various emacsen.
2 ;; Copyright (C) 1998-2000 Daiki Ueno
4 ;; Author: Daiki Ueno <ueno@unixuser.org>
7 ;; Keywords: IRC, liece, APEL
9 ;; This file is part of Liece.
11 ;; This program 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 2, or (at your option)
16 ;; This program 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; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
32 (eval-when-compile (require 'cl))
36 (eval-when-compile (require 'wid-edit))
38 (eval-and-compile (autoload 'widget-convert-button "wid-edit"))
40 (defalias 'liece-widget-convert-button 'widget-convert-button)
41 (defalias 'liece-widget-button-click 'widget-button-click)
43 (defun-maybe region-active-p ()
44 "Return non-nil if the region is active.
45 If `zmacs-regions' is true, this is equivalent to `region-exists-p'.
46 Otherwise, this function always returns false.
47 \[XEmacs emulating function]"
48 (static-if (and (boundp 'transient-mark-mode) (boundp 'mark-active))
49 (and transient-mark-mode mark-active)))
51 (defun liece-map-overlays (function)
52 "Map FUNCTION over the extents which overlap the current buffer."
53 (let* ((overlayss (overlay-lists))
54 (buffer-read-only nil)
55 (overlays (delq nil (nconc (car overlayss) (cdr overlayss)))))
56 (dolist (overlay overlays)
57 (funcall function overlay))))
59 (defun liece-kill-all-overlays ()
60 "Delete all overlays in the current buffer."
61 (liece-map-overlays #'delete-overlay))
63 (defmacro liece-get-buffer-window (buffer)
64 "Traverse all frames and return a window currently displaying BUFFER."
65 `(get-buffer-window ,buffer t))
67 (static-if (fboundp 'window-displayed-height)
68 (defalias 'liece-window-height 'window-displayed-height)
69 (defalias 'liece-window-height 'window-height))
71 (defalias 'liece-mode-line-buffer-identification 'identity)
73 (defun liece-suppress-mode-line-format ()
74 "Remove unnecessary information from `mode-line-format'."
75 (let ((value (rassq 'mode-line-modified mode-line-format)))
77 (setq mode-line-format (delq value (copy-sequence mode-line-format)))
80 (defun liece-locate-data-directory (name &optional dir-list)
81 "Locate a directory in a search path DIR-LIST (a list of directories)."
85 (mapcar (lambda (path) (concat path "etc/"))
89 (if (and (car dir-list)
93 (directory-file-name (car dir-list)))
96 (setq dir-list (cdr dir-list))))
99 (defvar-maybe completion-display-completion-list-function
100 'display-completion-list)
102 (defalias-maybe 'easy-menu-add-item 'ignore)
104 ;; from XEmacs's minibuf.el
105 (defun-maybe temp-minibuffer-message (m)
106 (let ((savemax (point-max)))
108 (goto-char (point-max))
111 (let ((inhibit-quit t))
113 (delete-region savemax (point-max)))))
115 ;; from XEmacs's subr.el
116 (defun-maybe replace-in-string (str regexp newtext &optional literal)
117 "Replace all matches in STR for REGEXP with NEWTEXT string,
118 and returns the new string.
119 Optional LITERAL non-nil means do a literal replacement.
120 Otherwise treat \\ in NEWTEXT string as special:
121 \\& means substitute original matched text,
122 \\N means substitute match for \(...\) number N,
123 \\\\ means insert one \\."
128 (while (setq match (string-match regexp str start))
129 (setq prev-start start
134 (substring str prev-start match)
135 (cond (literal newtext)
141 (cond ((eq c ?\\) "\\")
146 ((and (>= c ?0) (<= c ?9))
147 (if (> c (+ ?0 (length
150 (error "Invalid match num: %c" c)
155 (t (char-to-string c))))
156 (if (eq c ?\\) (progn (setq special t) nil)
157 (char-to-string c))))
159 (concat rtn-str (substring str start))))
161 (provide 'liece-compat)
163 ;;; liece-compat.el ends here