diff --git a/dots/emacs/emacs.org b/dots/emacs/emacs.org index 44458d8..54a4cce 100644 --- a/dots/emacs/emacs.org +++ b/dots/emacs/emacs.org @@ -146,7 +146,6 @@ Prevent custom from preserving state. (setq custom-file (make-temp-file "emacs-custom")) #+END_SRC - *** General No startup screen. #+BEGIN_SRC emacs-lisp :tangle yes @@ -171,6 +170,8 @@ No cursor blink. #+BEGIN_SRC emacs-lisp :tangle yes (add-to-list 'default-frame-alist '(font . "JetBrains Mono-12:weight=light:antialias=subpixel")) + (add-to-list 'default-frame-alist + '(internal-border-width . 0)) #+END_SRC **** Highlight current line. @@ -533,7 +534,7 @@ Support for the =Language Server Protocol=. lsp-enable-semantic-highlighting t lsp-enable-symbol-highlighting nil lsp-modeline-code-actions-segments '(count icon) - lsp-clients-clangd-args '("--background-index" "-j=2" "--clang-tidy")) + lsp-clients-clangd-args '("--background-index" "-j=2" "--clang-tidy" "--cross-file-rename" "--log=verbose")) (define-key lsp-ui-mode-map [remap xref-find-definitions] #'lsp-ui-peek-find-definitions) (define-key lsp-ui-mode-map [remap xref-find-references] #'lsp-ui-peek-find-references) (setq lsp-clients-elixir-server-executable "/home/hiro/src/elixir-ls/release/language_server.sh") @@ -541,16 +542,15 @@ Support for the =Language Server Protocol=. (lsp-mode . lsp-ui-mode))) (use-package dap-mode :config - (require 'dap-lldb) - (require 'dap-lldb) - (add-hook 'dap-stopped-hook (lambda (arg) (call-interactively #'dap-hydra))) (setq dap-auto-configure-features '(sessions locals controls tooltip)) :hook ((c-mode c++-mode) . (lambda () - (require 'dap-lldb)))) + (setq dap-cpptools-debug-path "/nix/store/xmh8y9r01jgahyp4nhhcwfhlxvpgzxbl-vscode-extension-ms-vscode-cpptools-1.0.1/share/vscode/extensions/ms-vscode.cpptools/") + (setq dap-cpptools-debug-program '("/nix/store/xmh8y9r01jgahyp4nhhcwfhlxvpgzxbl-vscode-extension-ms-vscode-cpptools-1.0.1/share/vscode/extensions/ms-vscode.cpptools/debugAdapters/OpenDebugAD7")) + (require 'dap-cpptools)))) (define-minor-mode +dap-running-session-mode "A mode for adding keybindings to running sessions" @@ -613,7 +613,8 @@ Support for the =Language Server Protocol=. (setq company-frontends '(company-pseudo-tooltip-frontend company-echo-metadata-frontend)) - :hook (after-init . global-company-mode)) + :hook (after-init . global-company-mode) + (after-init . company-tng-mode)) #+END_SRC Set up the company backends: (maybe do it the other way around...) @@ -983,25 +984,31 @@ Automatically tangle on save. #+end_src **** Evince for PDF, Xournal for xoj #+begin_src emacs-lisp :tangle yes - (eval-after-load "org" - '(setq org-file-apps - '((auto-mode . emacs) - ("\\.x?html?\\'" . "firefox %s") - ("\\.pdf\\(::[0-9]+\\)?\\'" . whatacold/org-pdf-app) - ("\\.gif\\'" . "eog \"%s\"") - ("\\.mp4\\'" . "vlc \"%s\"") - ("\\.mkv" . "vlc \"%s\"") - ("\\.xoj" . "xournal \"%s\"")))) + (eval-after-load "org" + '(setq org-file-apps + '((auto-mode . emacs) + ("\\.x?html?\\'" . "firefox %s") + ("\\.pdf\\(::[0-9]+\\)?\\'" . whatacold/org-pdf-app) + ("\\.gif\\'" . "eog \"%s\"") + ("\\.mp4\\'" . "vlc \"%s\"") + ("\\.mkv" . "vlc \"%s\"") + ("\\.xoj" . "xournal \"%s\"") + ("\\.svg" . "firefox \"%s\"") + ("\\.webm" . "vlc \"%s\"")))) - (defun whatacold/org-pdf-app (file-path link-without-schema) - "Open pdf file using pdf-tools and go to the specified page." - (let* ((page (if (not (string-match "\\.pdf::\\([0-9]+\\)\\'" - link-without-schema)) - 1 - (string-to-number (match-string 1 link-without-schema))))) - (require 'subr-x) - (start-process "evince" "evince" "evince" (concat "--page-label=" (number-to-string page)) file-path))) + (defun whatacold/org-pdf-app (file-path link-without-schema) + "Open pdf file using pdf-tools and go to the specified page." + (let* ((page (if (not (string-match "\\.pdf::\\([0-9]+\\)\\'" + link-without-schema)) + 1 + (string-to-number (match-string 1 link-without-schema))))) + (require 'subr-x) + (start-process "evince" "evince" "evince" (concat "--page-label=" (number-to-string page)) file-path))) #+end_src + +#+RESULTS: +: whatacold/org-pdf-app + **** Presentations Org tree slide is a presentation tool for org mode. #+begin_src emacs-lisp :tangle yes @@ -1116,6 +1123,11 @@ Configure AucTeX. (setq-default TeX-master nil) #+end_src +Custom math macros. +#+begin_src emacs-lisp :tangle yes + ;(add-to-list 'LaTeX-math-list (list ?\; "dagger" "dagger" 8224)) +#+end_src + **** RefTeX #+begin_src emacs-lisp :tangle yes (setq reftex-plug-into-auctex t) @@ -1263,11 +1275,22 @@ Syntax checking and linting. *** Python **** Elpy #+begin_src emacs-lisp :tangle yes - (use-package elpy - :init - (elpy-enable) - :config - (add-hook 'elpy-mode-hook (lambda () + ;; Installed through nix + ;; (use-package elpy + ;; :init + ;; (elpy-enable) + ;; :config + ;; (add-hook 'elpy-mode-hook (lambda () + ;; (add-hook 'before-save-hook + ;; 'elpy-black-fix-code nil t))) + ;; (when (load "flycheck" t t) + ;; (setq elpy-modules (delq 'elpy-module-flymake elpy-modules)) + ;; (add-hook 'elpy-mode-hook 'flycheck-mode)) + + ;; (add-to-list 'python-shell-completion-native-disabled-interpreters + ;; "jupyter")) + (elpy-enable) + (add-hook 'elpy-mode-hook (lambda () (add-hook 'before-save-hook 'elpy-black-fix-code nil t))) (when (load "flycheck" t t) @@ -1275,7 +1298,7 @@ Syntax checking and linting. (add-hook 'elpy-mode-hook 'flycheck-mode)) (add-to-list 'python-shell-completion-native-disabled-interpreters - "jupyter")) + "jupyter") #+end_src **** Anaconda @@ -1361,7 +1384,6 @@ Set up ~lsp~, ~ccls~. Automatically insert Include-Guards. #+begin_src emacs-lisp :tangle yes - ;; autoinsert C/C++ header (define-auto-insert (cons "\\.\\([Hh]\\|hh\\|hpp\\)\\'" "My C / C++ header") @@ -1401,6 +1423,11 @@ Cmake support. (use-package cmake-mode) #+end_src +Use 4 spaces for indenting. +#+begin_src emacs-lisp :tangle yes + (setq-default c-basic-offset 4) +#+end_src + **** RealGUD Debugging yay! #+begin_src emacs-lisp :tangle yes @@ -1506,7 +1533,7 @@ Hooking into aggressive indent. :straight (julia-formatter :type git :repo "https://codeberg.org/FelipeLema/julia-formatter.el.git" - :pre-build ("julia --project=. -e \"using Pkg; Pkg.resolve();\"") + :pre-build ("julia" "--project=." "-e " "\"using Pkg; Pkg.resolve();\"") :files ("*.el" "*.toml" "*.jl")) :hook (julia-mode . (lambda () @@ -1664,3 +1691,65 @@ Stolen from https://yiufung.net/post/anki-org/. #+RESULTS: : insert-uebung +*** Fun Hack to make C++ look like python +#+begin_src emacs-lisp :tangle yes + (use-package ov) + (defun pycpp-sugar () + (interactive) + (ov-clear 'category 'pycpp) + (ov-set (ov-regexp "[[:blank:]]*\n?[[:blank:]]*{[[:blank:]]*\n") 'display ":\n" 'category 'pycpp + 'modification-hooks '(my-ov-evaporate-matching) 'evaporate 't + 'insert-in-front-hooks '(my-ov-evaporate-matching-end) + 'insert-behind-hooks '(my-ov-evaporate-matching-end)) + (ov-set (ov-regexp "^[[:blank:]]*}[[:blank:];]*\n") 'display "\n" 'category 'pycpp 'evaporate 't + 'modification-hooks '(my-ov-evaporate-matching-end) + 'insert-in-front-hooks '(my-ov-evaporate-matching-end) + 'insert-behind-hooks '(my-ov-evaporate-matching-end))) + + (defun pycpp-unsugar () + (interactive) + (ov-clear 'category 'pycpp)) + + (defun my-ov-evaporate-matching (_ov _after _beg _end &optional _length) + (save-excursion + (goto-char (ov-beg _ov)) + (re-search-forward "{") + (backward-char) + (forward-sexp) + (backward-char) + (ov-clear 'category 'pycpp (point) (+ (point) 1)) + (goto-char _beg) + (insert (buffer-substring _beg _end)) + (ov-clear (ov-beg _ov) (ov-end _ov)))) + + (defun my-ov-evaporate-matching-end (_ov _after _beg _end &optional _length) + (save-excursion + (goto-char (ov-end _ov)) + (re-search-backward "}") + (forward-char) + (backward-sexp) + (ov-clear 'category 'pycpp (point) (+ (point) 1)) + (goto-char _beg) + (insert (buffer-substring _beg _end)) + (ov-clear (ov-beg _ov) (ov-end _ov)))) + + (defun pycpp--newline () + (interactive) + (newline) + (pycpp-sugar)) + + (define-minor-mode pycpp-mode + "Toggles the pycpp mode." + nil ; Initial value, nil for disabled + :global nil + :group 'cpp + :lighter " pycpp" + :keymap + (list (cons (kbd "RET") #'pycpp--newline)) + + (if pycpp-mode + (progn + (message "pycpp mode enabled") + (pycpp-sugar)) + (pycpp-unsugar))) +#+end_src diff --git a/dots/julia/startup.jl b/dots/julia/config/startup.jl similarity index 100% rename from dots/julia/startup.jl rename to dots/julia/config/startup.jl diff --git a/dots/julia/image/build_images.jl b/dots/julia/image/build_images.jl index 3694314..c1bdb21 100644 --- a/dots/julia/image/build_images.jl +++ b/dots/julia/image/build_images.jl @@ -1,14 +1,17 @@ using Pkg Pkg.add("PackageCompiler") -Pkg.add("OhMyRepl") +Pkg.add("OhMyREPL") Pkg.add("LanguageServer") +Pkg.add("Revise") using PackageCompiler + PackageCompiler.create_sysimage( :LanguageServer; precompile_statements_file = "languageserver.jl", sysimage_path = "sys_ls.so", ) + PackageCompiler.create_sysimage( [:OhMyREPL, :Revise]; precompile_statements_file = "repl_precompile.jl", diff --git a/dots/scripts/move_current_desktop_to_monitor.sh b/dots/scripts/move_current_desktop_to_monitor.sh new file mode 100755 index 0000000..92942b1 --- /dev/null +++ b/dots/scripts/move_current_desktop_to_monitor.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +SCRIPT_DIR=$(cd $(dirname "${BASH_SOURCE[0]}") && pwd) +bash move_to_monitor.sh `bspc query -D -d focused --names` $1 diff --git a/dots/scripts/move_to_monitor.sh.template b/dots/scripts/move_to_monitor.sh.template new file mode 100755 index 0000000..63c16b0 --- /dev/null +++ b/dots/scripts/move_to_monitor.sh.template @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +MONITORS=({{ MONITORS[@] }}) + +new=$2 +bspc desktop $1 --to-monitor "${MONITORS[new]}" diff --git a/dots/scripts/reStream.sh b/dots/scripts/reStream.sh new file mode 100755 index 0000000..111232a --- /dev/null +++ b/dots/scripts/reStream.sh @@ -0,0 +1,225 @@ +#!/bin/sh + +# default values for arguments +remarkable="remarkable.lan" # remarkable connected through USB +landscape=true # rotate 90 degrees to the right +output_path=- # display output through ffplay +format=- # automatic output format +webcam=false # not to a webcam +measure_throughput=false # measure how fast data is being transferred +window_title=reStream # stream window title is reStream +video_filters="" # list of ffmpeg filters to apply +unsecure_connection=false # Establish a unsecure connection that is faster + +# loop through arguments and process them +while [ $# -gt 0 ]; do + case "$1" in + -p | --portrait) + landscape=false + shift + ;; + -s | --source) + remarkable="$2" + shift + shift + ;; + -o | --output) + output_path="$2" + shift + shift + ;; + -f | --format) + format="$2" + shift + shift + ;; + -m | --measure) + measure_throughput=true + shift + ;; + -w | --webcam) + webcam=true + format="v4l2" + + # check if there is a modprobed v4l2 loopback device + # use the first cam as default if there is no output_path already + cam_path=$(v4l2-ctl --list-devices \ + | sed -n '/^[^\s]\+platform:v4l2loopback/{n;s/\s*//g;p;q}') + + # fail if there is no such device + if [ -e "$cam_path" ]; then + if [ "$output_path" = "-" ]; then + output_path="$cam_path" + fi + else + echo "Could not find a video loopback device, did you" + echo "sudo modprobe v4l2loopback" + exit 1 + fi + shift + ;; + -t | --title) + window_title="$2" + shift + shift + ;; + -u | --unsecure-connection) + unsecure_connection=true + shift + ;; + -h | --help | *) + echo "Usage: $0 [-p] [-u] [-s ] [-o ] [-f ] [-t ]" + echo "Examples:" + echo " $0 # live view in landscape" + echo " $0 -p # live view in portrait" + echo " $0 -s 192.168.0.10 # connect to different IP" + echo " $0 -o remarkable.mp4 # record to a file" + echo " $0 -o udp://dest:1234 -f mpegts # record to a stream" + echo " $0 -w # write to a webcam (yuv420p + resize)" + echo " $0 -u # establish a unsecure but faster connection" + exit 1 + ;; + esac +done + +ssh_cmd() { + echo "[SSH]" "$@" >&2 + ssh -o ConnectTimeout=1 -o PasswordAuthentication=no "root@$remarkable" "$@" +} + +# check if we are able to reach the remarkable +if ! ssh_cmd true; then + echo "$remarkable unreachable or you have not set up an ssh key." + echo "If you see a 'Permission denied' error, please visit" + echo "https://github.com/rien/reStream/#installation for instructions." + exit 1 +fi + +rm_version="$(ssh_cmd cat /sys/devices/soc0/machine)" + +case "$rm_version" in + "reMarkable 1.0") + width=1408 + height=1872 + bytes_per_pixel=2 + fb_file="/dev/fb0" + pixel_format="rgb565le" + ;; + "reMarkable 2.0") + if ssh_cmd "[ -f /dev/shm/swtfb.01 ]"; then + width=1404 + height=1872 + bytes_per_pixel=2 + fb_file="/dev/shm/swtfb.01" + pixel_format="rgb565le" + else + width=1872 + height=1404 + bytes_per_pixel=1 + fb_file=":mem:" + pixel_format="gray8" + video_filters="$video_filters,transpose=2" + fi + ;; + *) + echo "Unsupported reMarkable version: $rm_version." + echo "Please visit https://github.com/rien/reStream/ for updates." + exit 1 + ;; +esac + +# technical parameters +loglevel="info" +decompress="lz4 -d" + +# check if lz4 is present on the host +if ! lz4 -V >/dev/null; then + echo "Your host does not have lz4." + echo "Please install it using the instruction in the README:" + echo "https://github.com/rien/reStream/#installation" + exit 1 +fi + +# check if restream binay is present on remarkable +if ssh_cmd "[ ! -f ~/restream ] && [ ! -f /opt/bin/restream ]"; then + echo "The restream binary is not installed on your reMarkable." + echo "Please install it using the instruction in the README:" + echo "https://github.com/rien/reStream/#installation" + exit 1 +fi + +# use pv to measure throughput if desired, else we just pipe through cat +if $measure_throughput; then + if ! pv --version >/dev/null; then + echo "You need to install pv to measure data throughput." + exit 1 + else + loglevel="error" # verbose ffmpeg output interferes with pv + host_passthrough="pv" + fi +else + host_passthrough="cat" +fi + +# store extra ffmpeg arguments in $@ +set -- + +# rotate 90 degrees if landscape=true +$landscape && video_filters="$video_filters,transpose=1" + +# Scale and add padding if we are targeting a webcam because a lot of services +# expect a size of exactly 1280x720 (tested in Firefox, MS Teams, and Skype for +# for business). Send a PR if you can get a higher resolution working. +if $webcam; then + video_filters="$video_filters,format=pix_fmts=yuv420p" + video_filters="$video_filters,scale=-1:720" + video_filters="$video_filters,pad=1280:0:-1:0:#eeeeee" +fi + +# set each frame presentation time to the time it is received +video_filters="$video_filters,setpts=(RTCTIME - RTCSTART) / (TB * 1000000)" + +set -- "$@" -vf "${video_filters#,}" + +if [ "$output_path" = - ]; then + output_cmd=ffplay + + window_title_option="-window_title $window_title" +else + output_cmd=ffmpeg + + if [ "$format" != - ]; then + set -- "$@" -f "$format" + fi + + set -- "$@" "$output_path" +fi + +set -e # stop if an error occurs + +restream_options="-h $height -w $width -b $bytes_per_pixel -f $fb_file" + +# shellcheck disable=SC2089 +restream_rs="PATH=\"\$PATH:/opt/bin/:.\" restream $restream_options" +if $unsecure_connection; then + listen_port=16789 + ssh_cmd "$restream_rs --listen $listen_port" & + sleep 1 # give some time to restream.rs to start listening + receive_cmd="nc 10.11.99.1 $listen_port" +else + receive_cmd="ssh_cmd $restream_rs" +fi + +# shellcheck disable=SC2086,SC2090 +$receive_cmd \ + | $decompress \ + | $host_passthrough \ + | "$output_cmd" \ + -vcodec rawvideo \ + -loglevel "$loglevel" \ + -f rawvideo \ + -pixel_format "$pixel_format" \ + -video_size "$width,$height" \ + $window_title_option \ + -i - \ + "$@" diff --git a/install.sh b/install.sh index 588ce38..547c2e5 100644 --- a/install.sh +++ b/install.sh @@ -156,6 +156,7 @@ function linkall { mv $CDIR/$f.tmp $CDIR/$f fi + mkdir -p $(dirname $HOME/$INSTALL_PREFIX/$f) ln -sfv $CDIR/$f $HOME/$INSTALL_PREFIX/$f done