;;; liece-compat.el --- Provide compatibility for various emacsen. ;; Copyright (C) 1998-2000 Daiki Ueno ;; Author: Daiki Ueno ;; Created: 1998-09-28 ;; Revised: 1999-12-19 ;; Keywords: IRC, liece, APEL ;; This file is part of Liece. ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation; either version 2, or (at your option) ;; any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs; see the file COPYING. If not, write to the ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, ;; Boston, MA 02111-1307, USA. ;;; Commentary: ;; ;;; Code: (eval-when-compile (require 'cl)) (require 'pcustom) (require 'wid-edit) (defalias 'liece-widget-convert-button 'widget-convert-button) (defalias 'liece-widget-button-click 'widget-button-click) (defun-maybe region-active-p () "Return non-nil if the region is active. If `zmacs-regions' is true, this is equivalent to `region-exists-p'. Otherwise, this function always returns false. \[XEmacs emulating function]" (static-if (and (boundp 'transient-mark-mode) (boundp 'mark-active)) (and transient-mark-mode mark-active))) (defun liece-map-overlays (function) "Map FUNCTION over the extents which overlap the current buffer." (let* ((overlayss (overlay-lists)) (buffer-read-only nil) (overlays (delq nil (nconc (car overlayss) (cdr overlayss))))) (dolist (overlay overlays) (funcall function overlay)))) (defun liece-kill-all-overlays () "Delete all overlays in the current buffer." (liece-map-overlays #'delete-overlay)) (defmacro liece-get-buffer-window (buffer) "Traverse all frames and return a window currently displaying BUFFER." `(get-buffer-window ,buffer t)) (static-if (fboundp 'window-displayed-height) (defalias 'liece-window-height 'window-displayed-height) (defalias 'liece-window-height 'window-height)) (defalias 'liece-mode-line-buffer-identification 'identity) (defun liece-suppress-mode-line-format () "Remove unnecessary information from `mode-line-format'." (let ((value (rassq 'mode-line-modified mode-line-format))) (if value (setq mode-line-format (delq value (copy-sequence mode-line-format))) mode-line-format))) (defun liece-locate-data-directory (name &optional dir-list) "Locate a directory in a search path DIR-LIST (a list of directories)." (let ((dir-list (or dir-list (cons data-directory (mapcar (lambda (path) (concat path "etc/")) load-path)))) dir) (while dir-list (if (and (car dir-list) (file-directory-p (setq dir (concat (file-name-directory (directory-file-name (car dir-list))) name "/")))) (setq dir-list nil) (setq dir-list (cdr dir-list)))) dir)) (defvar-maybe completion-display-completion-list-function 'display-completion-list) (defalias-maybe 'easy-menu-add-item 'ignore) ;; from XEmacs's minibuf.el (defun-maybe temp-minibuffer-message (m) (let ((savemax (point-max))) (save-excursion (goto-char (point-max)) (message nil) (insert m)) (let ((inhibit-quit t)) (sit-for 2) (delete-region savemax (point-max))))) (defvar liece-read-passwd nil) (defun liece-read-passwd (prompt) (if (not liece-read-passwd) (if (functionp 'read-passwd) (setq liece-read-passwd 'read-passwd) (if (load "passwd" t) (setq liece-read-passwd 'read-passwd) (autoload 'ange-ftp-read-passwd "ange-ftp") (setq liece-read-passwd 'ange-ftp-read-passwd)))) (funcall liece-read-passwd prompt)) ;; from XEmacs's subr.el (defun-maybe replace-in-string (str regexp newtext &optional literal) "Replace all matches in STR for REGEXP with NEWTEXT string, and returns the new string. Optional LITERAL non-nil means do a literal replacement. Otherwise treat \\ in NEWTEXT string as special: \\& means substitute original matched text, \\N means substitute match for \(...\) number N, \\\\ means insert one \\." (let ((rtn-str "") (start 0) (special) match prev-start) (while (setq match (string-match regexp str start)) (setq prev-start start start (match-end 0) rtn-str (concat rtn-str (substring str prev-start match) (cond (literal newtext) (t (mapconcat (lambda (c) (if special (progn (setq special nil) (cond ((eq c ?\\) "\\") ((eq c ?&) (substring str (match-beginning 0) (match-end 0))) ((and (>= c ?0) (<= c ?9)) (if (> c (+ ?0 (length (match-data)))) ;; Invalid match num (error "Invalid match num: %c" c) (setq c (- c ?0)) (substring str (match-beginning c) (match-end c)))) (t (char-to-string c)))) (if (eq c ?\\) (progn (setq special t) nil) (char-to-string c)))) newtext "")))))) (concat rtn-str (substring str start)))) (provide 'liece-compat) ;;; liece-compat.el ends here