aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--emms-compat.el77
-rw-r--r--jack.el19
2 files changed, 65 insertions, 31 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
diff --git a/jack.el b/jack.el
index 76acf76..959873c 100644
--- a/jack.el
+++ b/jack.el
@@ -41,7 +41,7 @@
;;; Code:
-(require 'cl)
+(require 'emms-compat)
(defgroup jack ()
"Jack Audio Connection Kit"
@@ -255,7 +255,7 @@ is given in jackd command-line."
(defun jack-read-program (prompt &optional predicate)
(let ((progs (if (functionp predicate)
- (remove-if-not predicate (jack-list))
+ (emms-remove-if-not predicate (jack-list))
(jack-list))))
(unless progs (error "No matching JACK clients found"))
(if (< (length progs) 2) (caar progs)
@@ -277,7 +277,7 @@ is given in jackd command-line."
(defun jack-read-port (program prompt &optional predicate)
(let ((ports (if (functionp predicate)
- (remove-if-not predicate (jack-ports program))
+ (emms-remove-if-not predicate (jack-ports program))
(jack-ports program))))
(if (< (length ports) 2) (caar ports)
(completing-read prompt ports nil t (jack-unique-port-name (mapcar 'car ports))))))
@@ -293,9 +293,10 @@ If called interactively, the direction does not matter."
(to-prog (jack-read-program
(format "Connect %s port %s to: " prog port)
(lambda (prog)
- (find-if (lambda (port)
- (member to-type (assoc 'properties (cdr port))))
- (cdr prog)))))
+ (emms-find-if (lambda (port)
+ (member to-type (assoc 'properties
+ (cdr port))))
+ (cdr prog)))))
(to-port (jack-read-port
to-prog
(format "Connect %s port %s to %s port: " prog port to-prog)
@@ -319,8 +320,8 @@ If called interactively, the direction is not relevant."
(let* ((prog (jack-read-program
"Disconnect: "
(lambda (prog)
- (find-if (lambda (port) (assoc 'connections (cdr port)))
- (cdr prog)))))
+ (emms-find-if (lambda (port) (assoc 'connections (cdr port)))
+ (cdr prog)))))
(port (jack-read-port prog
(format "Disconnect %s port: " prog)
(lambda (port)
@@ -342,7 +343,7 @@ If called interactively, the direction is not relevant."
(completing-read
(format "Disconnect %s port %s from: "
prog port) to-progs nil t))))
- (setq connections (remove-if-not
+ (setq connections (emms-remove-if-not
(lambda (conn)
(string= (car conn) to-prog))
connections))