[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/ampc 76b1125941 025/111: Add ampc-suspend.
From: |
Stefan Monnier |
Subject: |
[elpa] externals/ampc 76b1125941 025/111: Add ampc-suspend. |
Date: |
Tue, 20 Feb 2024 18:16:37 -0500 (EST) |
branch: externals/ampc
commit 76b1125941e34ae5391b9aefec366e88b67b456d
Author: Christopher Schmidt <christopher@ch.ristopher.com>
Commit: Christopher Schmidt <christopher@ch.ristopher.com>
Add ampc-suspend.
---
ampc.el | 109 ++++++++++++++++++++++++++++++++++++++++------------------------
1 file changed, 68 insertions(+), 41 deletions(-)
diff --git a/ampc.el b/ampc.el
index 32ee4c28af..31852342fd 100644
--- a/ampc.el
+++ b/ampc.el
@@ -157,6 +157,7 @@
;; point to the current song.
;;
;; `T' (ampc-trigger-update): Trigger a database update.
+;; `Z' (ampc-suspend): Suspend ampc.
;; `q' (ampc-quit): Quit ampc.
;;
;; The keymap of ampc is designed to fit the QWERTY United States keyboard
@@ -169,6 +170,7 @@
;; (from to)
;; (define-key ampc-mode-map to (lookup-key ampc-mode-map from))
;; (define-key ampc-mode-map from nil)))
+;; (substitute-ampc-key (kbd "z") (kbd "Z"))
;; (substitute-ampc-key (kbd "y") (kbd "z"))
;; (substitute-ampc-key (kbd "M-y") (kbd "M-z"))
;; (substitute-ampc-key (kbd "<") (kbd ";")))
@@ -208,6 +210,9 @@ This hook is called as the first thing when ampc is
started."
(defcustom ampc-connected-hook nil
"A hook called after ampc connected to MPD."
:type 'hook)
+(defcustom ampc-suspend-hook nil
+ "A hook called when suspending ampc."
+ :type 'hook)
(defcustom ampc-quit-hook nil
"A hook called when exiting ampc."
:type 'hook)
@@ -278,6 +283,8 @@ This hook is called as the first thing when ampc is
started."
("outputenabled" :title "Enabled" :offset 10))))))
(defvar ampc-connection nil)
+(defvar ampc-host nil)
+(defvar ampc-port nil)
(defvar ampc-outstanding-commands nil)
(defvar ampc-working-timer nil)
@@ -317,6 +324,7 @@ This hook is called as the first thing when ampc is
started."
(define-key map (kbd "f") 'ampc-toggle-consume)
(define-key map (kbd "P") 'ampc-goto-current-song)
(define-key map (kbd "q") 'ampc-quit)
+ (define-key map (kbd "z") 'ampc-suspend)
(define-key map (kbd "T") 'ampc-trigger-update)
(loop for view in ampc-views
do (define-key map (car view)
@@ -1254,7 +1262,7 @@ This hook is called as the first thing when ampc is
started."
(defun ampc-windows (&optional unordered)
(loop for f being the frame
thereis (loop for w being the windows of f
- when (eq (window-buffer w) (car ampc-buffers))
+ when (eq (window-buffer w) (car-safe ampc-buffers))
return (loop for b in (if unordered
ampc-buffers-unordered
ampc-buffers)
@@ -1634,6 +1642,34 @@ ARG defaults to 1."
(ampc-align-point)
nil))
+(defun* ampc-suspend (&optional (run-hook t))
+ "Suspend ampc.
+This function resets the window configuration, but does not close
+the connection to mpd or destroy the internal cache of ampc.
+This means subsequent startups of ampc will be faster."
+ (interactive)
+ (when ampc-working-timer
+ (cancel-timer ampc-working-timer))
+ (loop with found-window
+ for w in (nreverse (ampc-windows t))
+ when (window-live-p w)
+ when found-window
+ do (delete-window w)
+ else
+ do (setf found-window t
+ (window-dedicated-p w) nil)
+ end
+ end)
+ (loop for b in ampc-all-buffers
+ when (buffer-live-p b)
+ do (kill-buffer b)
+ end)
+ (setf ampc-buffers nil
+ ampc-all-buffers nil
+ ampc-working-timer nil)
+ (when run-hook
+ (run-hooks 'ampc-suspend-hook)))
+
(defun ampc-quit (&optional arg)
"Quit ampc.
If called with a prefix argument ARG, kill the mpd instance that
@@ -1651,25 +1687,9 @@ ampc is connected to."
(ampc-send-command-impl (if arg "kill" "close")))
(when ampc-working-timer
(cancel-timer ampc-working-timer))
- (loop with found-window
- for w in (nreverse (ampc-windows t))
- when (window-live-p w)
- when found-window
- do (delete-window w)
- else
- do (setf found-window t
- (window-dedicated-p w) nil)
- end
- end)
- (loop for b in ampc-all-buffers
- when (buffer-live-p b)
- do (kill-buffer b)
- end)
+ (ampc-suspend nil)
(setf ampc-connection nil
- ampc-buffers nil
- ampc-all-buffers nil
ampc-internal-db nil
- ampc-working-timer nil
ampc-outstanding-commands nil
ampc-status nil)
(run-hooks 'ampc-quit-hook))
@@ -1682,30 +1702,37 @@ This function is the main entry point for ampc.
Non-interactively, HOST and PORT specify the MPD instance to
connect to. The values default to localhost:6600."
(interactive "MHost (localhost): \nMPort (6600): ")
- (when ampc-connection
- (ampc-quit))
(run-hooks 'ampc-before-startup-hook)
- (when (equal host "")
- (setf host nil))
- (when (equal port "")
- (setf port nil))
- (let ((connection (open-network-stream "ampc"
- (with-current-buffer
- (get-buffer-create " *mpc*")
- (delete-region (point-min)
- (point-max))
- (current-buffer))
- (or host "localhost")
- (or port 6600)
- :type 'plain :return-list t)))
- (unless (car connection)
- (error "Failed connecting to server: %s"
- (plist-get ampc-connection :error)))
- (setf ampc-connection (car connection)))
- (setf ampc-outstanding-commands '((setup)))
- (set-process-coding-system ampc-connection 'utf-8-unix 'utf-8-unix)
- (set-process-filter ampc-connection 'ampc-filter)
- (set-process-query-on-exit-flag ampc-connection nil)
+ (when (or (not host) (equal host ""))
+ (setf host "localhost"))
+ (when (or (not port) (equal port ""))
+ (setf port 6600))
+ (when (and ampc-connection
+ (or (not (equal host ampc-host))
+ (not (equal port ampc-port))
+ (not (member (process-status ampc-connection)
+ '(open run)))))
+ (ampc-quit))
+ (unless ampc-connection
+ (let ((connection (open-network-stream "ampc"
+ (with-current-buffer
+ (get-buffer-create " *mpc*")
+ (delete-region (point-min)
+ (point-max))
+ (current-buffer))
+ host
+ port
+ :type 'plain :return-list t)))
+ (unless (car connection)
+ (error "Failed connecting to server: %s"
+ (plist-get ampc-connection :error)))
+ (setf ampc-connection (car connection)
+ ampc-host host
+ ampc-port port))
+ (set-process-coding-system ampc-connection 'utf-8-unix 'utf-8-unix)
+ (set-process-filter ampc-connection 'ampc-filter)
+ (set-process-query-on-exit-flag ampc-connection nil)
+ (setf ampc-outstanding-commands '((setup))))
(ampc-configure-frame (cdar ampc-views))
(run-hooks 'ampc-connected-hook)
(ampc-filter (process-buffer ampc-connection) nil))
- [elpa] externals/ampc 11216543fb 097/111: * ampc.el (ampc-handle-status): Run ampc-status-changed-hook., (continued)
- [elpa] externals/ampc 11216543fb 097/111: * ampc.el (ampc-handle-status): Run ampc-status-changed-hook., Stefan Monnier, 2024/02/20
- [elpa] externals/ampc ea1a2267d9 100/111: * ampc: Sync to version 0.2., Stefan Monnier, 2024/02/20
- [elpa] externals/ampc 120a515820 015/111: ampc is (hopefully) a part of GNU Emacs., Stefan Monnier, 2024/02/20
- [elpa] externals/ampc 683f02ed7c 003/111: Remove autoload for ampc-quit., Stefan Monnier, 2024/02/20
- [elpa] externals/ampc 097424e63e 005/111: Simplify ampc-toggle-*., Stefan Monnier, 2024/02/20
- [elpa] externals/ampc 8df5fd0ff3 010/111: Fix indentation in source code., Stefan Monnier, 2024/02/20
- [elpa] externals/ampc d465fe978e 013/111: Add version tag., Stefan Monnier, 2024/02/20
- [elpa] externals/ampc d27ffb2415 016/111: * ampc: New package., Stefan Monnier, 2024/02/20
- [elpa] externals/ampc ee5f78f2ea 019/111: Add new views with a different order of tag browsers., Stefan Monnier, 2024/02/20
- [elpa] externals/ampc 7289f29365 020/111: Add note on how to remap keys in ampc-mode-map., Stefan Monnier, 2024/02/20
- [elpa] externals/ampc 76b1125941 025/111: Add ampc-suspend.,
Stefan Monnier <=
- [elpa] externals/ampc 1d2d403a59 026/111: Remove superfluous whitespace., Stefan Monnier, 2024/02/20
- [elpa] externals/ampc cc7f4c8432 031/111: Alias unspecified tags in ampc-status., Stefan Monnier, 2024/02/20
- [elpa] externals/ampc 6ea9805c14 034/111: Clarify version error message., Stefan Monnier, 2024/02/20
- [elpa] externals/ampc 8b11bf109c 107/111: ; Fix typos, Stefan Monnier, 2024/02/20
- [elpa] externals/ampc ba9840c63f 110/111: ; Depend on Emacs 24.3, Stefan Monnier, 2024/02/20
- [elpa] externals/ampc ed0caf2d07 035/111: Correctly quote arguments before sending them to MPD., Stefan Monnier, 2024/02/20
- [elpa] externals/ampc 69bef3a98d 040/111: Fix code alignment., Stefan Monnier, 2024/02/20
- [elpa] externals/ampc 18dc9a9870 041/111: Handle listallinfo chunks right after receiving them., Stefan Monnier, 2024/02/20
- [elpa] externals/ampc 473ad7dbc3 042/111: Add emacswiki-generator.el., Stefan Monnier, 2024/02/20
- [elpa] externals/ampc d8ba1ed217 045/111: * ampc.el (ampc): Fix typo., Stefan Monnier, 2024/02/20