From 371db30c10157d649a4e59ff5747b27500c87590 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Sat, 1 Jul 2023 08:55:24 +0300 Subject: Define yt-mode - Add minor mode - Define keybindings and doc them to *Yeetube-Search* buffer --- yeetube.el | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/yeetube.el b/yeetube.el index 9c79cb7..9b23991 100644 --- a/yeetube.el +++ b/yeetube.el @@ -65,9 +65,19 @@ Example Usage: :safe #'stringp :group 'yeetube) +(define-minor-mode yt-mode + "Yeetube mode." + :init-value nil + :lighter " yt-moden" + :keymap (let ((map (make-sparse-keymap))) + (define-key map (kbd "p") 'yt-play) + (define-key map (kbd "RET") 'yt-play) + (define-key map (kbd "d") 'yt-download-video) + map)) + (defun yt-play () - "Open the link at point in an `'org-mode buffer with `'mpv." (interactive) + "Open the link at point in an `'org-mode buffer with `'mpv." (let ((url (org-element-property :raw-link (org-element-context)))) (when (string-prefix-p "http" url) @@ -103,16 +113,20 @@ Example Usage: (setq buffer-read-only nil) (erase-buffer) (org-mode) - (insert "\n* Search Results: \n \n") + (insert + "~p~ /or/ ~RET~ to play video\n" + "\n~d~ to download" + "\n* Search Results: \n \n") (cl-loop for (videoId . videoTitle) in (cl-mapcar #'cons (reverse videoIds) (reverse videoTitles)) do (insert (format "+ [[https://www.youtube.com/watch?v=%s][%s ]]\n" videoId videoTitle))) - (setq buffer-read-only t)))) + (setq buffer-read-only t) + (yt-mode)))) (defun yt-download-video () - "Download using link at point in an `'org-mode buffer with yt-dlp." (interactive) + "Download using link at point in an `'org-mode buffer with yt-dlp." (let ((url (org-element-property :raw-link (org-element-context)))) (when (string-prefix-p "http" url) -- cgit v1.2.3