diff options
author | Thanos Apollo <[email protected]> | 2023-10-07 12:18:32 +0300 |
---|---|---|
committer | Thanos Apollo <[email protected]> | 2023-10-07 12:18:32 +0300 |
commit | d89fb174171f98d056cd8d34d02bd62fc86bcd1c (patch) | |
tree | dc457b4612c97d52b975c42718d069dcebba77f5 | |
parent | 2e0d024b7450c9148825d980b08c67a1165d3038 (diff) | |
parent | 6621fbadad002b32ed6ace1e0461268e333e5470 (diff) |
yeetube-buffer: Use cl-loop to insert contents
- Seperate #'yeetube-insert-content
- Simplify/rewrite yeetube-buffer-create using cl-loop
-rw-r--r-- | yeetube-buffer.el | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/yeetube-buffer.el b/yeetube-buffer.el index 0042fcc..fed3c66 100644 --- a/yeetube-buffer.el +++ b/yeetube-buffer.el @@ -180,6 +180,16 @@ Emojis cause formatting issues, this should be off by default." (yeetube-buffer--format-video-duration "Duration") (yeetube-buffer--format-channel "Channel")))) +(defun yeetube-buffer-insert-content (content) + "Insert formatted CONTENT." + (insert + (concat (yeetube-buffer--format-title (yeetube-buffer-fix-title (car content))) + (yeetube-buffer--format-view-count (yeetube-buffer-view-count-add-commas + (yeetube-buffer-fix-view-count (nth 2 content)))) + (yeetube-buffer--format-video-duration (nth 3 content)) + (yeetube-buffer--format-channel (nth 4 content)) + "\n"))) + ;;;###autoload (defun yeetube-buffer-create (query content buffer-mode) "Create *yeetube* buffer with BUFFER-MODE for search QUERY, displaying CONTENT." @@ -189,22 +199,8 @@ Emojis cause formatting issues, this should be off by default." (setf buffer-read-only nil) (erase-buffer) (yeetube-buffer--format-header query) - (dolist (info (reverse content)) - (let ((title (yeetube-buffer-fix-title (car info))) - (view-count (nth 2 info)) - (video-duration (nth 3 info)) - (channel-name (nth 4 info))) - (insert - (yeetube-buffer--format-title title) - (yeetube-buffer--format-view-count - (yeetube-buffer-view-count-add-commas - (yeetube-buffer-fix-view-count view-count))) - (yeetube-buffer--format-video-duration - (if (string-match-p "^[0-9:]+$" video-duration) - video-duration - "nil")) - (yeetube-buffer--format-channel channel-name) - "\n"))) + (cl-loop for result in (reverse content) + do (yeetube-buffer-insert-content result)) (delete-char -1) (goto-char (point-min)))) |