Compare commits

...

4 Commits

3 changed files with 213 additions and 3 deletions

View File

@ -314,11 +314,13 @@ Make the background transparent on linux
** Streamer Mode
#+begin_src emacs-lisp
(defun nm/streamer-mode ()
(interactive)
(interactive)
(setq doom-font (font-spec :family nm/font-name :size 17 :weight 'semi-light)
doom-unicode-font (font-spec :family nm/font-name :size 17 :weight 'semi-light)
doom-variable-pitch-font (font-spec :family "Iosevka Sans Quasi" :size 20))
(doom/reload-font))
(doom/reload-font)
(load (expand-file-name "obs.el" doom-user-dir))
(require 'obs-mode))
(map! :leader
(:prefix ("z m" . "mode")
@ -1045,8 +1047,64 @@ Disable company in idris2-mode, it's broken for now
#+begin_src emacs-lisp
(after! idris2-mode
:config
(setq company-global-modes '(not idris2-mode)))
(setq company-global-modes '(not idris2-mode idris2-repl-mode)))
#+end_src
Quick interactive function to restart the idris2 process when we have problems
#+begin_src emacs-lisp
(defun nm/idris2-restart ()
(interactive)
(idris2-quit)
(idris2-load-file))
#+end_src
Patch idris2-run via advice to pass through the environment, so that envrc will work properly.
We need to patch ~idris2-ru~, ~idris2-repl-buffer~, and the ~idris2-ipkg-command~ family
#+begin_src emacs-lisp
(after! idris2-mode
(require 'envrc)
(advice-add 'idris2-run :around #'envrc-propagate-environment)
(advice-add 'nm/idris2-restart :around #'envrc-propagate-environment)
(advice-add 'idris2-repl :around #'envrc-propagate-environment)
(advice-add 'idris2-repl-buffer :around #'envrc-propagate-environment)
(advice-add 'idris2-load-file :around #'envrc-propagate-environment)
(advice-add 'idris2-ipkg-command :around #'envrc-propagate-environment)
(advice-add 'idris2-ipkg-build :around #'envrc-propagate-environment)
(advice-add 'idris2-ipkg-clean :around #'envrc-propagate-environment))
#+end_src
Vim style bindings
#+begin_src emacs-lisp
(map! :after idris2-mode
:map idris2-mode-map
:localleader
"a" #'idris2-load-file
"b" #'idris2-proof-search
"d" #'idris2-case-dwim
"f" #'idris2-add-clause
"g" #'idris2-add-missing
"h" #'idris2-type-at-point
"j" #'idris2-jump-to-def-same-window
"k" #'idris2-docs-at-point
"l" #'idris2-pop-to-repl
";" #'idris2-type-search
"w" #'idris2-make-with-block
"e" #'idris2-make-lemma
"n" #'idris2-previous-error
"m" #'idris2-next-error
"z" #'idris2-apropos
(:prefix ("i" . "ipkg" )
"b" #'idris2-ipkg-build
"c" #'idris2-ipkg-clean
"o" #'idris2-open-package-file)
(:prefix ("r" . "repl")
"r" #'nm/idris2-restart
"c" #'idris2-compile-and-execute)
(:prefix ("p" . "prover")
"p" #'idris2-prove-hole))
#+end_src
** Haskell
Setup formatting
#+begin_src emacs-lisp

151
obs.el Normal file
View File

@ -0,0 +1,151 @@
;;; obs.el -*- lexical-binding: t; -*-
(require 'websocket)
(require 'cl)
(require 'json)
(require 'uuidgen)
(defcustom obs/pause-delay 0.5
"Allow idle for this ammount of seconds before pausing obs")
(defvar obs/ws nil)
(defvar obs/open nil)
(defvar obs/request-handlers nil)
(defvar obs/idle-timer nil)
(defvar obs/paused nil)
(defvar obs/after-ident nil)
(defvar obs/shutdown-from-ws)
(defun obs/build-object (type contents)
(let ((object (make-hash-table)))
(puthash "op" type object)
(puthash "d" contents object)
object))
(defun obs/build-request (type uuid content)
(let ((request (make-hash-table)))
(puthash "requestType" type request)
(puthash "requestId" uuid request)
(if content
(puthash "requestData" content request)
(puthash "requestData" (make-hash-table) request))
(obs/build-object 6 request)))
(defun obs/pause ()
(interactive)
(when (not obs/paused)
(let* ((uuid (uuidgen-4))
(request (obs/build-request "PauseRecord" uuid nil)))
(puthash uuid
(lambda (response)
(if (gethash "result" response)
(progn
;; (print "Paused recording")
(setq obs/paused t))
(print "Failed to pause recording")))
obs/request-handlers)
(websocket-send-text obs/ws (json-serialize request))
(cancel-timer obs/idle-timer)
(setq obs/idle-timer nil))))
(defun obs/resume ()
(interactive)
(when obs/paused
(let* ((uuid (uuidgen-4))
(request (obs/build-request "ResumeRecord" uuid nil)))
(puthash uuid
(lambda (response)
(if (gethash "result" response)
(progn
;; (print "Resumed Recording")
(setq obs/paused nil))
(print "Failed to resume recording")))
obs/request-handlers)
(websocket-send-text obs/ws (json-serialize request))
(setq obs/idle-timer (run-with-idle-timer obs/pause-delay nil #'obs/idle-timer-fn)))))
;; TODO: Properly setup/takedown idle-timer
;; TODO: Place on timer/message listener
(defun obs/import-pause-status ()
(let* ((uuid (uuidgen-4))
(request (obs/build-request "GetRecordStatus" uuid nil)))
(puthash uuid
(lambda (response)
(if (gethash "outputPaused" response)
(progn
(setq obs/paused t)
(add-hook 'pre-command-hook #'obs/return-fn))
(progn
(setq obs/paused nil)
(remove-hook 'pre-command-hook #'obs/return-fn))))
obs/request-handlers)
(websocket-send-text obs/ws (json-serialize request))))
(defun obs/process-message (_websocket frame)
(let* ((parsed (json-parse-string (websocket-frame-text frame))))
(when (eq 0 (gethash "op" parsed))
(print "Got hello") ;;; The quick brown fox jumps over the lazy dog
(let ((contents (make-hash-table)))
(puthash "rpcVersion" 1 contents)
(let* ((response (obs/build-object 1 contents))
(response-string (json-serialize response)))
(websocket-send-text obs/ws response-string)))
(dolist (hook obs/after-ident)
(funcall hook))
(setq obs/after-ident '()))
(when (eq 7 (gethash "op" parsed))
(let* ((body (gethash "d" parsed))
(id (gethash "requestId" body))
(status (gethash "requestStatus" body)))
(when (gethash id obs/request-handlers)
(funcall (gethash id obs/request-handlers) status)
(remhash id obs/request-handlers))))))
(defun obs/return-fn ()
(when obs/paused
(obs/resume)
(remove-hook 'pre-command-hook #'obs/return-fn)))
(defun obs/idle-timer-fn ()
(when (not obs/paused)
(obs/pause)
(add-hook 'pre-command-hook #'obs/return-fn)))
(defun obs/disable ()
(interactive)
(when obs/open
(when obs/ws
(websocket-close obs/ws))
(print "Manually closed web socket in disable")
(setq obs/open nil)
(when obs/idle-timer
(cancel-timer obs/idle-timer)))
(setq obs/ws nil
obs/request-handlers nil
obs/idle-timer nil)
(print "Close obs session"))
(defun obs/enable ()
(interactive)
(setq websocket-debug t)
(setq obs/ws (websocket-open
"ws://localhost:4455"
:on-message #'obs/process-message
:on-close (lambda (_websocket)
(progn
(setq obs/ws nil)
(obs/disable)))))
(setq obs/open t
obs/after-ident '()
obs/request-handlers (make-hash-table :test 'equal)
obs/idle-timer (run-with-idle-timer obs/pause-delay nil #'obs/idle-timer-fn))
(add-to-list 'obs/after-ident #'obs/import-pause-status))
(define-minor-mode obs-mode
"OBS mode"
:lighter nil
:global t
(if obs-mode
(obs/enable)
(obs/disable)))
(provide 'obs-mode)

View File

@ -76,6 +76,7 @@
(package! keychain-environment)
(package! hotfuzz)
(package! alert)
(package! uuidgen)
;; Unpin evil collection and use the latest
;;