Compare commits

...

4 Commits

2 changed files with 85 additions and 201 deletions

View File

@ -1580,6 +1580,32 @@ the current [[https://en.wikipedia.org/wiki/Version_control][VCS]] directory tre
(keymap-set deadgrep-mode-map "C-c C-w" #'deadgrep-edit-mode)))
#+end_src
** [[https://www.masteringemacs.org/article/searching-buffers-occur-mode][Searching and Editing in Buffers with Occur Mode]]
:PROPERTIES:
:CUSTOM_ID: sec:occur
:END:
#+caption[Define =multi-occur-in-this-mode=]:
#+caption: Define =multi-occur-in-this-mode=.
#+name: lst:multi-occur-in-this-mode
#+begin_src emacs-lisp -n :results silent
(defun get-buffers-matching-mode (mode)
"Return a list of buffers whose major-mode is equal to MODE."
(let ((buffer-mode-matches '()))
(dolist (buf (buffer-list))
(with-current-buffer buf
(when (eq mode major-mode)
(push buf buffer-mode-matches))))
buffer-mode-matches))
(defun multi-occur-in-this-mode ()
"Show all lines matching REGEXP in buffers with this major mode."
(interactive)
(multi-occur
(get-buffers-matching-mode major-mode)
(car (occur-read-primary-args))))
#+end_src
** [[https://www.genivia.com/get-ugrep.html][Ugrep]]
:PROPERTIES:
:CUSTOM_ID: sec:ugrep
@ -2931,205 +2957,54 @@ See `org-link-parameters' for details about PATH, DESC and FORMAT."
:END:
Listing [[lst:define-org-yt-link-type][define org-yt-link type]] implements code to open the link to the
following YouTube video [[yt:eaZUZCzaIgw#6s#10s][Extending org-mode to handle YouTube links.]]
following YouTube video [[yt:eaZUZCzaIgw][Extending org-mode to handle YouTube links]] and the
following [[https://raw.githubusercontent.com/bitspook/spookmax.d/master/readme.org][Emacs setup]].
Opening [[yt:eaZUZCzaIgw][Extending org-mode to handle YouTube links]] may fail due to a bug in the
interface between =mpv= and =yt-dlp=. Listing [[lst:set-emms-options][set EMMS options]] indicates how to
work around this bug at the cost of making the user interface less clean.
However, the link [[yt:48JlgiBpw_I][Absolute Beginner's Guide to Emacs]] works always.
The following posts provide programming information:
1. [[https://developers.google.com/youtube/v3/docs][YouTube API reference]].
2. [[https://developers.google.com/youtube/iframe_api_reference][YouTube Player API reference for iframe embeds]].
3. [[https://www.alphr.com/how-to-link-specific-timestamp-youtube/][How to link to a specific timestamp in a YouTube video]].
#+begin_src emacs-lisp -n :exports none :tangle no
;; https://www.youtube.com/embed/M03bTkQxVUg?start=30&end=120
(org-yt-seconds-to-hms (+ (* 3600 120) (* 60 9) 7))
(org-yt-seconds-to-hms 3661)
(org-yt-time-to-seconds "")
(org-yt-time-to-seconds "1")
(org-yt-time-to-seconds "1:1")
(org-yt-time-to-seconds "1:1:1")
(org-yt-time-to-seconds "1h1m1s")
(org-yt-time-to-seconds "1mX")
(org-yt-time-to-seconds "1h")
(org-yt-time-to-seconds "1H1m")
(org-yt-time-to-seconds "1h1s")
(org-yt-time-to-seconds "1m1s")
(org-yt-time-to-seconds "1h1s")
(org-yt-time-to-seconds "1h1M1s")
(org-yt-format-open-url "WKwZHSbHmPg" "")
(org-yt-format-open-url "WKwZHSbHmPg" nil)
(org-yt-format-open-url "WKwZHSbHmPg" '("1m1s"))
(org-yt-format-open-url "WKwZHSbHmPg" '("0:2:44" "0:2:50"))
(org-yt-open "WKwZHSbHmPg#0:2:44#0:2:50" t)
(org-yt-export "WKwZHSbHmPg#0:2:44#0:2:50" "Title" 'html nil)
(org-yt-export "WKwZHSbHmPg#0h2m40s#0h2m50s" "Title" 'html nil)
(org-yt-export "WKwZHSbHmPg#2M40S#2M50S" "Title" 'html nil)
(org-yt-export "WKwZHSbHmPg#0:2:44#0:2:50" "Title" 'latex nil)
(org-yt-export "WKwZHSbHmPg#0h2m40s#0h2m50s" "Title" 'latex nil)
(org-yt-export "WKwZHSbHmPg#2M40S#2M50S" "Title" 'latex nil)
#+end_src
#+caption[Parsing function for the =org-yt= link type]:
#+caption: Parsing function for the =org-yt= link type.
#+name: lst:org-yt-parsing
#+begin_src emacs-lisp -n :results silent
(defun org-yt-time-to-seconds (text)
"Convert TEXT of the form `12:34:56' or `12h34m56s' to seconds as integers."
(let* ((case-fold-search t)
(hms (< (length (split-string text "[:]"))
(length (split-string text "[HhMmSs]"))))
(regexp (if hms
(rx (opt (group (+ digit) "h"))
(opt (group (+ digit) "m"))
(opt (group (+ digit) "s")))
(rx (opt (group (+ digit)))
(opt ":" (group (+ digit)))
(opt ":" (group (+ digit))))))
(_ (string-match regexp text))
(md (match-data))
(found (substring text (pop md) (pop md)))
(seconds 0)
lot)
(if (string< found text)
(user-error "Found `%s' which is a prefix of `%s'" found text)
(if hms
(while md
(setq lot (substring text (or (pop md) 0) (or (pop md) 0)))
(cond
((or (string-suffix-p "h" lot) (string-suffix-p "H" lot))
(setq seconds (+ seconds (* 3600 (string-to-number lot)))))
((or (string-suffix-p "m" lot) (string-suffix-p "M" lot))
(setq seconds (+ seconds (* 60 (string-to-number lot)))))
((or (string-suffix-p "s" lot) (string-suffix-p "S" lot))
(setq seconds (+ seconds (string-to-number lot))))))
(while md (push (string-to-number
(substring text (or (pop md) 0) (or (pop md) 0)))
lot))
(cond
((length= lot 1) (setq seconds (car lot)))
((length= lot 2) (setq seconds (+ (* 60 (cadr lot))
(car lot))))
((length= lot 3) (setq seconds (+ (* 3600 (caddr lot))
(* 60 (cadr lot))
(car lot)))))))
seconds))
#+end_src
#+caption[Formatting functions to open =org-yt= links]:
#+caption: Formatting functions to open =org-yt= links.
#+name: lst:org-yt-open-formatting
#+begin_src emacs-lisp -n :results silent
(defun org-yt-seconds-to-hms (seconds)
"Convert seconds as integers to text of the form `12h34m56s'."
(let ((h (/ seconds 3600))
(m (/ (% seconds 3600) 60))
(s (% seconds 60)))
(concat (and (> h 0) (format "%dh" h))
(if (> h 0)
(format "%02dm" m)
(and (> m 0) (format "%dm" m)))
(if (or (> h 0) (> m 0))
(format "%02ds" s)
(format "%ds" s)))))
(defconst org-yt-start
"https://www.youtube.com/watch?v=%s&t=%s"
"Format string for `org-yt-format-open-url' to fill in ID and TIMING.")
(defconst org-yt-chunk
"https://www.youtube.com/embed/%s?autoplay=1&start=%d&end=%d"
"Format string for `org-yt-format-open-url' to fill in ID and TIMING.")
(defun org-yt-format-open-url (id timing)
"Convert an \"yt\" type link to an URL for opening."
(cond
((not timing)
(format org-yt-start id "0s"))
((length= timing 1)
(format org-yt-start id
(org-yt-seconds-to-hms (org-yt-time-to-seconds (car timing)))))
((length= timing 2)
(format org-yt-chunk id
(org-yt-time-to-seconds (car timing))
(org-yt-time-to-seconds (cadr timing))))))
#+end_src
#+caption[Formatting function for HTML export of =org-yt= links]:
#+caption: Formatting function for HTML export of =org-yt= links.
#+name: lst:org-yt-html-export-formatting
#+begin_src emacs-lisp -n :results silent
(defconst org-yt-iframe
"<iframe
frameborder=\"0\" width=\"600\" height=\"450\"
src=\"https://www.youtube.com/embed/%s%s\"
title=\"%s\"
allowfullscreen></iframe>"
"Format string for `org-yt-iframe' to fill in ID, TIMING, and TITLE.")
(defun org-yt-format-iframe (id timing title)
"Convert an \"yt\" type link to an inline frame element for export to HTML."
(format org-yt-iframe id
(cond
((not timing) "")
((length= timing 1)
(format "?start=%d" id (org-yt-time-to-seconds (car timing))))
((length= timing 2)
(format "?start=%d&end=%d"
(org-yt-time-to-seconds (car timing))
(org-yt-time-to-seconds (cadr timing)))))
title))
#+end_src
#+caption[Define an =org-link= type for =YouTube=]:
#+caption: Define an =org-link= type for =YouTube=.
#+name: lst:define-org-yt-link-type
#+begin_src emacs-lisp -n :results silent
(defun org-yt-open (path prefix)
"Open an \"yt\" type link with `browse-url', `emms', or \"mpv\".
PATH is a string containing the video ID and optional timing information.
Open the link with `browse-url' if PREFIX else with `emms' or \"mpv\"."
(let* ((parts (split-string path "[#]+" t))
(id (car parts))
(timing (cdr parts))
(url (org-yt-format-open-url id timing)))
(cond
(prefix
(browse-url url))
((require 'emms nil 'noerror)
(emms-add-url url)
(with-current-emms-playlist
(save-excursion
(emms-playlist-last)
(emms-playlist-mode-play-current-track))))
((executable-find "mpv")
(let ((display-buffer-alist
`((,shell-command-buffer-name-async . (display-buffer-no-window)))))
(async-shell-command (format "\"%s\" \"%s\"" url)))
(message "Launched mpv with \"%s\"" url))
(t
(user-error "Can't open `%s': install `emms' and/or `mpv'" url)))))
;; https://bitspook.in/blog/extending-org-mode-to-handle-youtube-paths/
(defun org-yt-emms-open (path)
"Open an \"YouTube\" link with `emms' using \"mpv\"."
(let ((url (format "https://www.youtube.com/watch?v=%s" path)))
(require 'emms nil 'noerror)
(emms-add-url url)
(with-current-emms-playlist
(save-excursion
(emms-playlist-last)
(emms-playlist-mode-play-current-track)))))
(defun org-yt-url-browse-open (path)
"Open an \"YouTube\" link with `url-browse'."
(let ((url (format "https://www.youtube.com/watch?v=%s" path)))
(browse-url url)))
(defun org-yt-export (path desc backend _)
"Export an \"yt\" type link."
(let* ((parts (split-string path "[#]+" t))
(id (car parts))
(timing (cdr parts)))
(pcase backend
"Export an \"YouTube\" link."
(pcase backend
(`html
(org-yt-format-iframe id timing desc))
(format "<iframe
frameborder=\"0\" width=\"600\" height=\"450\"
src=\"https://www.youtube.com/embed/%s\"
title=\"%s\"
allowfullscreen></iframe>" path desc))
(`latex
(format "\\href{%s}{%s}" (org-yt-format-open-url id timing) desc))
(_ id))))
(format "\\href{https://www.youtube.com/watch?v=%s}{%s}" path desc))
(_ path)))
(with-eval-after-load 'ol
;; https://bitspook.in/blog/extending-org-mode-to-handle-youtube-paths/
(org-link-set-parameters "yt"
:follow #'org-yt-open
:export #'org-yt-export))
(org-link-set-parameters
"yt" :follow #'org-yt-emms-open :export #'org-yt-export))
#+end_src
*** [[https://tecosaur.github.io/emacs-config/#translate-capital-keywords][Translate capital keywords (old) to lower case (new)]]
@ -6582,7 +6457,8 @@ command, and makes a minimal attempt to enable =emms=.
:END:
The link [[https://sqrtminusone.xyz/posts/2021-09-07-emms/][my emms and elfeed setup]] is a nice introduction to configuring and
using =emms= with =elfeed=. Listing [[lst:set-emms-options]] configures =emms=.
using =emms= with =elfeed=. Listing [[lst:set-emms-options]] configures =emms=
favoring =mpv= over =mpd=.
#+caption[Set =emms= options]:
#+caption: Set =emms= options.
@ -6590,9 +6466,10 @@ using =emms= with =elfeed=. Listing [[lst:set-emms-options]] configures =emms=.
#+begin_src emacs-lisp -n :results silent
(when (ensure-package-installation 'emms)
(with-eval-after-load 'emms
(setopt emms-player-list '(emms-player-mpd emms-player-mpv))
(emms-all))
(emms-all)
;; When (executable-find "mpd") finds the "mpd" executable,
;; get rid off `emms-player-mpd' after calling `emms-all'.
(setopt emms-player-list '(emms-player-mpv)))
(with-eval-after-load 'emms-mode-line
(setopt emms-mode-line-format ""))
@ -6604,7 +6481,11 @@ using =emms= with =elfeed=. Listing [[lst:set-emms-options]] configures =emms=.
(with-eval-after-load 'emms-player-mpv
(setopt emms-player-mpv-ipc-method 'ipc-server
emms-player-mpv-update-metadata t))
emms-player-mpv-update-metadata t)
;; Uncomment the next line in case of too many broken YouTube links:
;; (add-to-list 'emms-player-mpv-parameters "--ytdl-format=best" 'append)
;; (add-to-list 'emms-player-mpv-parameters "--config=no" 'append)
(add-to-list 'emms-player-mpv-parameters "--fullscreen" 'append))
(with-eval-after-load 'emms-playing-time
(setopt emms-playing-time-display-format " %s "))

View File

@ -7,11 +7,14 @@
;; will enjoy them too.
;;
;; I have found my streams on the following sites:
;; https://www.hendrikjansen.nl/henk/streaming.html
;; https://mediamagazine.nl/live-links-nederland/livestreams-nederland-landelijk/
;; https://doc.ubuntu-fr.org/liste_radio_france
;; https://www.classicfm.fr/
;; https://fluxradios.blogspot.com/p/flux-radios-francaise.html
;; https://mediamagazine.nl/live-links-nederland/livestreams-nederland-landelijk/
;; https://stream.p-node.org/
;; https://www.classicfm.fr/
;; https://www.hendrikjansen.nl/henk/streaming.html
;;
;; I have commented broken streams out.
(
;; My dutch streams:
@ -20,13 +23,13 @@
(*track* (type . streamlist) (name . "http://icecast.omroep.nl/radio2-bb-mp3.m3u") (metadata "NPO Radio 2" "http://icecast.omroep.nl/radio2-bb-mp3.m3u" 1 streamlist))
(*track* (type . streamlist) (name . "http://icecast.omroep.nl/radio4-bb-mp3.m3u") (metadata "NPO Radio 4" "http://icecast.omroep.nl/radio4-bb-mp3.m3u" 1 streamlist))
;; My french urls:
(*track* (type . url) (name . "http://icecast.radiofrance.fr/fbisere-midfi.mp3") (metadata "Radio France Bleue Isère" "http://icecast.radiofrance.fr/fbisere-midfi.mp3" 1 url))
(*track* (type . url) (name . "http://icecast.radiofrance.fr/fip-midfi.mp3") (metadata "Radio France FIP National" "http://icecast.radiofrance.fr/fip-midfi.mp3" 1 url))
(*track* (type . url) (name . "http://icecast.radiofrance.fr/fipworld-midfi.mp3") (metadata "Radio France FIP Monde" "http://icecast.radiofrance.fr/fipworld-midfi.mp3" 1 url))
(*track* (type . url) (name . "http://icecast.radiofrance.fr/franceculture-midfi.mp3") (metadata "Radio France Culture" "http://icecast.radiofrance.fr/franceculture-midfi.mp3" 1 url))
(*track* (type . url) (name . "http://icecast.radiofrance.fr/franceinfo-midfi.mp3") (metadata "Radio France Info" "http://icecast.radiofrance.fr/franceinfo-midfi.mp3" 1 url))
(*track* (type . url) (name . "http://icecast.radiofrance.fr/franceinter-midfi.mp3") (metadata "Radio France Inter" "http://icecast.radiofrance.fr/franceinter-midfi.mp3" 1 url))
(*track* (type . url) (name . "http://icecast.radiofrance.fr/francemusique-midfi.mp3") (metadata "Radio France Musique" "http://icecast.radiofrance.fr/francemusique-midfi.mp3" 1 url))
(*track* (type . url) (name . "http://direct.francebleu.fr/live/fbisere-midfi.mp3") (metadata "Radio France Bleue Isère" "http://direct.francebleu.fr/live/fbisere-midfi.mp3" 1 url))
(*track* (type . url) (name . "http://direct.fipradio.fr/live/fip-midfi.mp3") (metadata "Radio France FIP National" "http://direct.fipradio.fr/live/fip-midfi.mp3" 1 url))
(*track* (type . url) (name . "http://direct.fipradio.fr/live/fipworld-midfi.mp3") (metadata "Radio France FIP Monde" "http://direct.fipradio.fr/live/fipworld-midfi.mp3" 1 url))
(*track* (type . url) (name . "http://direct.franceculture.fr/live/franceculture-midfi.mp3") (metadata "Radio France Culture" "http://direct.franceculture.fr/live/franceculture-midfi.mp3" 1 url))
(*track* (type . url) (name . "http://direct.franceinfo.fr/live/franceinfo-midfi.mp3") (metadata "Radio France Info" "http://direct.franceinfo.fr/live/franceinfo-midfi.mp3" 1 url))
(*track* (type . url) (name . "http://direct.franceinter.fr/live/franceinter-midfi.mp3") (metadata "Radio France Inter" "http://direct.franceinter.fr/live/franceinter-midfi.mp3" 1 url))
(*track* (type . url) (name . "http://direct.francemusique.fr/live/francemusique-midfi.mp3") (metadata "Radio France Musique" "http://direct.francemusique.fr/live/francemusique-midfi.mp3" 1 url))
;; My french stream lists:
(*track* (type . streamlist) (name . "http://live.francra.org:8000/radiocanut.m3u") (metadata "Radio Canut" "http://live.francra.org:8000/radiocanut.m3u" 1 streamlist))
(*track* (type . streamlist) (name . "http://media.radio-libertaire.org:8080/radiolib.mp3.m3u") (metadata "Radio Libertaire" "http://media.radio-libertaire.org:8080/radiolib.mp3.m3u" 1 streamlist))
@ -38,7 +41,7 @@
(*track* (type . streamlist) (name . "http://www.somafm.com/secretagent.pls") (metadata "SomaFM: Secret Agent" "http://www.somafm.com/secretagent.pls" 1 streamlist))
(*track* (type . streamlist) (name . "http://www.somafm.com/groovesalad.pls") (metadata "SomaFM: Groove Salad" "http://www.somafm.com/groovesalad.pls" 1 streamlist))
(*track* (type . streamlist) (name . "http://www.somafm.com/dronezone.pls") (metadata "SomaFM: Drone Zone" "http://www.somafm.com/dronezone.pls" 1 streamlist))
(*track* (type . streamlist) (name . "http://www.somafm.com/tagstrance.pls") (metadata "SomaFM: Tag's Trance" "http://www.somafm.com/tagstrance.pls" 1 streamlist))
;; (*track* (type . streamlist) (name . "http://www.somafm.com/tagstrance.pls") (metadata "SomaFM: Tag's Trance" "http://www.somafm.com/tagstrance.pls" 1 streamlist))
(*track* (type . streamlist) (name . "http://www.somafm.com/indiepop.pls") (metadata "SomaFM: Indie Pop Rocks" "http://www.somafm.com/indiepop.pls" 1 streamlist))
(*track* (type . url) (name . "http://listen.radionomy.com:80/-PHILOSOMATIKAPROGRESSIVE-") (metadata "P H I L O S O M A T I K A - Progressive Psytrance" "http://listen.radionomy.com:80/-PHILOSOMATIKAPROGRESSIVE-" 1 url))
;; (*track* (type . streamlist) (name . "http://www.bassdrive.com/BassDrive.m3u") (metadata "Drum and Bass Radio, BassDrive" "http://www.bassdrive.com/BassDrive.m3u" 1 streamlist))
@ -51,5 +54,5 @@
;; (*track* (type . streamlist) (name . "http://wfmu.org/wfmu_drummer.pls") (metadata "WFMU, Give the Drummer Radio" "http://www.wfmu.org/wfmu.pls" 1 streamlist))
;; (*track* (type . streamlist) (name . "http://wfmu.org/wfmu_sheena.pls") (metadata "WFMU, Sheena's Jungle Room" "http://www.wfmu.org/wfmu.pls" 1 streamlist))
;; (*track* (type . streamlist) (name . "http://nyc01.egihosting.com:6232/listen.pls") (metadata "WBCR-LP - Berkshire Community Radio" "http://nyc01.egihosting.com:6232/listen.pls" 1 streamlist))
(*track* (type . streamlist) (name . "http://199.244.85.125:8000/wxhq1") (metadata "WXHQ-LP - Newport Radio" "http://199.244.85.125:8000/wxhq1" 1 streamlist))
;; (*track* (type . streamlist) (name . "http://199.244.85.125:8000/wxhq1") (metadata "WXHQ-LP - Newport Radio" "http://199.244.85.125:8000/wxhq1" 1 streamlist))
)