;;; ~/.config/doom/config.el -*- lexical-binding: t; -*-

;; (defvar xdg-data (getenv "XDG_DATA_HOME"))
;; (defvar xdg-bin (getenv "XDG_BIN_HOME"))
;; (defvar xdg-cache (getenv "XDG_CACHE_HOME"))
;; (defvar xdg-config (getenv "XDG_CONFIG_HOME"))

(add-to-list 'default-frame-alist '(inhibit-double-buffering . t))

(setq user-full-name "Colin Powell"
      user-mail-address "colin@onec.me")

(setq doom-theme 'doom-outrun-electric)

;; Fonts
(setq doom-font (font-spec :family "Iosevka" :size 14))
(setq doom-big-font (font-spec :family "Iosevka" :size 22))

;; Host-specific config

(pcase (system-name)
  ("prometheus"
   (font-put doom-font :size 12)
   (font-put doom-big-font :size 20)) ; smaller display
  ("triton"
   ;; I've swapped these keys on my keyboard
   (setq x-super-keysym 'meta
         x-meta-keysym  'super)))

(when IS-MAC
  (setq ns-use-thin-smoothing t))


;;
;; Keybinds

;;:m "M-j" '+hlissner:multi-next-line
;;:m "M-k" '+hlissner:multi-previous-line
(map! ;; Easier window movement
      :n "C-h" 'evil-window-left
      :n "C-j" 'evil-window-down
      :n "C-k" 'evil-window-up
      :n "C-l" 'evil-window-right

      (:map evil-treemacs-state-map
        "C-h" 'evil-window-left
        "C-l" 'evil-window-right)

      (:when IS-LINUX
        "s-x" #'execute-extended-command
        "s-;" #'eval-expression
        ;; use super for window/frame navigation/manipulation
        "s-w" #'delete-window
        "s-W" #'delete-frame
        "s-n" #'+default/new-buffer
        "s-j" #'org-move-subtree-down
        "s-k" #'org-move-subtree-up
        "s-N" #'make-frame
        "s-q" (if (daemonp) #'delete-frame #'evil-quit-all)
                  ;; Restore OS undo, save, copy, & paste keys (without cua-mode, because
        ;; it imposes some other functionality and overhead we don't need)
        "s-z" #'undo
        "s-c" (if (featurep 'evil) #'evil-yank #'copy-region-as-kill)
        "s-v" #'yank
        "s-s" #'save-buffer
        ;; Buffer-local font scaling
        "s-+" (λ! (text-scale-set 0))
        "s-=" #'text-scale-increase
        "s--" #'text-scale-decrease
        ;; Conventional text-editing keys
        "s-a" #'mark-whole-buffer
        :gi [s-return]    #'+default/newline-below
        :gi [s-S-return]  #'+default/newline-above
        :gi [s-backspace] #'doom/backward-kill-to-bol-and-indent)

      :leader
      (:prefix "j"
        :desc "Dumb jump to def"        "g" #'dumb-jump-go
        :desc "Dumb jump back"        "b" #'dumb-jump-back)
      (:prefix "f"
        :desc "Find file in dotfiles"   "t" #'+hlissner/find-in-dotfiles
        :desc "Browse dotfiles"         "T" #'+hlissner/browse-dotfiles)
      (:prefix "t"
        :desc "Switch themes"           "t" #'load-theme)
      (:prefix "o"
        :desc "Open imenu"              "i" #'lsp-ui-imenu
        :desc "Elfeed feed reader"      "f" #'elfeed
        :desc "Lobste.rs"               "l" #'ivy-lobsters
        :desc "Compose an email"        "c" #'notmuch-mua-new-mail)
      (:prefix "l"
        :desc "MPD Open playlist"       "o" #'mpdel-playlist-open
        :desc "MPD Remove at point"     "d" #'mpdel-playlist-delete
        :desc "MPD Start at point"      "s" #'mpdel-playlist-play
        :desc "MPD Next track"          "n" #'libmpdel-playback-next
        :desc "MPD Previous track"      "p" #'libmpdel-playback-previous)
      (:prefix "b"
        :desc "Black format buffer"     "f" #'blacken-buffer
        :desc "Links in buffer"         "l" #'counsel-ace-link)
      (:prefix "/"
        :desc "Search the web"          "w" #'web-search
        :desc "Search all the things"   "g" #'deadgrep)
      (:prefix "y"
        :desc "Yank pop!"               "p" #'counsel-yank-pop
        :desc "Git yank link"           "g" #'git-link))

;; app/search
(after! web-search
  (push '("Searx" "http://search.unbl.ink/?q=%s")
        web-search-providers)
  (setq web-search-default-provider "Searx"))

(def-package! org-alert
  :commands (org-alert-enable))

(after! org-alert-mode
  (setq alert-default-style 'libnotify))

;;
;; Modules

(setq +workspaces-switch-project-function #'ignore
      +format-on-save-enabled-modes '(python-mode)
      +pretty-code-enabled-modes '(emacs-lisp-mode org-mode))

;; app/mpdel
;;
(setq libmpdel-hostname "play.unbl.ink")

;; app/rss
(add-hook! 'elfeed-show-mode-hook (text-scale-set 1.5))

(setq rmh-elfeed-org-files (list "~/org/elfeed.org")
      elfeed-search-filter "@1-week-ago +unread ")

;; emacs/eshell
(after! eshell
  (set-eshell-alias!
   "f"   "(other-window 1) && find-file $1"
   "l"   "ls -lh"
   "d"   "dired $1"
   "gl"  "(call-interactively 'magit-log-current)"
   "gs"  "magit-status"
   "gc"  "magit-commit"))

(add-hook 'prog-mode-hook #'goto-address-mode) ;; Linkify links!

;; tools/deft
(setq deft-extensions '("org"))
(setq deft-directory "~/org")

;; tools/magit
(setq magit-repository-directories '(("~/work" . 2))
      magit-save-repository-buffers nil)

;;; Setup sending email with msmtp
(setq send-mail-function 'sendmail-send-it
      sendmail-program "/usr/local/bin/msmtp"
      mail-specify-envelope-from t
      message-sendmail-f-is-evil t
      message-sendmail-envelope-from 'header
      message-sendmail-extra-arguments '("--read-envelope-from")
      mail-envelope-from 'header)

(add-to-list 'auto-mode-alist '("\\.plantuml\\'" . planetuml-mode))

(load! "+ui.el")
(load! "+org")      ;; Org mode stuff like todos and rebindings
(load! "+org-cal")
;(load! "+elfeed")
(load! "+mail")    ;; Mail stuff
(load! "+ranger")
(load! "+wttrin")     ;; Weather config
