diff options
Diffstat (limited to 'emms-compat.el')
-rw-r--r-- | emms-compat.el | 77 |
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 |