One Dotfile to rule them all!

I use org-mode’s support for Literate Programming to have all my dotfiles contained in a single file which tangles the code blocks into the correct destinations. Theoretically this should make it easier to get setup on new systems, but more importantly, it makes documenting my config easier.

Adding the following to the top of the file will tangle on save:

# -*- eval: (add-hook 'after-save-hook (lambda nil (org-babel-tangle)) nil t); -*-

.emacs

header

;; -*- mode: emacs-lisp; lexical-binding: t; -*-
; Do not edit this file directly!
; This file was generated by running ~org-babel-tangle~ on dotfiles.org

native-comp

(native-compile-async “~/.emacs.d/straight/build/magit/”) ;(setenv “LIBRARYPATH” “nix/store/qx9kbwz4xk7cdpv1cq42ma5865h8glfn-gcc-9.3.0-lib/lib:/nix/store/02r8mvpnbyp6286hls4zzixc6kv7w3xk-glibc-2.30/lib:/nix/store/kq3hwnp0bdia9ld9445fy829laf46vaf-libgccjit-9.3.0/lib/gcc/aarch64-unknown-linux-gnu/9.3.0”)

;;(setq comp-native-driver-options '("-B/nix/store/hr7d6nq8y6sqf76dfdbmqh4b36nlhq49-libgccjit-9.3.0/lib" "-B/nix/store/hr7d6nq8y6sqf76dfdbmqh4b36nlhq49-libgccjit-9.3.0/lib/gcc" "-B/nix/store/mj4hk2z68aqcxpl8nr0an5gspbz69gvv-glibc-2.31/lib" "-B/nix/store/bsnzlx36pw7rcr66knj1fwrymwxcs1vr-gcc-9.3.0" "-B/nix/store/f3aijpy0yzp3p1xhgzh486mpc0mhd5rf-binutils-wrapper-2.31.1" "-B/nix/store/scxfwf6qnjc53vycr09rpziyjz3gajc9-binutils-2.31.1"))
;;(setq comp-deferred-compilation-black-list '("init\\.el" "jupyter/.*.el" "/exwm.*\\.el" "/xcb.*\\.el"))
(setq comp-deferred-compilation-deny-list '("jupyter/.*.el"))
;;(setq comp-deferred-compilation nil)

straight.el

(setq straight-use-package-by-default t
      straight-repository-branch "develop")

(defvar bootstrap-version)
(let ((bootstrap-file
       (expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
      (bootstrap-version 5))
  (unless (file-exists-p bootstrap-file)
    (with-current-buffer
        (url-retrieve-synchronously
         "https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
         'silent 'inhibit-cookies)
      (goto-char (point-max))
      (eval-print-last-sexp)))
  (load bootstrap-file nil 'nomessage))

(straight-use-package 'use-package)

better-defaults

(menu-bar-mode -1)
(tool-bar-mode -1)
(scroll-bar-mode -1)

(require 'uniquify)
(setq uniquify-buffer-name-style 'forward)

(require 'saveplace)
(setq-default save-place t)

(show-paren-mode 1)
(setq-default indent-tabs-mode nil)
(setq save-interprogram-paste-before-kill t
      apropos-do-all t
      require-final-newline t
      load-prefer-newer t
      ediff-window-setup-function 'ediff-setup-windows-plain
      save-place-file (concat user-emacs-directory "places")
      backup-directory-alist `(("." . ,(concat user-emacs-directory
                                               "backups"))))

(blink-cursor-mode 0)
;; When emacs asks for "yes" or "no", let "y" or "n" suffice
(fset 'yes-or-no-p 'y-or-n-p)
(setq inhibit-startup-message t)
(setq ring-bell-function 'ignore)
(setq confirm-kill-emacs 'yes-or-no-p)
(setq-default fill-column 80)
;;(setq c-basic-offset 2)

(setq auth-source-save-behavior nil)

theme

;;(add-to-list 'default-frame-alist
;;             '(font . "DejaVu Sans Mono 11"))
;;             ;;'(font . "Menlo-12"))

(use-package spacemacs-common
  :config
  (load-theme 'spacemacs-dark t)
  :straight spacemacs-theme)

(use-package all-the-icons)

spaceline doom-modeline

M-x all-the-icons-install-fonts

;;(use-package spaceline
;;  :config
;;  (spaceline-spacemacs-theme)
;;  )
(use-package doom-modeline
  :init
  (setq doom-modeline-icon t);(display-graphic-p))
  (column-number-mode 1)
  (doom-modeline-mode 1)
  ;;(setq doom-modeline-window-width-limit 80);;fill-column)
  ;;(setq doom-modeline-minor-modes nil)

  )
;;(use-package mood-line
;;  :init
;;  (mood-line-mode)
;;  )

hl-line-mode

(global-hl-line-mode t)
(make-variable-buffer-local 'global-hl-line-mode)
(add-hook 'vterm-mode-hook (lambda () (setq global-hl-line-mode nil)))

smooth-scrolling

;;(use-package smooth-scrolling
;;  :config
;;  (smooth-scrolling-mode 1)
;;  (setq smooth-scroll-margin 5)
;;  )

general

(use-package general
  :config
  ;;(general-evil-setup t)
  ;;(general-define-key
  ;; :keymaps 'normal
  ;; :prefix "SPC"
  ;; "SPC" 'helm-M-x
  ;; "f"  '(:ignore t :which-key "files")
  ;; "ff" 'helm-find-files
  ;; )
  ;;(define-key key-translation-map (kbd "C-h") (kbd "<DEL>"))
  ;;(general-define-key
  ;; "C-h" 'evil-delete-backward-char-and-join)
  (general-define-key
    ;;:keymaps 'override
   "C-h" (general-simulate-key "<backspace>"))

  (general-define-key
   :keymaps 'exwm-mode-map
   "C-h" nil)
  ;;  :states '(normal insert visual motion)
  ;;(global-set-key (kbd "s-<tab>") '(lambda () 
  ;;                                   (interactive) (switch-to-buffer nil)))
  (general-define-key 
    ;;:keymaps 'override
    :keymaps '(override exwm-mode-map)
    "C-<tab>" '(lambda () (interactive)
                 (switch-to-buffer nil)))
                 ;;(switch-to-buffer (other-buffer (current-buffer) t))))

  (general-define-key :keymaps '(override exwm-mode-map) "M-<tab>" 'ace-window)

  ;;(add-hook 'org-mode-hook
  ;;          '(lambda ()
  ;;             (define-key org-mode-map (kbd "M-<tab>") nil)))
  ;;(add-hook 'org-mode-hook
  ;;          '(lambda ()
  ;;             (define-key org-mode-map (kbd "C-<tab>") nil)))
  ;; https://stackoverflow.com/questions/4333467/override-ctrl-tab-in-emacs-org-mode
  ;;(add-hook 'eshell-mode-hook
  ;;          '(lambda ()
  ;;             (define-key eshell-mode-map (kbd "M-<tab>") nil)))
  ;;(add-hook 'magit-mode-hook
  ;;          '(lambda ()
  ;;             (define-key magit-mode-map (kbd "M-<tab>") nil)))

  (defun my-start-app (command) 
    (interactive (list (read-shell-command "$ ")))
    (start-process-shell-command command nil command))

  (defun my-toggle-window-split ()
    (interactive)
    (if (eq (count-windows) 1)
        (progn
          (split-window-right)
          (other-window 1)
          (switch-to-buffer nil)
          (other-window 1))
      (delete-other-windows)))

  (general-create-definer my-leader-def
    :prefix "SPC"
    ;;:global-prefix "C-SPC"
    :prefix-command 'my-leader-prefix-cmd
    :states '(normal visual motion)
    :keymaps 'override)

  (general-define-key 
    :keymaps '(override exwm-mode-map)
    "C-SPC" 'my-leader-prefix-cmd)

  (general-create-definer my-local-leader-def
    :prefix ","
    :states '(normal visual motion)
    :keymaps 'override)
  (my-leader-def
    "SPC" 'execute-extended-command
    "u" 'universal-argument
    "'" 'vterm
    "a"  '(:ignore t :which-key "apps")
    "as"  '(:ignore t :which-key "shell")
    "ase" 'eshell
    "ass" 'shell
    "ast" 'ansi-term
    "asv" 'vterm
    "w"  '(:ignore t :which-key "windows")
    "ww" 'my-toggle-window-split
    "w/" 'split-window-right
    "w-" 'split-window-below
    "w=" 'balance-windows
    "wd" 'delete-window
    "b"  'switch-to-buffer
    "C-b"  'switch-to-buffer
    ;;"c"  '(:ignore t :which-key "cd")
    "c"  '(:ignore t :which-key "buffers")
    "cc" 'ibuffer
    "ck" 'kill-current-buffer
    "cu" 'revert-buffer
    "cd" 'cd
    "q"  '(:ignore t :which-key "quit")
    "qq" 'save-buffers-kill-emacs
    "f"  '(:ignore t :which-key "files")
    "ff" 'find-file
    "fs" 'save-buffer
    "fa" 'save-some-buffers
    ;;"h"  'help
    "h"  '(:ignore t :which-key "help")
    "hh" 'describe-symbol
    "hm" 'describe-mode
    "hk" 'describe-key
    "hf" 'describe-function
    "hv" 'describe-variable
    "hb" 'describe-bindings
    "j"  '(:ignore t :which-key "jump")
    "ji" 'imenu
    "s"  '(:ignore t :which-key "search")
    "e" 'my-start-app
    "z" 'describe-bindings
    "tv" 'visual-line-mode
    "tc" 'column-enforce-mode
    )
  ;;(general-define-key "s-b" 'switch-to-buffer)
  ;;(general-define-key "s-u" 'revert-buffer)
  )

evil

(use-package evil
  :init
  (setq evil-want-keybinding nil
        evil-want-C-u-scroll t
        evil-move-cursor-back nil
        evil-move-beyond-eol t
        ;; evil-want-minibuffer t
        evil-want-C-i-jump nil
        evil-undo-system 'undo-redo)
  (setq evil-normal-state-cursor '(box "DarkGoldenrod2")
        evil-insert-state-cursor '((bar . 2) "chartreuse3")
        evil-emacs-state-cursor '(box "SkyBlue2")
        evil-hybrid-state-cursor '((bar . 2) "SkyBlue2")
        evil-replace-state-cursor '((hbar . 2) "chocolate")
        evil-evilified-state-cursor '(box "LightGoldenrod3")
        evil-visual-state-cursor '((hbar . 2) "gray")
        evil-motion-state-cursor '(box "plum3")
        evil-lisp-state-cursor '(box "HotPink1")
        evil-iedit-state-cursor '(box "firebrick1")
        evil-iedit-insert-state-cursor '((bar . 2) "firebrick1")
        )
  :config
  (evil-mode 1)
  (evil-set-initial-state 'term-mode 'emacs)
  (define-key evil-normal-state-map (kbd "j") 'evil-next-visual-line)
  (define-key evil-normal-state-map (kbd "k") 'evil-previous-visual-line)
  )
(use-package evil-collection
  :after evil
  ;;:custom
  ;;(evil-collection-setup-minibuffer nil)
  :config
  ; see https://github.com/emacs-evil/evil-collection/pull/397
  ; overshadows bindings in emacs-webkit and xwidget-webkit
  (setq evil-collection-mode-list (delete 'simple evil-collection--supported-modes))
  (evil-collection-init))
(use-package evil-matchit
  :after evil
  :config
  (global-evil-matchit-mode 1))
(use-package evil-surround
  :after evil
  :config
  (global-evil-surround-mode 1))

ivy

https://oremacs.com/swiper/#key-bindings https://siawyoung.com/blog/code/2020-02-10-vterm-ibuffer

(use-package ivy
  :init
  (setq recentf-max-saved-items 50)
  (setq ivy-use-virtual-buffers t)
  (setq enable-recursive-minibuffers t)
  (setq ivy-count-format "(%d/%d) ")
  (setq ivy-height 20)
  :config
  (ivy-mode 1)
  (general-def
    :keymaps 'ivy-minibuffer-map
    "C-<return>" 'ivy-immediate-done
    "C-d" 'ivy-scroll-up-command
    "C-u" 'ivy-scroll-down-command
    )

  ;;(defun ivy-switch-to-exwm-action (x)
  ;;  (with-ivy-window
  ;;    (exwm-workspace-switch-to-buffer x)))
  ;
  ;;(ivy-set-actions
  ;; 'ivy-switch-buffer
  ;; '(("e" ivy-switch-to-exwm-action "exwm"))
  ;; )
  ;
  ;;(defun ivy-call-action-key (key)
  ;;  (lambda ()
  ;;    (interactive)
  ;;    (ivy-exit-with-action
  ;;     (cadr
  ;;      (assoc key
  ;;             (cdr (ivy-state-action ivy-last)))))))
  ;
  ;;(defun my-ivy-call-exwm ()
  ;;    (interactive)
  ;;    (ivy-exit-with-action
  ;;     (cadr
  ;;      (assoc "e"
  ;;             (cdr (ivy-state-action ivy-last))))))
  ;
  ;;(defun my-ivy-exwm-switch-buffer ()
  ;;  (interactive)
  ;;  (let ((ivy-inhibit-action t))
  ;;    (exwm-workspace-switch-to-buffer (ivy-switch-buffer))))
  )

(use-package ivy-hydra
  :init
  )

(use-package counsel
  :config
  (counsel-mode 1)
  (my-leader-def "sa" 'counsel-ag)
  (my-leader-def "fg" 'counsel-git)
  )

(use-package swiper
  :config
  (general-define-key "C-s" 'swiper)
  (my-leader-def "ss" 'swiper)
  )

(use-package ivy-avy)

(use-package amx)

;; inspired by https://github.com/pjones/ivy-exwm
(use-package ivy-rich
  :init
  (setq ivy-rich-parse-remote-buffer nil)
  ;;(setq ivy-format-function #'ivy-format-function-line)
  :config
  ;;(defun ivy-rich-switch-buffer-exwm-or-project (candidate)
  ;;  (with-current-buffer
  ;;      (get-buffer candidate)
  ;;    (if (derived-mode-p 'exwm-mode)
  ;;        exwm-class-name
  ;;      (ivy-rich-switch-buffer-project candidate))))

  ;;(setq ivy-rich-display-transformers-list
  ;;      '(ivy-switch-buffer
  ;;        (:columns
  ;;         ((ivy-rich-candidate (:width 60))
  ;;          (ivy-rich-switch-buffer-size (:width 7))
  ;;          (ivy-rich-switch-buffer-indicators (:width 4 :face error :align right))
  ;;          (ivy-rich-switch-buffer-major-mode (:width 18 :face warning))
  ;;          (ivy-rich-switch-buffer-exwm-or-project (:width 15 :face success))
  ;;          (ivy-rich-switch-buffer-path (:width (lambda (x) (ivy-rich-switch-buffer-shorten-path x (ivy-rich-minibuffer-width 0.3))))))
  ;;         :predicate
  ;;         (lambda (cand) (get-buffer cand)))
  ;;        counsel-M-x
  ;;        (:columns
  ;;         ((counsel-M-x-transformer (:width 40))
  ;;          (ivy-rich-counsel-function-docstring (:face font-lock-doc-face))))
  ;;        counsel-describe-function
  ;;        (:columns
  ;;         ((counsel-describe-function-transformer (:width 40))
  ;;          (ivy-rich-counsel-function-docstring (:face font-lock-doc-face))))
  ;;        counsel-describe-variable
  ;;        (:columns
  ;;         ((counsel-describe-variable-transformer (:width 40))
  ;;          (ivy-rich-counsel-variable-docstring (:face font-lock-doc-face))))
  ;;        counsel-recentf
  ;;        (:columns
  ;;         ((ivy-rich-candidate (:width 0.8))
  ;;          (ivy-rich-file-last-modified-time (:face font-lock-comment-face))))))
  (ivy-rich-mode 1)
  (ivy-rich-project-root-cache-mode 1)
  )

(use-package ivy-posframe
  :config
  (put 'ivy-posframe 'face-alias 'default)
  (setq ivy-posframe-border-width 5)
  (setq ivy-posframe-display-functions-alist '((t . ivy-posframe-display-at-frame-center)))
  (setq ivy-posframe-display-functions-alist
      '((swiper          . ivy-posframe-display-at-point)
        (complete-symbol . ivy-posframe-display-at-point)
        (t               . ivy-posframe-display-at-frame-center)))
  (ivy-posframe-mode 1)
  )

avy

(use-package avy
  :config
  (avy-setup-default)
  ;;(my-leader-def
  ;; "jj" 'evil-avy-goto-char-timer
  ;; )
  (setq avy-all-windows nil)
  (setq avy-keys '(?a ?o ?e ?u ?h ?t ?n ?s))
  (setq avy-timeout-seconds 0.2)
  (general-define-key :states 'normal "gc" 'evil-avy-goto-char-timer);;evil-avy-goto-char-2)
  )
(use-package ace-link
  :config
  (ace-link-setup-default)
  (general-define-key :states 'normal :keymaps 'Info-mode-map "o" 'ace-link-info)
  (general-define-key :states 'normal :keymaps 'help-mode-map "o" 'ace-link-help)
  (general-define-key :states 'normal :keymaps 'help-mode-map "o" 'ace-link-help)
  (my-local-leader-def :keymaps 'org-mode-map "o" 'ace-link-org)
  )
(use-package ace-window
  :config
  ;;(general-define-key "C-o" 'ace-buffer)
  (setq aw-keys '(?h ?t ?n ?s))
  ;;(general-define-key :keymaps 'override "M-<tab>" 'ace-window)
  ;;(my-leader-def
  ;; "o" 'ace-window
  ;; )
  )
;;(use-package evil-easymotion
;;  :config
;;  (evilem-default-keybindings "SPC j")
;;  )

ibuffer

(use-package ibuffer
  :straight nil
  :config
  (general-def
    :states 'normal
    :keymaps 'ibuffer-mode-map
    "<tab>" 'ibuffer-visit-buffer-other-window-noselect)
  )

dired

(setq delete-by-moving-to-trash t)
(setq trash-directory "~/amac/.Trash")

(setq dired-listing-switches "-alhv")
(setq dired-guess-shell-alist-user
      (list (list "\\.pdf" "open")))
(put 'dired-find-alternate-file 'disabled nil)

(general-def
  :keymaps 'dired-mode-map
  :states 'normal
  "gj" 'dired-next-subdir
  "gk" 'dired-prev-subdir
  )

yasnippet

(use-package yasnippet
  :config
  (yas-global-mode 1)
  )

company

(use-package company
  :init
  (setq
   ;company-dabbrev-downcase nil
   company-idle-delay 0
   company-tooltip-align-annotations t
   company-show-quick-access t
   )
  :config
  (company-mode 1)
  (add-hook 'after-init-hook 'global-company-mode)
  (define-key company-active-map (kbd "C-h") nil)

  (company-tng-mode 1)

  (setq company-backends '((company-math-symbols-latex
                            company-latex-commands
                            company-math-symbols-unicode
                            company-capf
                            :with company-yasnippet)
                           company-files
                           (company-dabbrev-code
                            company-gtags company-etags
                            company-keywords
                            :with company-yasnippet)
                           (company-dabbrev :with company-yasnippet)))
  )

(use-package company-math)

pdf-tools

(use-package pdf-tools
  :mode (("\\.pdf\\'" . pdf-view-mode))
  :config
  (evil-collection-define-key 'normal 'pdf-view-mode-map
    "u" 'pdf-view-scroll-down-or-previous-page
    "d" 'pdf-view-scroll-up-or-next-page
    "J" 'pdf-view-next-page-command
    "K" 'pdf-view-previous-page-command
    "<right>" 'image-forward-hscroll
    "<left>" 'image-backward-hscroll
    (kbd "C-u") 'pdf-view-scroll-down-or-previous-page
    (kbd "C-d") 'pdf-view-scroll-up-or-next-page
    (kbd "C-s") 'pdf-occur
    )
  (setq pdf-view-use-scaling t)
  (setq pdf-view-resize-factor 1.1)
  (setq pdf-cache-image-limit 16)
  (add-hook 'pdf-view-mode-hook #'pdf-links-minor-mode)
  (setq pdf-annot-activate-created-annotations t)
  (setq pdf-annot-default-annotation-properties
        `((t (label . ,user-full-name))
          (text (icon . "Comment")
                (color . "#ff0000"))
          (highlight (color . "yellow"))
          (squiggly (color . "orange"))
          (strike-out(color . "red"))
          (underline (color . "blue"))))
  )

epub

(use-package nov
  :mode (("\\.epub\\'" . nov-mode))
  )

flyspell

(use-package flyspell
  :straight nil
  :init
  (setq ispell-program-name "aspell")
  :config
  (add-hook 'org-mode-hook 'flyspell-mode)
  (add-hook 'TeX-mode-hook 'flyspell-mode)
  (add-hook 'message-mode-hook 'flyspell-mode)
  )
(use-package flyspell-correct-ivy
  :config
  (my-leader-def
    "sc" 'flyspell-correct-wrapper
    )
  )

which-key

(use-package which-key
  :config
  (which-key-mode)
  )

magit

(use-package magit
  :config
  (my-leader-def
   "g"  '(:ignore t :which-key "git")
   "gs" 'magit-status
   )
  (define-key magit-mode-map (kbd "C-<tab>") nil)
  (define-key magit-mode-map (kbd "M-<tab>") nil)
  (setq magit-diff-refine-hunk 'all)
  )
;;(use-package evil-magit ;; now part of evil-collection
;;  )

org

org

  (use-package org
    ;:straight (org ;;org-plus-contrib https://github.com/raxod502/straight.el/issues/352
    ;           :build `("nix-shell" "--command"
    ;                    ,(concat "make oldorg EMACS="
    ;                             invocation-directory invocation-name)))
    :init
    (setq org-agenda-files (list "~/org/todo.org")
          org-agenda-span 10
          org-edit-src-content-indentation 0
          org-agenda-window-setup 'current-window
          org-startup-with-inline-images nil
          org-src-tab-acts-natively t
          org-adapt-indentation nil
          org-src-window-setup 'current-window
          org-export-with-smart-quotes t
          org-log-done t
          ;;org-src-window-setup 'other-window
          ;;org-export-in-background t
          org-startup-folded t
          org-highlight-latex-and-related '(native latex scripts entities)
          org-ellipsis "⤵"
          org-imenu-depth 4
          org-cycle-hook '(org-cycle-hide-archived-subtrees org-cycle-show-empty-lines org-optimize-window-after-visibility-change)
          org-latex-prefer-user-labels t
          )
    ;; TODO: fix this so org-scheduled today actually applied correctly in org-faces.el
    ;; (- 1 (/ (float diff) (max wdays 0)))
    ;;   (upcoming? (and today? (> deadline today)))
    (setq org-deadline-warning-days 0)
    (setq org-agenda-deadline-faces '((1.01 . org-scheduled-previously)
                                      (1.0 . org-scheduled)
                                      (0.99 . org-sheduled-today)
                                      (0.0 . org-scheduled)))

    (setq org-confirm-babel-evaluate nil)
    ;; display/update images in the buffer after I evaluate
    (add-hook 'org-babel-after-execute-hook 'org-display-inline-images 'append)

    :config
    (evil-define-key 'normal org-mode-map (kbd "RET") 'org-open-at-point)
    (add-to-list 'org-src-lang-modes '("conf" . conf))
    (require 'ox-latex)
    (require 'ox-beamer)
    ;;(setq org-export-allow-bind-keywords t)
    ;;(add-to-list 'org-latex-packages-alist '("" "minted")) added by custom instead
    ;;(ox-extras-activate '(ignore-headlines))
    (setq org-latex-listings 'minted)

    (setq org-latex-packages-alist '(("" "lmodern" nil)
                                     ("" "minted" nil)
                                     ("" "svg" nil)))
                                     ;;("margin=1in,headsep=0.4in,headheight=14pt" "geometry" nil)
                                     ;;("" "geometry" nil)
                                     ;;("" "fancyhdr" nil)
                                     ;;("" "parskip" nil)))
    ;;(setq org-file-apps
    ;;      '((auto-mode . emacs)
    ;;        ("\\.mm\\'" . default)
    ;;        ("\\.x?html?\\'" . default)
    ;;        ("\\.pdf\\'" . default)
    ;;        ("\\.png\\'" . "open \"%s\"")
    ;;        ("\\.svg\\'" . "open \"%s\"")))

    ;;(setq org-latex-pdf-process
    ;;      '("%latex -interaction nonstopmode -shell-escape -output-directory %o %f" "%latex -interaction nonstopmode -shell-escape -output-directory %o %f" "%latex -interaction nonstopmode -shell-escape -output-directory %o %f"))
    (setq org-latex-pdf-process (list "latexmk -shell-escape -bibtex -f -pdf %f"))
    (setq org-latex-table-scientific-notation "$%s\\times10^{%s}$")

    (setq org-preview-latex-default-process 'dvisvgm
          org-preview-latex-image-directory "~/.cache/org-preview-latex/"
          org-format-latex-options '(:foreground default :background default
                                                 :scale 0.4
                                                 :html-foreground "Black"
                                                 :html-background "Transparent"
                                                 :html-scale 1.0
                                                 :matchers ("begin" "$1" "$" "$$" "\\(" "\\["))
          )

    (defun my-org-format-web-link ()
      (interactive)
      (let ((el (org-element-context)))
        (when (and (eq (org-element-type el) 'link)
                   (let ((type (org-element-property :type el)))
                     (or (string= type "http") (string= type "https"))))
          (let* ((url (org-element-property :raw-link el))
                 (title (with-current-buffer (url-retrieve-synchronously url)
                          (dom-text
                           (dom-by-tag
                            (libxml-parse-html-region (point-min) (point-max))
                            'title)))))
            (delete-region (org-element-property :begin el)
                           (org-element-property :end el))
            (insert (org-link-make-string url title))))))

    (my-local-leader-def
     :keymaps 'org-mode-map
     "'" 'org-edit-special
     "c" 'org-capture

     "l" 'org-latex-export-to-pdf
     "h" 'org-latex-export-to-html

     ;; Clock
     ;; These keybindings should match those under the "aoC" prefix (below)
     "Cc" 'org-clock-cancel
     "Cd" 'org-clock-display
     "Ce" 'org-evaluate-time-range
     "Cg" 'org-clock-goto
     "Ci" 'org-clock-in
     "CI" 'org-clock-in-last
     "Cj" 'spacemacs/org-clock-jump-to-current-clock
     "Co" 'org-clock-out
     "CR" 'org-clock-report
     "Cr" 'org-resolve-clocks

     "dd" 'org-deadline
     "ds" 'org-schedule
     "dt" 'org-time-stamp
     "dT" 'org-time-stamp-inactive
     "e" 'org-export-dispatch
     "fi" 'org-feed-goto-inbox
     "fu" 'org-feed-update-all

     "a" 'org-agenda

     "p" 'org-priority

     "Tc" 'org-toggle-checkbox
     "Te" 'org-toggle-pretty-entities
     "Ti" 'org-toggle-inline-images
     "Tl" 'org-toggle-link-display
     "Tt" 'org-show-todo-tree
     "TT" 'org-todo
     "TV" 'space-doc-mode
     "Tx" 'org-latex-preview
     ;;    "o" 'org-toggle-latex-fragment

     ;; More cycling options (timestamps, headlines, items, properties)
     "L" 'org-shiftright
     "H" 'org-shiftleft
     "J" 'org-shiftdown
     "K" 'org-shiftup

     ;; Change between TODO sets
     "C-S-l" 'org-shiftcontrolright
     "C-S-h" 'org-shiftcontrolleft
     "C-S-j" 'org-shiftcontroldown
     "C-S-k" 'org-shiftcontrolup

     ;; Subtree editing
     "sa" 'org-toggle-archive-tag
     "sA" 'org-archive-subtree
     "sb" 'org-tree-to-indirect-buffer
     "sh" 'org-promote-subtree
     "sj" 'org-move-subtree-down
     "sk" 'org-move-subtree-up
     "sl" 'org-demote-subtree
     "sn" 'org-narrow-to-subtree
     "sN" 'widen
     "sr" 'org-refile
     "ss" 'org-sparse-tree
     "sS" 'org-sort

     ;; tables
     "ta" 'org-table-align
     "tb" 'org-table-blank-field
     "tc" 'org-table-convert
     "tdc" 'org-table-delete-column
     "tdr" 'org-table-kill-row
     "te" 'org-table-eval-formula
     "tE" 'org-table-export
     "th" 'org-table-previous-field
     "tH" 'org-table-move-column-left
     "tic" 'org-table-insert-column
     "tih" 'org-table-insert-hline
     "tiH" 'org-table-hline-and-move
     "tir" 'org-table-insert-row
     "tI" 'org-table-import
     "tj" 'org-table-next-row
     "tJ" 'org-table-move-row-down
     "tK" 'org-table-move-row-up
     "tl" 'org-table-next-field
     "tL" 'org-table-move-column-right
     "tn" 'org-table-create
     "tN" 'org-table-create-with-table.el
     "tr" 'org-table-recalculate
     "ts" 'org-table-sort-lines
     "ttf" 'org-table-toggle-formula-debugger
     "tto" 'org-table-toggle-coordinate-overlays
     "tw" 'org-table-wrap-region

     ;; Source blocks / org-babel
     "bp" 'org-babel-previous-src-block
     "bn" 'org-babel-next-src-block
     "be" 'org-babel-execute-maybe
     "bo" 'org-babel-open-src-block-result
     "bv" 'org-babel-expand-src-block
     "bu" 'org-babel-goto-src-block-head
     "bg" 'org-babel-goto-named-src-block
     "br" 'org-babel-goto-named-result
     "bb" 'org-babel-execute-buffer
     "bs" 'org-babel-execute-subtree
     "bd" 'org-babel-demarcate-block
     "bt" 'org-babel-tangle
     "bf" 'org-babel-tangle-file
     "bc" 'org-babel-check-src-block
     "bj" 'org-babel-insert-header-arg
     "bl" 'org-babel-load-in-session
     "bi" 'org-babel-lob-ingest
     "bI" 'org-babel-view-src-block-info
     "bz" 'org-babel-switch-to-session
     "bZ" 'org-babel-switch-to-session-with-code
     "ba" 'org-babel-sha1-hash
     "bx" 'org-babel-do-key-sequence-in-edit-buffer
     "vk" 'org-babel-remove-result-one-or-many
     "vm" 'org-babel-mark-block

     ;; Multi-purpose keys
     "," 'org-ctrl-c-ctrl-c
     "*" 'org-ctrl-c-star
     "-" 'org-ctrl-c-minus
     "#" 'org-update-statistics-cookies
     "RET"   'org-ctrl-c-ret
     "M-RET" 'org-meta-return
     ;; attachments
     "A" 'org-attach
     ;; insertion
     "ib" 'org-insert-structure-template
     "id" 'org-insert-drawer
     "ie" 'org-set-effort
     "if" 'org-footnote-new
     "ih" 'org-insert-heading
     "iH" 'org-insert-heading-after-current
     "iK" 'spacemacs/insert-keybinding-org
     "il" 'org-insert-link
     ;"iL" 'org-ref-insert-link
     "in" 'org-add-note
     "ip" 'org-set-property
     "is" 'org-insert-subheading
     "it" 'org-set-tags-command
     "ii" 'my-org-format-web-link
     )

    (my-leader-def
     ;; org-agenda
     "ao#" 'org-agenda-list-stuck-projects
     "ao/" 'org-occur-in-agenda-files
     "aoa" 'org-agenda-list
     "aoc" 'org-capture
     "aoe" 'org-store-agenda-views
     "aofi" 'org-feed-goto-inbox
     "aofu" 'org-feed-update-all
     "aol" 'org-store-link
     "aom" 'org-tags-view
     "aoo" 'org-agenda
     "aos" 'org-search-view
     "aot" 'org-todo-list
     )
    )

(use-package  org-contrib)

ox-latex

(use-package ox-latex
  :straight nil
  :config
  (add-to-list 'org-latex-minted-langs '(ipython "python"))
  )

org-bullets

evil-org

(use-package evil-org
  :after org
  :config
  (add-hook 'org-mode-hook 'evil-org-mode)
  (add-hook 'evil-org-mode-hook
            (lambda ()
              (evil-org-set-key-theme '(navigation insert textobjects additional
                                                   calendar todo))))
  (require 'evil-org-agenda)
  (evil-org-agenda-set-keys)
)

jupyter

; to build using straight on arm:
; cd ~/.emacs.d/straight/build/zmq
; nix-shell -p autoconf automake libtool pkg-config my-zeromq
; make
(use-package zmq
   :straight (zmq :type git :flavor melpa :host github :repo "nnicandro/emacs-zmq"
                  :files (:defaults "Makefile" "src" "zmq-pkg.el" "emacs-zmq.so")
                  :pre-build ("nix-shell" "-p" "autoconf" "automake" "libtool" "pkg-config" "my-zeromq"
                          "--command" "make clean && make")))


(use-package jupyter
  :config
  (org-babel-do-load-languages
   'org-babel-load-languages
   '(
     (shell . t)
     (python . t)
     (emacs-lisp . t)
     (latex . t)
     (jupyter . t) ; must be last
     ))
  )

htmlize

(use-package htmlize
  )

org-ref

(use-package bibtex
  :init
  (setq bibtex-autokey-year-title-separator "_")
  :config
  (setq bibtex-autokey-titleword-ignore
        (remove "[^[:upper:]].*" bibtex-autokey-titleword-ignore))
  )

(use-package biblio
  :init
  (setq biblio-bibtex-use-autokey t)
  )

(use-package ivy-bibtex
  :init
    (my-leader-def "ab" 'ivy-bibtex)

  (setq bibtex-completion-bibliography '("~/qnet/notebook/references.bib")
        bibtex-completion-library-path '("~/qnet/ref-pdfs/")
        bibtex-completion-notes-path "~/qnet/notebook/ref-notes.org")
  (setq bibtex-completion-format-citation-functions
        '((org-mode      . bibtex-completion-format-citation-org-cite)
          (latex-mode    . bibtex-completion-format-citation-cite)
          (markdown-mode . bibtex-completion-format-citation-pandoc-citeproc)
          (default       . bibtex-completion-format-citation-default)))

  (org-cite-register-processor 'ivy-bibtex-org-cite-follow
    :follow (lambda (_ _) (ivy-bibtex)))

  (setq org-cite-follow-processor 'ivy-bibtex-org-cite-follow)
  )

(use-package citeproc)

;(use-package org-ref
;  (setq doi-utils-download-pdf nil)
;  :config
;  (require 'org-ref-ivy)
;  )

org-pdftools

;(use-package org-pdftools
;  :straight (org-pdftools :type git :host github :repo "fuxialexander/org-pdftools")
;  :config (setq org-pdftools-root-dir "~/qnet/ref-pdfs/")
;  (with-eval-after-load 'org
;    (org-link-set-parameters "pdftools"
;                             :follow #'org-pdftools-open
;                             :complete #'org-pdftools-complete-link
;                             :store #'org-pdftools-store-link
;                             :export #'org-pdftools-export)
;    (add-hook 'org-store-link-functions 'org-pdftools-store-link)))

LaTeX

(use-package tex
  :straight auctex
  :ensure auctex
  :init
  (setq TeX-view-program-selection '((output-pdf "pdf-tools")))
  (setq TeX-view-program-list '(("pdf-tools" "TeX-pdf-tools-sync-view")))
  (add-hook 'TeX-after-compilation-finished-functions
            #'TeX-revert-document-buffer)
  (add-hook 'LaTeX-mode-hook #'visual-line-mode)
  (add-hook 'LaTeX-mode-hook (lambda () (column-enforce-mode -1)))
;;(setq TeX-command-extra-options "\"-shell-escape\"")
;;(spacemacs/set-leader-keys-for-major-mode 'tex-mode
;;  "l" 'latex/build)
;;(spacemacs/set-leader-keys-for-major-mode 'latex-mode
;;  "l" 'latex/build)
  )

markdown

(use-package markdown-mode
  )

mu4e

(add-to-list 'load-path "~/.nix-profile/share/emacs/site-lisp/mu4e/")

(use-package mu4e
  :straight nil
  :config
  ;(setq mu4e-mu-binary "/usr/local/share/emacs/site-lisp/mu/mu4e")

  (general-define-key
   :states 'normal
   :keymaps 'mu4e-view-mode-map
   "o" 'ace-link-mu4e
   "O" 'mu4e-view-open-attachment)
;;(define-key mu4e-view-mode-map (kbd "f") 'mu4e-view-go-to-url)
;;(define-key mu4e-view-mode-map (kbd "o") 'ace-link-mu4e)
;;(define-key mu4e-view-mode-map (kbd "O") 'mu4e-view-open-attachment)

  (my-leader-def
   "am" 'mu4e
   )

  <<mu4e>>

  (require 'org-mu4e)

  (setq mu4e-change-filenames-when-moving t
        mu4e-headers-time-format "%I:%M %p"
        mu4e-headers-date-format "%y-%m-%d"
        ;;mu4e-split-view 'vertical
        ;;mu4e-headers-visible-columns 80
        mu4e-get-mail-command "mbsync -a"
        ;;mu4e-headers-auto-update nil
        ;;mu4e-update-interval 120
        mu4e-headers-fields '((:maildir . 12)
                              (:flags . 4)
                              (:human-date . 9)
                              ;;(:mailing-list . 10)
                              (:from . 24)
                              (:subject))
        mu4e-headers-sort-field ':date
        mu4e-headers-sort-direction 'ascending
        mu4e-view-show-addresses t
        mu4e-compose-format-flowed t
        mu4e-compose-dont-reply-to-self t
        mu4e-headers-results-limit 1000
        message-send-mail-function 'smtpmail-send-it ; For message-mode (Gnus)
        send-mail-function 'smtpmail-send-it ; For mail-mode (Rmail)
        smtpmail-stream-type 'starttls
        ;;mu4e-view-prefer-html nil
        )

  ;; customize the reply-quote-string
  (setq message-citation-line-format "On %a, %b %d, %Y at %I:%M %p, %f wrote:\n")
  ;; choose to use the formatted string
  (setq message-citation-line-function 'message-insert-formatted-citation-line)

  ;;(with-eval-after-load 'mu4e-alert (mu4e-alert-set-default-style 'notifier))

  ;;(defun my-mu4e-html2text (msg)
  ;;  "My html2text function; shows short message inline, show
  ;;long messages in some external browser (see `browse-url-generic-program')."
  ;;  (let ((html (or (mu4e-message-field msg :body-html) "")))
  ;;    (if (> (length html) 20000)
  ;;        (progn
  ;;          (mu4e-action-view-in-browser msg)
  ;;          "[Viewing message in external browser]")
  ;;      (mu4e-shr2text msg))))

                                        ;(setq mu4e-html2text-command 'my-mu4e-html2text)
  (setq mu4e-html2text-command 'mu4e-shr2text)

  ;(add-to-list 'mu4e-view-actions
  ;             '("view in browser" . my-mu4e-action-view-in-browser) t)

  (defun my-mu4e-action-view-in-browser (msg)
  "Show current MSG in browser if it includes an HTML-part.
The variables `browse-url-browser-function',
`browse-url-handlers', and `browse-url-default-handlers'
determine which browser function to use."
  (with-temp-buffer
    (insert-file-contents-literally
     (mu4e-message-field msg :path) nil nil nil t)
    (run-hooks 'gnus-article-decode-hook)
    (when (re-search-forward "<!DOCTYPE[^>]*>" nil t)
      (replace-match ""))
    (when (re-search-forward "<html[^>]*>" nil t)
      (replace-match "<html>"))
    (let ((header (cl-loop for field in '("from" "to" "cc" "date" "subject")
                           when (message-fetch-field field)
                           concat (format "%s: %s\n" (capitalize field) it)))
          (parts (mm-dissect-buffer t t)))
      ;; If singlepart, enforce a list.
      (when (and (bufferp (car parts))
                 (stringp (car (mm-handle-type parts))))
        (setq parts (list parts)))
      ;; Process the list
      (unless (gnus-article-browse-html-parts parts header)
        (mu4e-warn "Message does not contain a \"text/html\" part"))
      (mm-destroy-parts parts))))

  (setq mu4e-view-actions
        '(("capture message" . mu4e-action-capture-message)
          ("view in browser" . my-mu4e-action-view-in-browser)
          ("show this thread" . mu4e-action-show-thread)))

  (add-hook 'mu4e-view-mode-hook (lambda () (visual-line-mode 1)))

  (custom-theme-set-faces
   'user
   '(variable-pitch ((t (:family "DejaVu Sans" :height 120)))))

  (add-hook 'message-mode-hook (lambda () (column-enforce-mode -1))) ;;(set-fill-column 80) 

  )

(use-package mu4e-maildirs-extension
  :config
  (mu4e-maildirs-extension-load)
  )

nix

fix this so nix-eshell works

(use-package nix-mode
  )

direnv

(use-package direnv
 :config
 (setq direnv-always-show-summary nil)
 (direnv-mode))

smartparens and rainbow-delimiters

(use-package smartparens
  :config
  (sp-local-pair 'org-mode "$" "$")
  (sp-local-pair 'org-mode '"\\[" "\\]")
  )
(use-package rainbow-delimiters
  :config
  (add-hook 'prog-mode-hook #'rainbow-delimiters-mode)
  )

column-enforce-mode

(use-package column-enforce-mode
  :config
  (add-hook 'prog-mode-hook 'column-enforce-mode)
  (add-hook 'text-mode-hook 'column-enforce-mode)
  )
;;(require 'fill-column-indicator)
;;(add-hook 'prog-mode-hook 'turn-on-fci-mode)
;;(add-hook 'text-mode-hook 'turn-on-fci-mode)

frames and windows

(setq split-height-threshold nil) ;80) ;40)
(setq split-width-threshold nil) ;160) ;100)

eshell

(add-hook 'eshell-mode-hook
          '(lambda ()
             (define-key eshell-mode-map (kbd "<tab>") 'completion-at-point)))

(evil-define-key 'insert eshell-mode-map 
  (kbd "C-p") 'eshell-previous-input 
  (kbd "C-n") 'eshell-next-input)

comint

(setq shell-default-height 40)
(setq shell-default-position 'full)
(setq shell-default-full-span nil)
(setq shell-default-term-shell "/usr/local/bin/bash")
;;(setq shell-default-shell 'shell)
(push (cons "\\*shell\\*" display-buffer--same-window-action) display-buffer-alist)
;;(setq term-color-black ((t (:foreground "dim gray"))))

(evil-define-key 'normal comint-mode-map (kbd "C-p") 'comint-previous-input
  (kbd "C-n") 'comint-next-input)
(evil-define-key 'insert comint-mode-map (kbd "C-p") 'comint-previous-input
  (kbd "C-n") 'comint-next-input)
(evil-define-key 'normal comint-mode-map (kbd "C-l") 'comint-clear-buffer)
(evil-define-key 'insert comint-mode-map (kbd "C-l") 'comint-clear-buffer)
(evil-define-key 'normal term-raw-map (kbd "C-p") 'term-send-up
  (kbd "C-n") 'term-send-down)
(evil-define-key 'insert term-raw-map (kbd "C-p") 'term-send-up
  (kbd "C-n") 'term-send-down)

(setq python-shell-interpreter "ipython"
      python-shell-interpreter-args "--simple-prompt")

(setq python-shell-prompt-detect-failure-warning nil)
;;(setq python-shell-completion-native-disabled-interpreters '("jupyter" "pypy"))

;;(add-hook 'shell-mode-hook 'my-shell-mode-hook)
;;(defun my-shell-mode-hook ()
;;  (setq comint-input-ring-file-name "~/.bash_history")
;;  (comint-read-input-ring t))
;;(defun my-shell-mode-hook ()
;;  (let ((histfile  "~/.bash_history"))
;;    (if (tramp-tramp-file-p default-directory)
;;        (let ((vec (tramp-dissect-file-name default-directory)))
;;          (setq comint-input-ring-file-name
;;                (tramp-make-tramp-file-name
;;                 (tramp-file-name-method vec)
;;                 (tramp-file-name-user vec)
;;                 (tramp-file-name-host vec)
;;                 histfile)))
;;      (setq comint-input-ring-file-name histfile)))
;;  (comint-read-input-ring t)
;;  (let ((process (get-buffer-process (current-buffer))))
;;    (set-process-sentinel process #'comint-write-input-ring)))

;; modifid from https://github.com/syl20bnr/spacemacs/issues/10956
;; (add-hook 'term-mode-hook
;;           (lambda ()
;;             (add-hook 'evil-normal-state-entry-hook
;;                       (lambda () (term-line-mode)) nil t)
;;             (add-hook 'evil-normal-state-exit-hook
;;                       (lambda () (term-char-mode)) nil t)))
(setq term-char-mode-point-at-process-mark nil)

libvterm

;; to build using straight:
;; cd ~/.emacs.d/straight/build/vterm
;; nix-shell -p cmake libvterm-neovim --command "cmake -DUSE_SYSTEM_LIBVTERM=ON . && make"
;; cmake -DUSE_SYSTEM_LIBVTERM=ON .
;; make

(use-package vterm
  :straight (vterm :type git :host github :repo "akermu/emacs-libvterm"
                   :files ("*" (:exclude ".dir-locals.el" ".gitignore"
                                         ".clang-format" ".travis.yml")
                           "vterm-pkg.el")
                   :pre-build ("nix-shell" "-p" "cmake" "libvterm-neovim"
                           "--command" "cmake -DUSE_SYSTEM_LIBVTERM=ON . && make")))

tramp

(use-package tramp
  :config
  (add-to-list 'tramp-remote-path 'tramp-own-remote-path)

  ;; for some reason (bug probably) this has to be here to reset tram-password-prompt-regexp
  (setq tramp-password-prompt-regexp
        (format "^.*\\(%s\\).*:\^@? *" (regexp-opt password-word-equivalents)))

  :straight nil
  )

(setq password-word-equivalents (cons "token_response" password-word-equivalents))

;;(setq tramp-histfile-override t nil (tramp))

this fixes an issue where you get the error: ppwd: command not found only on macos?

lua

(use-package lua-mode
  :config
  )

json

(use-package json-mode
  :config
  )

hidden-mode-line

https://emacs-doctor.com/emacs-hide-mode-line.html

(defvar-local hidden-mode-line-mode nil)

(define-minor-mode hidden-mode-line-mode
  "Minor mode to hide the mode-line in the current buffer."
  :init-value nil
  :global t
  :variable hidden-mode-line-mode
  :group 'editing-basics
  (if hidden-mode-line-mode
      (setq hide-mode-line mode-line-format
            mode-line-format nil)
    (setq mode-line-format hide-mode-line
          hide-mode-line nil))
  (force-mode-line-update)
  ;; Apparently force-mode-line-update is not always enough to
  ;; redisplay the mode-line
  (redraw-display)
  (when (and (called-interactively-p 'interactive)
             hidden-mode-line-mode)
    (run-with-idle-timer
     0 nil 'message
     (concat "Hidden Mode Line Mode enabled.  "
             "Use M-x hidden-mode-line-mode to make the mode-line appear."))))

;; If you want to hide the mode-line in every buffer by default
;; (add-hook 'after-change-major-mode-hook 'hidden-mode-line-mode)

enwc

;(use-package enwc
;  :init
;  (setq enwc-default-backend 'nm)
;  )

brightness

https://github.com/dakra/xbacklight ;;(use-package xbacklight ;; :straight (xbacklight :type git :host github :repo “dakra/xbacklight”) ;;) https://github.com/DamienCassou/desktop-environment (setq brightness-delta “10%”) (setq brightness-get-cmd “light”) (setq brightness-get-regexp “\\([0-9]+%\\)”) (setq brightness-set-cmd “light set %s”)

(defun brightness-get () (let ((output (shell-command-to-string brightness-get-cmd))) (save-match-data (string-match brightness-get-regexp output) (match-string 1 output))))

(defun brightness-set (value) (shell-command-to-string (format brightness-set-cmd value)) (message “New brightness value: %s” (brightness-get)))

(defun brightness-inc () (interactive) (brightness-set (concat brightness-delta “+”)))

(defun brightness-dec () (interactive) (brightness-set (concat brightness-delta “-”)))

(defun brightness-get ()
  (interactive)
  (message "Brightness:  %s%%" 
           (string-trim (shell-command-to-string "light") "%")))

(defun brightness-inc ()
  (interactive)
  (shell-command-to-string "light -A 5")
  (brightness-get))

(defun brightness-dec ()
  (interactive)
  (shell-command-to-string "light -U 5")
  (brightness-get))

exwm

https://github.com/timor/spacemacsOS

(use-package pulseaudio-control
  :init
  (setq pulseaudio-control-volume-step "5%")
  :config
  (my-leader-def
    "ap" 'pulseaudio-control-map
    )
  )

(use-package exwm
;;  :straight nil
  :init
  ;;(setq mouse-autoselect-window t
  ;;      focus-follows-mouse t)
  (setq use-dialog-box nil)
  (setq exwm-workspace-show-all-buffers t)
  (setq exwm-layout-show-all-buffers t)
  (evil-set-initial-state 'exwm-mode 'emacs)
  (setq my-window-resize-delta 2)
  (setq lockcmd "i3lock -i /home/akyle/Downloads/outrun.png")
  ;;(setq exwm-workspace-minibuffer-position 'bottom)

  ;;(setenv "EDITOR" "emacsclient") set in xinitrc

  :config
  ;;(add-hook 'exwm-mode-hook #'hidden-mode-line-mode)
  (require 'exwm-systemtray)
  (exwm-systemtray-enable)
  ;(setq exwm-systemtray-height 40)

  ;;(my-leader-def
  ;;  "e" '(lambda () (interactive) (xcb:ewmh:set-_NET_WM_DESKTOP)))

  ;; All buffers created in EXWM mode are named "*EXWM*". You may want to
  ;; change it in `exwm-update-class-hook' and `exwm-update-title-hook', which
  ;; are run when a new X window class name or title is available.  Here's
  ;; some advice on this topic:
  ;; + Always use `exwm-workspace-rename-buffer` to avoid naming conflict.
  ;; + For applications with multiple windows (e.g. GIMP), the class names of
  ;;    all windows are probably the same.  Using window titles for them makes
  ;;   more sense.
  ;; In the following example, we use class names for all windows expect for
  ;; Java applications and GIMP.
  ;;(add-hook 'exwm-update-class-hook
  ;;          (lambda ()
  ;;            (unless (or (string-prefix-p "sun-awt-X11-" exwm-instance-name)
  ;;                        (string= "gimp" exwm-instance-name))
  ;;              (exwm-workspace-rename-buffer exwm-class-name))))
  ;;(add-hook 'exwm-update-title-hook
  ;;          (lambda ()
  ;;            (when (or (not exwm-instance-name)
  ;;                      (string-prefix-p "sun-awt-X11-" exwm-instance-name)
  ;;                      (string= "gimp" exwm-instance-name))
  ;;              (exwm-workspace-rename-buffer exwm-title))))

  (defun my-exwm-rename ()
    (exwm-workspace-rename-buffer (concat exwm-class-name ": " exwm-title)))

  (add-hook 'exwm-update-class-hook 'my-exwm-rename)
  (add-hook 'exwm-update-title-hook 'my-exwm-rename)

  ;;(add-hook 'exwm-update-title-hook 
  ;;          (lambda () 
  ;;            (if (and (string= "Firefox" exwm-class-name)
  ;;                     (not (string= "Mozilla Firefox" exwm-title)))
  ;;                ;;(exwm-workspace-rename-buffer (substring exwm-title 0 -18))
  ;;                (exwm-workspace-rename-buffer exwm-title)
  ;;              (exwm-workspace-rename-buffer exwm-title))))
  ;;;; Quick swtiching between workspaces
  ;;(defvar exwm-toggle-workspace 0
  ;;  "Previously selected workspace. Used with `exwm-jump-to-last-exwm'.")
  ;;(defun exwm-jump-to-last-exwm ()
  ;;  (interactive)
  ;;  (exwm-workspace-switch exwm-toggle-workspace))
  ;;(defadvice exwm-workspace-switch (before save-toggle-workspace activate)
  ;;  (setq exwm-toggle-workspace exwm-workspace-current-index))

  (setq touchpad-is-enabled t)
  (defun toggle-touchpad ()
    (interactive)
    (if touchpad-is-enabled
        (progn
          (shell-command "xinput disable 'Pine64 Pinebook Pro Touchpad'")
          (setq touchpad-is-enabled nil))
      (progn
        (shell-command "xinput enable 'Pine64 Pinebook Pro Touchpad'")
        (setq touchpad-is-enabled t))))

  (general-define-key :keymaps 'override "<f7>" 'toggle-touchpad)

  (define-key exwm-mode-map (kbd "C-c") nil)

  (add-to-list 'exwm-input-prefix-keys (kbd "C-SPC"))

  (setq exwm-input-global-keys
        `(
          ([?\s-r] . exwm-reset)
          ;;(,(kbd "C-SPC") . my-leader-prefix-cmd)
          ([?\s-f] . exwm-layout-toggle-fullscreen)
          ([?\s-F] . exwm-layout-toggle-mode-line)
          ([?\s-x] . exwm-workspace-switch)
          ;;([s-tab] . exwm-jump-to-last-exwm)
          ;;(,(kbd "M-<tab>") . exwm-jump-to-last-exwm)
          ;;(,(kbd "M-<tab>") . toggle-window-split)
          ;;(,(kbd "C-<tab>") . (lambda () (interactive) (switch-to-buffer nil)))
          ;;([?\s-b] . switch-to-buffer)
          ;;([?\s-o] . find-file)
          ;;(,(kbd "<f8>") . toggle-touchpad)

          ;;,@(mapcar (lambda (i)
          ;;            `(,(kbd (format "s-%d" i)) .
          ;;              (lambda ()
          ;;                (interactive)
          ;;                (exwm-workspace-switch-create ,i))))
          ;;          (number-sequence 0 9))

          ;; Bind "s-m" to launch applications ('M-&' also works if the output
          ;; buffer does not bother you).
          ;;(,(kbd "s-m") . counsel-linux-app)

          ;;;; Focusing windows
          ;;(,(kbd "s-h") . evil-window-left)
          ;;(,(kbd "s-j") . evil-window-down)
          ;;(,(kbd "s-k") . evil-window-up)
          ;;(,(kbd "s-l") . evil-window-right)
          ;;;; Moving Windows
          ;;(,(kbd "s-H") . evil-window-move-far-left)
          ;;(,(kbd "s-J") . evil-window-move-very-bottom)
          ;;(,(kbd "s-K") . evil-window-move-very-top)
          ;;(,(kbd "s-L") . evil-window-move-far-right)
          ;;;; Resize
          ;;(,(kbd "M-s-h") . (lambda () (interactive) (shrink-window my-window-resize-delta t)))
          ;;(,(kbd "M-s-j") . (lambda () (interactive) (shrink-window my-window-resize-delta)))
          ;;(,(kbd "M-s-k") . (lambda () (interactive) (enlarge-window my-window-resize-delta)))
          ;;(,(kbd "M-s-l") . (lambda () (interactive) (enlarge-window my-window-resize-delta t)))
          (,(kbd "<XF86MonBrightnessDown>") . brightness-dec)
          (,(kbd "<XF86MonBrightnessUp>") . brightness-inc)
          (,(kbd "<XF86AudioMute>") . pulseaudio-control-toggle-current-sink-mute)
          (,(kbd "<XF86AudioLowerVolume>") . pulseaudio-control-decrease-volume)
          (,(kbd "<XF86AudioRaiseVolume>") . pulseaudio-control-increase-volume)
          (,(kbd "s-<escape>") . (lambda () (interactive) (shell-command lockcmd)))
          ;(,(kbd "s-t") . (lambda () (interactive) (start-process "firefox" nil "firefox")))
          ))

  (setq my-global-simulation-keys 
        `(
          (,(kbd "C-b") . ,(kbd "<left>"))
          (,(kbd "C-f") . ,(kbd "<right>"))
          (,(kbd "C-p") . ,(kbd "<up>"))
          (,(kbd "C-n") . ,(kbd "<down>"))
          (,(kbd "C-a") . ,(kbd "<home>"))
          (,(kbd "C-e") . ,(kbd "<end>"))
          (,(kbd "C-h") . ,(kbd "<backspace>"))
          ;;(,(kbd "s-t") . ,(kbd "C-t"))
          ;;(,(kbd "s-c") . ,(kbd "C-c"))
          ;;(,(kbd "s-v") . ,(kbd "C-v"))
          ;;(,(kbd "s-w") . ,(kbd "C-w"))
          ;;(,(kbd "s-q") . ,(kbd "C-q"))
          ;;(,(kbd "s-n") . ,(kbd "C-n"))
          (,(kbd "C-j") . ,(kbd "C-<prior>"))
          (,(kbd "C-k") . ,(kbd "C-<next>"))
          ))

  (setq exwm-input-simulation-keys my-global-simulation-keys)

  ;;(setq my-firefox-simulation-keys
  ;;      (append my-global-simulation-keys
  ;;              `(
  ;;                ;;(,(kbd "s-<tab>") . ,(kbd "C-<tab>"))
  ;;                ;;(,(kbd "s-<tab>") . ,(kbd "^")) ; works with vimperator
  ;;                (,(kbd "s-<tab>") . ,(kbd "C-6")) ; works with tridactyl
  ;;                (,(kbd "C-s") . ,(kbd "C-g")) ; works with tridactyl
  ;;                (,(kbd "C-S-s") . ,(kbd "C-S-g")) ; works with tridactyl
  ;;                )))

  ; c-tab seem like it just wont work given emacs' limitations
  ; exwm-input--fake-key:       id=#x1000037 event=C-tab keycode
  ;[[file:/nix/store/b011yv21rbqr7a35m1prl4jk44cybwxl-emacs-exwm-0.22.1/share/emacs/site-lisp/elpa/exwm-0.22.1/exwm-input.el::(make-instance class]] 
  ; https://emacs.stackexchange.com/questions/52752/how-to-use-unbound-keys-as-non-sticky-modifier-keys

  ;(setq exwm-manage-finish-hook nil)
  ;;(add-hook 'exwm-manage-finish-hook
  ;;        (lambda ()
  ;;          (when (and exwm-class-name
  ;;                     (string= exwm-class-name "Firefox"))
  ;;            (exwm-input-set-local-simulation-keys my-firefox-simulation-keys))))

  ;;(require 'subr-x)  ;; Because of when-let

  ;;(defvar exwm-workspace-window-assignments
  ;;  '(("Firefox" . 0))
  ;;  "An alist of window classes and which workspace to put them on.")

  ;;(add-hook 'exwm-manage-finish-hook
  ;;          (lambda ()
  ;;            (when-let ((target (cdr (assoc exwm-class-name exwm-workspace-window-assignments))))
  ;;              (exwm-workspace-move-window target))))


  ;;(defun my-startup-processes ()
  ;;  (start-process "firefox" nil "firefox")
  ;;  ;;(start-process "calendar" nil "gnome-calendar")
  ;;  )
  ;(add-hook 'exwm-init-hook 'my-startup-processes)

  (add-hook 'exwm-mode-hook (lambda ()
                              (setq ivy-posframe-parameters '((parent-frame nil)))
                              (my-start-app "nm-applet")
                              (my-start-app "pasystray")
                              (my-start-app "blueman-applet")))

  ;;(defun my-startup-layout ()
  ;;  (interactive)
  ;;  (switch-to-buffer "Firefox")
  ;;  (exwm-workspace-move-window 9)
  ;;  (switch-to-buffer "Gnome-calendar")
  ;;  (exwm-workspace-move-window 8)
  ;;  (exwm-workspace-switch 0)
  ;;  (split-window-right)
  ;;  (setq current-prefix-arg '(4))
  ;;  (call-interactively 'spacemacs/default-pop-shell)
  ;;  (evil-normal-state)
  ;;  (evil-emacs-state)
  ;;  (other-window 1)
  ;;  (org-agenda-list))

  ;;(exwm-enable)

  ;;(require 'exwm-randr)
  ;;(setq exwm-randr-workspace-output-plist '(0 "VGA1"))
  ;;(add-hook 'exwm-randr-screen-change-hook
  ;;          (lambda ()
  ;;            (start-process-shell-command
  ;;             "xrandr" nil "xrandr --output VGA1 --left-of LVDS1 --auto")))
  ;;(exwm-randr-enable)
  ;;(server-start) ; start emacsclient for xdg-open of pdfs from firefox
  )



(general-define-key (kbd "<f1>") 'brightness-dec)
(general-define-key (kbd "<f2>") 'brightness-inc)
(general-define-key (kbd "<f4>") 'pulseaudio-control-toggle-current-sink-mute)
(general-define-key (kbd "<f5>") 'pulseaudio-control-decrease-volume)
(general-define-key (kbd "<f6>") 'pulseaudio-control-increase-volume)

minibuffer-statusbar

(use-package minibuffer-statusbar
  :straight (minibuffer-statusbar :type git :host github 
                                  :repo "akirakyle/minibuffer-statusbar")
  :config
  (minibuffer-statusbar-mode t)
  (global-eldoc-mode -1))

webkit

(use-package webkit
  :straight (webkit :type git :host github :repo "akirakyle/emacs-webkit"
                    :branch "main"
                    :files (:defaults "*.js" "*.css" "*.so")
                    :pre-build ("nix-shell" "--command" "make clean && make"))
  :init
  (setq browse-url-browser-function 'webkit-browse-url)
  ;(setq browse-url-browser-function 'xwidget-webkit-browse-url)
  (setq webkit-browse-url-force-new t)
  (setq webkit-search-prefix "https://google.com/search?q=")
  (setq webkit-ace-chars "aoeuidhtns")
  ;(setq webkit-dark-mode t)
  :config
  (my-leader-def
    "," 'webkit
    )

  (defun webkit--display-progress (progress)
    (setq webkit--progress-formatted
          (if (equal progress 100.0)
              ""
            (format "%s%.0f%%  " (all-the-icons-faicon "spinner") progress)))
    (force-mode-line-update))

  (defun my-mu4e-action-view-in-webkit (msg)
    (add-hook 'webkit-new-hook #'webkit-enable-javascript)
    (webkit-browse-url (concat "file://"
                               (mu4e~write-body-to-html msg)) t)
    (remove-hook 'webkit-new-hook #'webkit-enable-javascript))

  ;(add-to-list 'mu4e-view-actions
  ;             '("open in browser" . mu4e-action-view-in-browser) t)

(defun my-webkit-secure ()
  (interactive)
  (let ((cookie-file "~/.emacs.d/webkit/cookies-centos"))
    (webkit-set-proxy "socks://localhost:8000")
    (delete-file (expand-file-name cookie-file))
    (webkit-set-cookie-file cookie-file)))

(defun my-webkit-secure-start ()
  (interactive)
  (start-process "socks" "*socks*" "ssh" "centos" "ip a")
  (start-process "socks" "*socks*" "ssh" "-CND" "8000" "centos"))

)

(use-package webkit-ace
  :straight nil)

(use-package webkit-dark
  :straight nil)

(use-package evil-collection-webkit
  :straight nil
  :config
  (evil-collection-xwidget-setup)
  )

pass

(use-package pass)

GCMH

(use-package gcmh
  :init
  (setq gcmh-high-cons-threshold #x10000000)
  :config
  (gcmh-mode 1)
  )

Desktop

(use-package desktop
  :init
  (setq desktop-restore-frames nil)
  )

Server

(server-start)

qemu copy/paste

(defun my-copy-to-amac ()
  (interactive)
  (call-interactively 'evil-yank)
  (call-process-region (current-kill 0) nil "ssh" nil t nil "amac" "nc localhost 2224"))

(defun my-copy-from-amac ()
  (interactive)
  (kill-new
   (with-temp-buffer
     (call-process "ssh" nil t nil "amac" "nc localhost 2225")
     (buffer-string)))
  (call-interactively 'evil-paste-after))

(general-define-key (kbd "s-c") 'my-copy-to-amac)
(general-define-key (kbd "s-v") 'my-copy-from-amac)

snippets

org-mode

# -*- mode: snippet -*-
# name: general block
# key: 
# --
#+BEGIN_${1:SRC$(upcase yas-text)}
$0
#+END_$1
# -*- mode: snippet -*-
# name: general block
# key: bl
# --
#+BEGIN_${1:SRC}$2
$0
#+END_$1
# -*- mode: snippet -*-
# name: ipython block
# key: py
# --
#+begin_src ipython :session ${1::file ${2:./`(file-relative-name (let ((temporary-file-directory "./figs/")) (make-directory temporary-file-directory t) (make-temp-file "ipy" nil ".svg")))`}} :exports ${3:both}
$0
#+end_src
# -*- mode: snippet -*-
# name: ipython block
# key: py
# --
#+begin_src ipython :session ${1::ipyfile ${2:} }:exports ${3:both }:results ${4:raw drawer}
$0
#+end_src
# -*- mode: snippet -*-
# name: python block
# key: py
# --
#+BEGIN_SRC jupyter-python
$0
#+END_SRC
# -*- mode: snippet -*-
# name: latex block
# key: be
# --
\begin{${1:align*}}
$0
\end{$1}
# -*- mode: snippet -*-
# name: latex inline
# key: ma
# --
\\($0\\)
# -*- mode: snippet -*-
# name: matplotlib imports
# key: mpl
# --
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
%config InlineBackend.figure_format = 'svg'
Email: akira@akirakyle.com
GPG Public Key: 963C 2413 0BD3 BF1B 624C EF4C 8850 284C 20B8 078D