aboutsummaryrefslogtreecommitdiff
path: root/emms-compat.el
diff options
context:
space:
mode:
authorMichael Olson <mwolson@gnu.org>2007-01-05 04:27:00 +0000
committerMichael Olson <mwolson@gnu.org>2007-01-05 04:27:00 +0000
commit48b1d322af14361065d2b1b67d7817cd86b14370 (patch)
tree69caf60ecf89fbbcf888dfacfa9efdb857c979d8 /emms-compat.el
parent75b1bc1069691cc53c4f3120f67289890ef2d340 (diff)
Make jack.el use emms-compat.el rather than cl.el, and tidy up emms-compat.el
darcs-hash:20070105042701-1bfb2-0883b98f76b030dc45c5c8e975df8b12f4955204.gz
Diffstat (limited to 'emms-compat.el')
-rw-r--r--emms-compat.el77
1 files changed, 55 insertions, 22 deletions
diff --git a/emms-compat.el b/emms-compat.el
index 36608a1..748f487 100644
--- a/emms-compat.el
+++ b/emms-compat.el
@@ -28,12 +28,18 @@
;;; Code:
+
+;;; Miscellaneous
+
(defun emms-propertize (string &rest properties)
(if (fboundp 'propertize)
(apply #'propertize string properties)
(set-text-properties 0 (length string) properties string)
string))
+
+;;; Time and timers
+
(defun emms-cancel-timer (timer)
"Cancel the given TIMER."
(when timer
@@ -48,6 +54,35 @@
(and (= (car t1) (car t2))
(< (nth 1 t1) (nth 1 t2)))))
+
+;;; Movement and position
+
+(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))))
+
+(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)))))))
+
+
+;;; Regular expression matching
+
(defun emms-replace-regexp-in-string (regexp replacement text
&optional fixedcase literal)
"Replace REGEXP with REPLACEMENT in TEXT.
@@ -66,24 +101,14 @@ If fifth arg LITERAL is non-nil, insert REPLACEMENT literally."
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)))
+
+;;; Common Lisp
+
(defun emms-delete-if (predicate seq)
"Remove all items satisfying PREDICATE in SEQ.
This is a destructive function: it reuses the storage of SEQ
@@ -103,15 +128,23 @@ whenever possible."
(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))))
+(defun emms-find-if (predicate seq)
+ "Find the first item satisfying PREDICATE in SEQ.
+Return the matching item, or nil if not found."
+ (catch 'found
+ (dolist (el seq)
+ (when (funcall predicate el)
+ (throw 'found el)))))
+
+(defun emms-remove-if-not (predicate seq)
+ "Remove all items not satisfying PREDICATE in SEQ.
+This is a non-destructive function; it makes a copy of SEQ to
+avoid corrupting the original SEQ."
+ (let (newseq)
+ (dolist (el seq)
+ (when (funcall predicate el)
+ (setq newseq (cons el newseq))))
+ (nreverse newseq)))
(provide 'emms-compat)
;;; emms-compat.el ends here