1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- ;; Adds org-links for EMMS
- ;; Based on
- ;; https://orgmode.org/manual/Adding-Hyperlink-Types.html#Adding-Hyperlink-Types
- ;;
- ;; - (untested);;
- ;; (with-eval-afeter-load "org"
- ;; (add-to-list
- ;; 'load-path
- ;; "/your/path/to/this/file.el")
- ;; (require 'ol-emms))
- ;;
- ;; - To load it with use-package:
- ;; (use-package ol-emms
- ;; :after (ol)
- ;; :load-path "~/.emacs.d/plugins/"
- ;; :config
- ;; (add-hook 'org-mode-hook
- ;; #'(lambda ()
- ;; "Add `org-emms-open' to `org-add-link-type'"
- ;; (org-add-link-type "emms" 'org-emms-open))))
- (require 'ol)
- (require 'emms)
- (defun org-emms-store-link ()
- "Store a link to a sound file."
- (when (eq major-mode 'emms-playlist-mode)
- ;; This is EMMS mode, we do make this link.
- (let* ((file (org-emms-get-file-name))
- (link (concat "emms:" file))
- (desc (emms-info-track-description (emms-playlist-track-at)))
- )
- (org-link-store-props
- :type "emms"
- :link link
- :decription desc))))
- (defun org-emms-get-file-name ()
- "Get the file name from the current playlist line."
- (let ((fname (emms-track-simple-description (emms-playlist-track-at))))
- (if (file-exists-p fname)
- fname
- nil)))
- (defun org-emms-export (link description format)
- "Export an EMMS link from Org files."
- (let ((desc (or link description)))
- (pcase format
- (`html (format "<a href=\"%s\">%s</a>" path desc))
- (`latex (format "\\href{%s}{%s}" path desc))
- (`texinfo (format "@uref{%s,%s}" path desc))
- (`ascii (format "%s (%s)" desc path))
- (_ path))))
- (defun org-emms-open (link)
- "The EMMS command to be used to play a sound file."
- (if (file-exists-p link)
- ;; If the file is a playlist (based on extension), use
- ;; it as such. Otherwise, play the file
- (let ((fname (expand-file-name link))
- (buf nil))
- ;; Add file to playlist
- (if ;; Check if the extension of the file is in the
- ;; list of playlist extensions
- (member
- ;; Get the extension as a symbol
- ;; https://emacsredux.com/blog/2014/12/05
- ;; /converting-between-symbols-and-strings/
- (intern (file-name-extension link))
- emms-source-playlist-formats)
- ;; Add playlist
- (emms-play-playlist fname)
- ;; Add regular file
- (emms-play-file fname)))))
- (defun org-emms-complete-link (&optional arg)
- "Use the existing file name completion for file.
- Links to get the file name and append it. (Based on
- `org-pdfview')."
- (replace-regexp-in-string "^file:" "emms:" (org-link-complete-file arg)))
- (org-link-set-parameters "emms"
- :follow #'org-emms-open
- :export #'org-emms-export
- :complete #'org-emms-complete-link
- :store #'org-emms-store-link)
- (provide 'ol-emms)
- ;;; ol-emms.el ends here
|