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))
37 (defalias 'liece-widget-convert-button 'widget-convert-button)
38 (defalias 'liece-widget-button-click 'widget-button-click)
40 (defun-maybe region-active-p ()
41 "Return non-nil if the region is active.
42 If `zmacs-regions' is true, this is equivalent to `region-exists-p'.
43 Otherwise, this function always returns false.
44 \[XEmacs emulating function]"
45 (static-if (and (boundp 'transient-mark-mode) (boundp 'mark-active))
46 (and transient-mark-mode mark-active)))
48 (defun liece-map-overlays (function)
49 "Map FUNCTION over the extents which overlap the current buffer."
50 (let* ((overlayss (overlay-lists))
51 (buffer-read-only nil)
52 (overlays (delq nil (nconc (car overlayss) (cdr overlayss)))))
53 (dolist (overlay overlays)
54 (funcall function overlay))))
56 (defun liece-kill-all-overlays ()
57 "Delete all overlays in the current buffer."
58 (liece-map-overlays #'delete-overlay))
60 (defmacro liece-get-buffer-window (buffer)
61 "Traverse all frames and return a window currently displaying BUFFER."
62 `(get-buffer-window ,buffer t))
64 (static-if (fboundp 'window-displayed-height)
65 (defalias 'liece-window-height 'window-displayed-height)
66 (defalias 'liece-window-height 'window-height))
68 (static-if (fboundp 'string-to-list)
69 (defalias 'liece-string-to-list 'string-to-list)
70 ;; Rely on `string-to-char-list' emulation is provided in poem.
71 (defalias 'liece-string-to-list 'string-to-char-list))
73 (defalias 'liece-mode-line-buffer-identification 'identity)
75 (defun liece-suppress-mode-line-format ()
76 "Remove unnecessary information from `mode-line-format'."
77 (let ((value (rassq 'mode-line-modified mode-line-format)))
79 (setq mode-line-format (delq value (copy-sequence mode-line-format)))
82 (defun liece-locate-data-directory (name &optional dir-list)
83 "Locate a directory in a search path DIR-LIST (a list of directories)."
87 (mapcar (lambda (path) (concat path "etc/"))
91 (if (and (car dir-list)
95 (directory-file-name (car dir-list)))
98 (setq dir-list (cdr dir-list))))
101 (defvar-maybe completion-display-completion-list-function
102 'display-completion-list)
104 (defalias-maybe 'easy-menu-add-item 'ignore)
106 ;; from XEmacs's minibuf.el
107 (defun-maybe temp-minibuffer-message (m)
108 (let ((savemax (point-max)))
110 (goto-char (point-max))
113 (let ((inhibit-quit t))
115 (delete-region savemax (point-max)))))
117 (defvar liece-read-passwd nil)
118 (defun liece-read-passwd (prompt)
119 (if (not liece-read-passwd)
120 (if (functionp 'read-passwd)
121 (setq liece-read-passwd 'read-passwd)
122 (if (load "passwd" t)
123 (setq liece-read-passwd 'read-passwd)
124 (autoload 'ange-ftp-read-passwd "ange-ftp")
125 (setq liece-read-passwd 'ange-ftp-read-passwd))))
126 (funcall liece-read-passwd prompt))
129 (defun-maybe replace-in-string (str regexp newtext &optional literal)
130 "Replace all matches in STR for REGEXP with NEWTEXT string,
131 and returns the new string.
132 Optional LITERAL non-nil means do a literal replacement.
133 Otherwise treat `\\' in NEWTEXT as special:
134 `\\&' in NEWTEXT means substitute original matched text.
135 `\\N' means substitute what matched the Nth `\\(...\\)'.
136 If Nth parens didn't match, substitute nothing.
137 `\\\\' means insert one `\\'.
138 `\\u' means upcase the next character.
139 `\\l' means downcase the next character.
140 `\\U' means begin upcasing all following characters.
141 `\\L' means begin downcasing all following characters.
142 `\\E' means terminate the effect of any `\\U' or `\\L'."
143 (if (> (length str) 50)
147 (while (re-search-forward regexp nil t)
148 (replace-match newtext t literal))
150 (let ((start 0) newstr)
151 (while (string-match regexp str start)
152 (setq newstr (replace-match newtext t literal str)
153 start (+ (match-end 0) (- (length newstr) (length str)))
157 (provide 'liece-compat)
159 ;;; liece-compat.el ends here