(package-initialize)
(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)

(add-to-list 'load-path (expand-file-name "~/elisp/"))
(require 'ian-misc)

(set-default-coding-systems 'utf-8)

(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(abc-default-key "E")
 '(abc-default-tempo "1/4=100")
 '(aggressive-completion-delay 0.6)
 '(aggressive-indent-comments-too t)
 '(alda-binary-location (concat sys_root "usr/local/bin/alda"))
 '(ansi-color-faces-vector
	 [default default default italic underline success warning error])
 '(ansi-color-names-vector
	 ["#2f2f2e" "#ffb4ac" "#8ac6f2" "#e5c06d" "#a4b5e6" "#e5786d" "#7ec98f" "#74736f"])
 '(autoarg-kp-mode t)
 '(backward-delete-char-untabify-method 'hungry)
 '(balanced-windows-mode t)
 '(baud-rate 19200)
 '(blink-matching-paren-dont-ignore-comments t)
 '(c-basic-offset 4)
 '(c-default-style
	 '((c-mode . "user")
	 (c++-mode . "user")
	 (java-mode . "java")
	 (awk-mode . "awk")
	 (other . "gnu")))
 '(calendar-bahai-all-holidays-flag t)
 '(calendar-chinese-all-holidays-flag t)
 '(calendar-christian-all-holidays-flag t)
 '(calendar-date-style 'iso)
 '(calendar-hebrew-all-holidays-flag t)
 '(calendar-islamic-all-holidays-flag t)
 '(calendar-mark-diary-entries-flag t)
 '(calendar-mark-holidays-flag t)
 '(calendar-view-diary-initially-flag t)
 '(calendar-view-holidays-initially-flag t)
 '(column-number-mode t)
 '(completion-pcm-complete-word-inserts-delimiters t)
 '(completion-styles
	 '(basic partial-completion emacs22 shorthand substring flex emacs21 initials))
 '(completions-detailed t)
 '(completions-group t)
 '(completions-group-sort 'ignore)
 '(context-menu-functions
	 '(context-menu-undo context-menu-region context-menu-middle-separator context-menu-local context-menu-minor context-menu-middle-separator context-menu-ffap context-menu-middle-separator context-menu-ffap))
 '(context-menu-mode t)
 '(current-language-environment "UTF-8")
 '(custom-enabled-themes '(smart-mode-line-respectful doom-snazzy))
 '(default-input-method "rfc1345")
 '(default-transient-input-method "compose")
 '(delete-selection-mode t)
 '(describe-char-unidata-list
	 '(name general-category canonical-combining-class decomposition numeric-value iso-10646-comment))
 '(desktop-save-mode t)
 '(diary-abbreviated-year-flag t)
 '(dired-ls-F-marks-symlinks t)
 '(display-time-24hr-format t)
 '(display-time-day-and-date t)
 '(display-time-format "%a %F %T %Z")
 '(display-time-mode t)
 '(ediff-window-setup-function 'ediff-setup-windows-plain)
 '(electric-layout-mode t)
 '(electric-pair-mode t)
 '(electric-quote-context-sensitive t)
 '(electric-quote-mode t)
 '(emacs-lock-default-locking-mode 'kill)
 '(emojify-emoji-set "twemoji-v2-22")
 '(file-preserve-symlinks-on-save t)
 '(font-lock-global-modes '(not speedbar-mode))
 '(frame-background-mode 'dark)
 '(fringe-mode nil nil (fringe))
 '(global-display-line-numbers-mode t)
 '(global-hi-lock-mode t)
 '(global-hl-line-mode t)
 '(global-prettify-symbols-mode t)
 '(gpm-mouse-mode nil)
 '(helm-allow-mouse t)
 '(helm-autoresize-mode t)
 '(hexl-iso "-iso")
 '(hi-lock-file-patterns-policy 'never)
 '(history-delete-duplicates t)
 '(ibuffer-default-shrink-to-minimum-size t)
 '(ibuffer-default-sorting-mode 'filename/process)
 '(ibuffer-mode-hook '(ibuffer-auto-mode))
 '(ibuffer-view-ibuffer t)
 '(icomplete-mode t)
 '(ignored-local-variable-values '((mangle-whitespace . t)))
 '(image-animate-loop t)
 '(indicate-buffer-boundaries 'right)
 '(indicate-empty-lines t)
 '(inhibit-startup-screen t)
 '(initial-scratch-message " ;; scratch
")
;'(insert-esv-crossway-api-key "REDACTED-DUE-TO-BIBLE-POLICE") ;; https://api.esv.org
 '(j-console-cmd "jconsole")
 '(kill-whole-line t)
 '(list-colors-sort 'name)
 '(menu-bar-mode nil)
 '(minibuffer-eldef-shorten-default t)
 '(minibuffer-electric-default-mode t)
 '(minibuffer-message-clear-timeout 7)
 '(minibuffer-prompt-properties '(read-only t cursor-intangible t face minibuffer-prompt))
 '(mouse-drag-and-drop-region 'control)
 '(msb-files-by-directory t)
 '(msb-mode t)
 '(org-agenda-files "~/.agenda_files")
 '(org-enforce-todo-checkbox-dependencies t)
 '(org-enforce-todo-dependencies t)
 '(org-log-done 'time)
 '(org-log-note-clock-out t)
 '(org-todo-keywords '((sequence "TODO" "IN-P" "DONE")))
 '(package-selected-packages
	 '(php-mode raku-mode chemtable chinese-conv cangjie buffer-sets anki-mode anki-editor anki-vocabulary ivariants annotate restart-emacs turing-machine kurecolor diminish-buffer pyim org-drill eshell-vterm julia-vterm org-tag-beautify org-sidebar org-pretty-tags name-this-color native-complete frame-purpose format-table glsl-mode helm-j-cheatsheet jack-connect japanese-holidays org-index org-random-todo org-table-color pinyin-search racket-mode smartparens rust-mode csv-mode insert-esv inform7 indent-lint ibuffer-project ibuffer-vc howdoyou hl-sentence hl-block-mode helpful helm-mode-manager helm-ispell helm-helm-commands helm-ghs helm-firefox helm-frame ac-helm opencc youdao-dictionary balanced-windows ansi aggressive-fill-paragraph ac-js2 ac-math ac-emoji js2-mode context-coloring j-mode live-preview luarocks lua-mode midi-kbd muse num3-mode number pinyin powershell fsharp-mode try darkroom ascii-art-to-unicode electric-operator dired-quick-sort helm-git helm-google helm-org helm-unicode helm-w32-launcher helm-wikipedia helm-youtube org-books dired-single helm-lastpass ahk-mode alda-mode rainbow-delimiters helm electric-spacing annoying-arrows-mode smart-cursor-color doom-themes desktop-registry desktop+ metronome lastpass freeze-it vlc add-hooks google-this google-translate shut-up sml-modeline buffer-expose lingva org-notebook visual-ascii-mode prettier nhexl-mode linguistic holy-books gnuplot tabula-rasa diary-manager quiz rainbow-mode insert-random dimmer ilist blist better-jumper ac-octave abc-mode ac-html prettify-math pretty-mode ac-haskell-process aggressive-completion aggressive-indent keycast ibuffer-git fold-this htmlize i-ching which-key validate-html ibuffer-sidebar kaolin-themes smart-mode-line haskell-mode julia-mode emojify unicode-fonts tide ws-butler uni-confusables vlf typescript-mode))
 '(pcomplete-autolist t)
 '(read-buffer-completion-ignore-case t)
 '(remember-in-new-frame t)
 '(save-place-mode t)
 '(scroll-bar-mode nil)
 '(server-mode t)
 '(server-use-tcp t)
 '(show-paren-delay 0.1)
 '(show-paren-ring-bell-on-mismatch t)
 '(size-indication-mode t)
 '(sml/not-modified-char "=")
 '(sml/read-only-char "%")
 '(sml/show-frame-identification t)
 '(sml/theme 'respectful)
 '(tab-bar-close-button-show nil)
 '(tab-bar-close-last-tab-choice 'delete-frame)
 '(tab-bar-close-tab-select 'left)
 '(tab-bar-format
	 '(tab-bar-format-menu-bar tab-bar-format-history tab-bar-format-tabs tab-bar-separator tab-bar-format-align-right keycast-tab-bar keycast-))
 '(tab-bar-history-mode t)
 '(tab-bar-mode t)
 '(tab-bar-new-tab-choice 'bookmark-bmenu-get-buffer)
 '(tab-bar-new-tab-group nil)
 '(tab-bar-tab-hints t)
 '(tab-bar-tab-post-change-group-functions '(tab-bar-move-tab-to-group))
 '(tab-width 4)
 '(tool-bar-mode nil)
 '(tool-bar-style 'text)
 '(unicode-fonts-debug-availability t)
 '(unicode-fonts-fallback-font-list '("Noto Sans Mono" "DejaVu Sans Mono" "Symbola"))
 '(unicode-fonts-ignore-overrides t)
 '(visible-bell t))

(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(default ((t (:family "Noto Sans Mono" :foundry "outline" :slant normal :weight normal :height 120 :width normal))))
 '(bookmark-face ((t (:background "DeepPink4" :foreground "deeppink1" :weight bold))))
 '(helm-selection ((t (:inherit (default default) :extend t :background "blue violet" :foreground "azure" :underline (:color foreground-color :style wave)))))
 '(hi-aquamarine ((t (:background "aquamarine" :foreground "black" :weight bold))))
 '(hi-black-b ((t (:background "azure" :foreground "black" :weight bold))))
 '(hi-black-hb ((t (:height 1.67 :weight bold :foreground "black" :background "azure1" :inherit variable-pitch))))
 '(hi-blue ((t (:background "dark slate blue" :foreground "white" :weight bold))))
 '(hi-blue-b ((t (:background "RoyalBlue2" :foreground "black" :weight bold))))
 '(hi-green ((t (:background "#037a50" :foreground "white" :weight bold))))
 '(hi-pink ((t (:background "hot pink" :foreground "black" :weight bold))))
 '(hi-red-b ((t (:background "IndianRed4" :foreground "white" :weight bold))))
 '(hi-salmon ((t (:background "light salmon" :foreground "black" :weight bold))))
 '(hi-yellow ((t (:background "DarkGoldenrod4" :foreground "white" :weight bold))))
 '(hl-line ((t (:extend t :background "#1c1e26"))))
 '(keycast-key ((t (:inherit tab-bar-tab))))
 '(minibuffer-depth-indicator ((t (:box (:line-width (2 . 2) :color "grey75" :style released-button) :inherit highlight))))
		 '(tab-bar ((t (:background "gray10" :foreground "#fcefe6"))))
 '(tab-bar-tab ((t (:background "#303f3a" :foreground "#fcefe6" :box (:line-width (1 . 1) :color "grey75" :style pressed-button) :overline "black" :weight semi-bold))))
 '(tab-bar-tab-group-current ((t (:weight bold :box (:line-width (2 . 2) :color "grey75" :style pressed-button) :background "aquamarine4" :inherit tab-bar-tab))))
 '(tab-bar-tab-group-inactive ((t (:inherit tab-bar-tab-inactive :background "gray10" :box (:line-width (1 . 1) :color "cornsilk3" :style released-button) :slant oblique :weight ultra-bold))))
 '(tab-bar-tab-inactive ((t (:background "#1f1f1f" :foreground "cornsilk4" :overline t :slant italic))))
 '(tab-bar-tab-ungrouped ((t (:inherit (shadow tab-bar-tab-inactive) :overline "bisque2")))))

(cond
 ((string= system-type "gnu/linux")
	(setq d-drive "/media/DATA")
	(setq sys_root "/")
	)

 ((string= system-type "windows-nt")
	(setq d-drive "D:")
;	(setq sys_root "C:/your-posix-here")) ;; i use cygwin and wsl together it's kind of a mess
	)
 )

(setenv "D" d-drive)
(setenv "d" d-drive)
(setenv "ed" "~/.emacs.d/")
(setenv "org" (concat d-drive "/Documents/org"))
(setenv "dot" (concat d-drive "/code/dotfiles"))

(setenv "PATH" (concat
				sys_root "usr/local/bin" path-separator
				sys_root "usr/bin" path-separator
				sys_root "bin" path-separator
				(getenv "PATH")))

(dolist (package package-selected-packages)
	(unless (package-installed-p package)
		(package-install package)))

(require 'unicode-fonts)
(unicode-fonts-setup)

(setq-default default-directory "~/")
(setq diary-file (concat (getenv "org") "/diary"))
(setq compilation-filenames '("Makefile" "makefile"))

(defun mp-elisp-mode-eval-buffer ()
	(interactive)
	(message "Evaluated buffer")
	(eval-buffer))

(define-key emacs-lisp-mode-map (kbd "C-c C-c") #'mp-elisp-mode-eval-buffer)
(define-key emacs-lisp-mode-map (kbd "C-c c") #'eval-region)
(define-key lisp-interaction-mode-map (kbd "C-c C-c") #'mp-elisp-mode-eval-buffer)
(define-key lisp-interaction-mode-map (kbd "C-c c") #'eval-region)

(put 'downcase-region 'disabled nil)
(put 'upcase-region 'disabled nil)

(defadvice hi-lock-set-pattern (around use-overlays activate)
	(let ((font-lock-fontified nil))
		ad-do-it))

(global-set-key (kbd "C-x C-b") 'ibuffer)

(global-set-key (kbd "C-c C-+") 'number/add)
(global-set-key (kbd "C-c C--") 'number/sub)
(global-set-key (kbd "C-c C-*") 'number/multiply)
(global-set-key (kbd "C-c C-/") 'number/divide)
(global-set-key (kbd "C-c C-0") 'number/pad)
(global-set-key (kbd "C-c C-=") 'number/eval)

(add-hooks '(((prog-mode html-mode css-mode)
				. (lambda ()
					(setq auto-complete-mode t)
					(setq aggressive-completion-mode t)
					(setq show-trailing-whitespace t)
					(rainbow-delimiters-mode)
					(smartparens-mode)
					(add-to-list 'write-file-functions 'delete-trailing-whitespace)
					))))

(add-hooks '(((org-mode enriched-mode)
				. (lambda ()
					(auto-fill-mode)))))

(add-hook 'highlight-parentheses-mode-hook
					(lambda ()
						(setq autopair-handle-action-fns
									(append (if autopair-handle-action-fns autopair-handle-action-fns '(autopair-default-handle-action))
							'((lambda (action pair pos-before)
								(hl-paren-color-update)))))))
(add-hook 'python-mode-hook
			(lambda ()
			(setq-default py-indent-tabs-mode t)
			(add-to-list 'write-file-functions 'delete-trailing-whitespace)))

(defun get-makefile ()
	(if (file-exists-p "Makefile") (concat "")
	(let ((dir (locate-dominating-file "." "Makefile")))
			(when dir (concat "-C " dir)))))

(require 'smartparens-config)

(smart-mode-line-enable)
(keycast-tab-bar-mode 1)

(defun color-py () ; doesnt really work right
	(interactive)
	(beginning-of-buffer)
	(highlight-phrase (rx
					 (in "āēīōūǖ"))
					'hi-red-b)
	(highlight-phrase (rx
					 (in "áéíóúǘ"))
					'hi-yellow)
	(highlight-phrase (rx
					 (in "ǎěǐǒǔǚ"))
					 'hi-green)
	(highlight-phrase (rx
					 (in "àèìòùǜ"))
					'hi-blue))