;;; ~/.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@unbl.ink")

;;
;; 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 "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 "Elfeed feed reader"      "f" #'elfeed
        :desc "Hckrnews"                "h" #'hackernews
        :desc "Lobste.rs"               "l" #'ivy-lobsters)
      (:prefix "b"
        :desc "Black format buffer"     "f" #'blacken-buffer
        :desc "isort buffer"            "I" #'py-isort-buffer
        :desc "Links in buffer"         "l" #'ace-link-org)
      (:prefix "s"
        :desc "Search project TODOs"    "t" #'+ivy/tasks
        :desc "Search the web"          "w" #'web-search
        :desc "Goto URL in eww"         "u" #'eww-browse-url
        :desc "Search in eww"           "3" #'eww-search-words
        :desc "Search all the things"   "g" #'deadgrep))

;; 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))

;; enable smog writing analysis
(use-package smog
  :config (setq smog-command "style -L en"))

;;
;; 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 ")

(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)


;;; It is the opposite of fill-paragraph
(defun unfill-paragraph ()
  "Takes a multi-line paragraph and makes it into a single line of text."
  (interactive)
  (let ((fill-column (point-max)))
    (fill-paragraph nil)))
;; Handy key definition
(define-key global-map "\M-z" 'unfill-paragraph)

; A few nice to haves
(nyan-mode) ; a rainbow cat, why not
(beacon-mode) ; show me where my cursor is bouncing around to
(add-hook 'after-init-hook #'global-emojify-mode) ; emoji, sigh
(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! "+nov")     ;; nov.el epub mode settings
(load! "+mail")    ;; Mail stuff
(load! "+eshell")
(load! "+mpd")
(load! "+ranger")
(load! "+mastodon")
(load! "+wttrin")  ;; Weather config
(load! "+elfeed")  ;; This runs a background web process ...

;; findout timezone location strings at http://worldtime.io
(setq display-time-world-list '(("America/Los_Angeles" "San Francisco")
                                ("America/Tegucigalpa" "Tegucigalpa")
                                ("America/New_York" "New York")
                                ("Europe/London" "London")
                                ("Europe/Warsaw" "Warsaw")
                                ("Europe/Kiev" "Lviv")))

(load! "beancount")
(require 'beancount)
(add-to-list 'auto-mode-alist '("\\.beancount\\'" . beancount-mode))
