From c744071cb69bff0a4fa7dfaf469aa1d6bb845b1d Mon Sep 17 00:00:00 2001 From: Michael Olson Date: Fri, 5 Jan 2007 03:22:00 +0000 Subject: emms-compat: New file that contains compatibility functions for emms; this make emms.el a bit cleaner-looking darcs-hash:20070105032247-1bfb2-da5b30366dfa15a91f877cae883d7324965fec9c.gz --- emms-compat.el | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ emms.el | 84 +---------------------------------------- 2 files changed, 118 insertions(+), 83 deletions(-) create mode 100644 emms-compat.el diff --git a/emms-compat.el b/emms-compat.el new file mode 100644 index 0000000..36608a1 --- /dev/null +++ b/emms-compat.el @@ -0,0 +1,117 @@ +;;; emms-compat.el --- Compatibility routines for EMMS + +;; Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc. + +;; Author: Michael Olson + +;; This file is part of EMMS. + +;; EMMS 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. +;; +;; EMMS 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 EMMS; see the file COPYING. If not, write to the +;; Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, +;; Boston, MA 02110-1301, USA. + +;;; Commentary: + +;; These are functions and macros that EMMS needs in order to be +;; compatible with various Emacs and XEmacs versions. + +;;; Code: + +(defun emms-propertize (string &rest properties) + (if (fboundp 'propertize) + (apply #'propertize string properties) + (set-text-properties 0 (length string) properties string) + string)) + +(defun emms-cancel-timer (timer) + "Cancel the given TIMER." + (when timer + (cond ((fboundp 'cancel-timer) + (cancel-timer timer)) + ((fboundp 'delete-itimer) + (delete-itimer timer))))) + +(defun emms-time-less-p (t1 t2) + "Say whether time T1 is less than time T2." + (or (< (car t1) (car t2)) + (and (= (car t1) (car t2)) + (< (nth 1 t1) (nth 1 t2))))) + +(defun emms-replace-regexp-in-string (regexp replacement text + &optional fixedcase literal) + "Replace REGEXP with REPLACEMENT in TEXT. +If fourth arg FIXEDCASE is non-nil, do not alter case of replacement text. +If fifth arg LITERAL is non-nil, insert REPLACEMENT literally." + (cond + ((fboundp 'replace-regexp-in-string) + (replace-regexp-in-string regexp replacement text fixedcase literal)) + ((fboundp 'replace-in-string) + (replace-in-string text regexp replacement literal)) + (t (let ((repl-len (length replacement)) + start) + (save-match-data + (while (setq start (string-match regexp text start)) + (setq start (+ start repl-len) + text (replace-match replacement fixedcase literal text))))) + text))) + +(defun emms-line-number-at-pos (&optional pos) + "Return (narrowed) buffer line number at position POS. +If POS is nil, use current buffer location." + (if (fboundp 'line-number-at-pos) + (line-number-at-pos pos) + (let ((opoint (or pos (point))) start) + (save-excursion + (goto-char (point-min)) + (setq start (point)) + (goto-char opoint) + (forward-line 0) + (1+ (count-lines start (point))))))) + +(defun emms-match-string-no-properties (num &optional string) + (if (fboundp 'match-string-no-properties) + (match-string-no-properties num string) + (match-string num string))) + +(defun emms-delete-if (predicate seq) + "Remove all items satisfying PREDICATE in SEQ. +This is a destructive function: it reuses the storage of SEQ +whenever possible." + ;; remove from car + (while (when (funcall predicate (car seq)) + (setq seq (cdr seq)))) + ;; remove from cdr + (let ((ptr seq) + (next (cdr seq))) + (while next + (when (funcall predicate (car next)) + (setcdr ptr (if (consp next) + (cdr next) + nil))) + (setq ptr (cdr ptr)) + (setq next (cdr ptr)))) + seq) + +(defun emms-move-beginning-of-line (arg) + "Move point to beginning of current line as displayed. +If there's an image in the line, this disregards newlines +which are part of the text that the image rests on." + (if (fboundp 'move-beginning-of-line) + (move-beginning-of-line arg) + (if (numberp arg) + (forward-line (1- arg)) + (forward-line 0)))) + +(provide 'emms-compat) +;;; emms-compat.el ends here diff --git a/emms.el b/emms.el index 64bb93c..983defa 100644 --- a/emms.el +++ b/emms.el @@ -460,89 +460,7 @@ See `emms-repeat-track'." ;;; Compatibility functions -(defun emms-propertize (string &rest properties) - (if (fboundp 'propertize) - (apply #'propertize string properties) - (set-text-properties 0 (length string) properties string) - string)) - -(defun emms-cancel-timer (timer) - "Cancel the given TIMER." - (when timer - (cond ((fboundp 'cancel-timer) - (cancel-timer timer)) - ((fboundp 'delete-itimer) - (delete-itimer timer))))) - -(defun emms-time-less-p (t1 t2) - "Say whether time T1 is less than time T2." - (or (< (car t1) (car t2)) - (and (= (car t1) (car t2)) - (< (nth 1 t1) (nth 1 t2))))) - -(defun emms-replace-regexp-in-string (regexp replacement text &optional fixedcase literal) - "Replace REGEXP with REPLACEMENT in TEXT. -If fourth arg FIXEDCASE is non-nil, do not alter case of replacement text. -If fifth arg LITERAL is non-nil, insert REPLACEMENT literally." - (cond - ((fboundp 'replace-regexp-in-string) - (replace-regexp-in-string regexp replacement text fixedcase literal)) - ((fboundp 'replace-in-string) - (replace-in-string text regexp replacement literal)) - (t (let ((repl-len (length replacement)) - start) - (save-match-data - (while (setq start (string-match regexp text start)) - (setq start (+ start repl-len) - text (replace-match replacement fixedcase literal text))))) - text))) - -(defun emms-line-number-at-pos (&optional pos) - "Return (narrowed) buffer line number at position POS. -If POS is nil, use current buffer location." - (if (fboundp 'line-number-at-pos) - (line-number-at-pos pos) - (let ((opoint (or pos (point))) start) - (save-excursion - (goto-char (point-min)) - (setq start (point)) - (goto-char opoint) - (forward-line 0) - (1+ (count-lines start (point))))))) - -(defun emms-match-string-no-properties (num &optional string) - (if (fboundp 'match-string-no-properties) - (match-string-no-properties num string) - (match-string num string))) - -(defun emms-delete-if (predicate seq) - "Remove all items satisfying PREDICATE in SEQ. -This is a destructive function: it reuses the storage of SEQ -whenever possible." - ;; remove from car - (while (when (funcall predicate (car seq)) - (setq seq (cdr seq)))) - ;; remove from cdr - (let ((ptr seq) - (next (cdr seq))) - (while next - (when (funcall predicate (car next)) - (setcdr ptr (if (consp next) - (cdr next) - nil))) - (setq ptr (cdr ptr)) - (setq next (cdr ptr)))) - seq) - -(defun emms-move-beginning-of-line (arg) - "Move point to beginning of current line as displayed. -If there's an image in the line, this disregards newlines -which are part of the text that the image rests on." - (if (fboundp 'move-beginning-of-line) - (move-beginning-of-line arg) - (if (numberp arg) - (forward-line (1- arg)) - (forward-line 0)))) +(require 'emms-compat) ;;; Tracks -- cgit v1.2.3