diff options
author | Aryadev Chavali <aryadev@aryadevchavali.com> | 2024-05-13 17:32:38 +0530 |
---|---|---|
committer | Aryadev Chavali <aryadev@aryadevchavali.com> | 2024-05-13 17:32:38 +0530 |
commit | ab2742cd3efa28fe3a9c8c58ebabae3e0bac31ae (patch) | |
tree | 02f87d38c7bfe0d73cd616d95e8fe22fa5bda9a9 | |
parent | ce660d9a2a6bc016a0f9a635dc015b807c9a8f5f (diff) | |
download | dotfiles-ab2742cd3efa28fe3a9c8c58ebabae3e0bac31ae.tar.gz dotfiles-ab2742cd3efa28fe3a9c8c58ebabae3e0bac31ae.tar.bz2 dotfiles-ab2742cd3efa28fe3a9c8c58ebabae3e0bac31ae.zip |
(Emacs/elisp|config)+org-bookmark manager
Opens bookmarks from ~/Text/bookmarks.org with a dispatcher.
-rw-r--r-- | Emacs/.config/emacs/config.org | 15 | ||||
-rw-r--r-- | Emacs/.config/emacs/elisp/org-bookmark.el | 77 |
2 files changed, 92 insertions, 0 deletions
diff --git a/Emacs/.config/emacs/config.org b/Emacs/.config/emacs/config.org index eb8eb3c..79db252 100644 --- a/Emacs/.config/emacs/config.org +++ b/Emacs/.config/emacs/config.org @@ -1553,6 +1553,21 @@ directories particularly efficiently. "P" #'+search/find-file "S" #'+search/search-all)) #+end_src +** Bookmarks +I maintain a bookmarks file at =~/Text/bookmarks.org=. I would like +the ability to construct new bookmarks and open bookmarks. They may +be either articles I want to read, useful information documents or +just straight up youtube videos. This +[[file:elisp/bookmark.el][library]] does the appropriate dispatching +and work for me. + +#+begin_src emacs-lisp +(use-package org-bookmark + :load-path "elisp/" + :general + (file-leader + "b" #'+bookmark/open-bookmark)) +#+end_src * Applications Emacs is basically an operating system whose primary datatype is text. Applications are interfaces/environments which serve a variety of diff --git a/Emacs/.config/emacs/elisp/org-bookmark.el b/Emacs/.config/emacs/elisp/org-bookmark.el new file mode 100644 index 0000000..6bbad5d --- /dev/null +++ b/Emacs/.config/emacs/elisp/org-bookmark.el @@ -0,0 +1,77 @@ +;;; org-bookmark.el --- Bookmark manager using org-mode -*- lexical-binding: t; -*- + +;; Copyright (C) 2024 Aryadev Chavali + +;; Author: Aryadev Chavali <aryadev@aryadevchavali.com> +;; Keywords: + +;; This program is free software; you can redistribute it and/or +;; modify it under the terms of the GNU General Public License Version +;; 2 as published by the Free Software Foundation. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see <https://www.gnu.org/licenses/>. + +;;; Commentary: + +;; + +;;; Code: + +(require 'org) + +(defvar +bookmark/file (expand-file-name "~/Text/bookmarks.org")) +(defvar +bookmark/mpv-args "--ytdl-raw-options=force-ipv4= --ytdl-format=22") + +(defun +bookmark/bookmarks () + (with-current-buffer (find-file-noselect +bookmark/file) + (org-scan-tags + #'(lambda nil + (let ((heading-components (org-heading-components))) + (cons + (concat (nth 4 heading-components) (nth 5 heading-components)) + (substring-no-properties (org-agenda-get-some-entry-text + (point-marker) + most-positive-fixnum))))) + (cdr (org-make-tags-matcher ":bookmark:")) + nil))) + +(defun +bookmark/open-bookmark () + (interactive) + (let* ((bookmarks (+bookmark/bookmarks)) + (choice (completing-read "Choose bookmark: " + (mapcar #'car bookmarks) + nil t)) + (pair (assoc choice bookmarks #'string=))) + (if (null pair) + (error (format "`%s' is not a valid bookmark" choice)) + (message "[bookmark]: Opening `%s`" (car pair)) + (cond + ((or + (string-match-p "^https://\\(www.\\)?youtu\\(.\\)?be" (cdr pair)) + (string-match-p "\\.mp4$" (cdr pair))) + ;; Open MPV + (message "[bookmark]: Starting MPV process") + (with-current-buffer (get-buffer-create "*mpv*") + (ansi-color-for-comint-mode-on) + (comint-mode)) + (set-process-filter (start-process-shell-command + "bookmark-mpv" "*mpv*" + (concat + "mpv " + +bookmark/mpv-args + " \"" + (cdr pair) + "\"")) + #'comint-output-filter)) + (t + (message "[bookmark]: Starting eww") + (eww (cdr pair))))))) + +(provide 'org-bookmark) +;;; bookmark.el ends here |