; installed packages
; (elpy, undo-tree, evil, evil-tabs, realgud, smooth-scrolling, smart-compile, nyan-mode, emojify)

(toggle-frame-maximized)

(require 'package)
(let* ((no-ssl (and (memq system-type '(windows-nt ms-dos))
                    (not (gnutls-available-p))))
       (proto (if no-ssl "http" "https")))
  (add-to-list 'package-archives (cons "melpa-stable" (concat proto "://melpa.org/packages/")) t)
  (add-to-list 'package-archives '("org" . "http://orgmode.org/elpa/") t)
  (when (< emacs-major-version 24)
    (add-to-list 'package-archives '("gnu" . (concat proto "://elpa.gnu.org/packages/")))))
(package-initialize)

(elpy-enable)

(add-to-list 'load-path "~/.emacs.d/lisp/")

;;; general configs
(menu-bar-mode -1)
(tool-bar-mode -1)

(global-eldoc-mode -1)

(setq x-select-enable-clipboard t)

(global-set-key (kbd "C-.") #'other-window)
(global-set-key (kbd "C-,") #'prev-window)

(defun prev-window ()
  (interactive)
    (other-window -1))

(setq savehist-additional-variables
	'(search-ring regexp-search-ring))
(setq savehist-file "~/.emacs.d/savehist")
(savehist-mode 1)

(add-hook 'emacs-lisp-mode-hook 'ielm-auto-complete)

(setq explicit-shell-file-name "/bin/zsh")
(setq tramp-shell-prompt-pattern "^[^$>\n]*[#$%>] *\\(\[[0-9;]*[a-zA-Z] *\\)*")

;(autoload 'notmuch "notmuch" "notmuch mail" t)
;(require 'bbdb)
;(require 'org-notmuch)
;(setq smtpmail-smtp-server "smtp.gmail.com"
;      smtpmail-smtp-service 587)

(require 'evil)
(evil-mode t)
(setq-default evil-search-module 'evil-search)
;(global-evil-tabs-mode t)

; evil stuff for TABS & programming
; if something starts getting fucked up on indendation side, just comment out this whole block!
(add-hook 'python-mode-hook
	(lambda ()
		;(global-set-key (kbd "TAB") 'self-insert-command)
		(setq indent-tabs-mode t)
		(setq python-indent-offset 4)
		(setq tab-width 4)))

(require 'smart-compile)

(require 'ido)
(ido-mode 1)
(setq ido-ignore-buffers '("^ " "*Completions*" "*Shell Command Output*"
		"*Messages*" "*scratch*" "Async Shell Command"))

(setq backup-directory-alist `((".*" . "~/.emacs.d/saves")))
(setq auto-save-file-name-transforms
	`((".*" "~/.emacs.d/saves")))

(load-file "~/.emacs.d/undo-tree.el")
(global-undo-tree-mode)
(setq undo-tree-auto-save-history t)
(save-place-mode 1)

(setq inhibit-startup-screen t)
(setq initial-scratch-message "")
(setq initial-major-mode 'text-mode)

(require 'smooth-scrolling)
(smooth-scrolling-mode 1)
; (setq smooth-scroll-margin 5)

(set-default-font "Hack 13")
(global-display-line-numbers-mode)
(column-number-mode)

;(add-hook 'after-init-hook 'global-color-identifiers-mode)

;;; org-mode
(require 'org)
(setq org-tag-faces '(("important" . (:foreground "red"))
					 ("revisit" . (:foreground "white"))))

;; Reset the global variable to nil, just in case org-mode has already been used
;;(when org-tags-special-faces re
;;	(setq org-tags-special-faces-re nil))

(setq org-hide-emphasis-markers t)

(add-to-list 'auto-mode-alist '("\\.org\\'" . org-mode)) ;; activate org-mode agenda view
(global-set-key "\C-cl" 'org-store-link)
(global-set-key "\C-ca" 'org-agenda)
(global-set-key "\C-cc" 'org-capture)
(global-set-key "\C-cb" 'org-iswitchb)

(setq org-log-done 'time)
(setq org-agenda-log-mode-items '(state))
(setq org-todo-keywords
	'((sequence "TODO(t)" "IN PROGRESS(i)" "REVIEW(r)" "PROJECT" "REPEATING" "WAITING(w@/!)" "PAUSED(p)" "|" "DONE(d!)" "CANCELLED(c@)")))
(setq org-todo-keyword-faces
	'(("IN PROGRESS" . "DarkOrange") ("WAITING" . "magenta") ("CANCELLED" . "red") ("DONE" . "green") ("PAUSED" . "orchid"))
 )

(setq org-priority-faces '((65 :foreground "cyan") ; :background "color"
						   (66 :foreground "deep sky blue")
						   (67 . "royal blue")))

(setq org-agenda-use-time-grid t)
(setq org-agenda-time-grid
	(quote
		((daily today remove-match)
		(1000 1200 1400 1600 1800 2000)
		"......" "----------------")))

(setq org-cycle-separator-lines 1)
(add-hook 'org-mode-hook 'visual-line-mode)

;;; latex things
(setq org-format-latex-options (plist-put org-format-latex-options :scale 4.0))

;;; custom random shit
;;; https://lists.gnu.org/archive/html/emacs-orgmode/2016-06/msg00484.html
;;; http://kitchingroup.cheme.cmu.edu/blog/2016/11/04/New-link-features-in-org-9/
(org-link-set-parameters
  "red"
  :face '(:foreground "red"))
(org-link-set-parameters
  "green"
  :face '(:foreground "green"))

;;; emacs auto things
(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.
 '(custom-enabled-themes (quote (tango-dark)))
 '(ein:jupyter-default-server-command "/home/m/.local/bin/jupyter")
 '(ein:polymode t)
 '(org-agenda-files (quote ("~/org/generaltodo.org")))
 '(org-preview-latex-image-directory "~/org/")
 '(package-selected-packages
   (quote
    (md4rd tuareg evil-magit git github-review ein org-babel-eval-in-repl elpygen bbdb smart-compile ac-emoji emojify nyan-mode evil-tabs realgud smooth-scrolling evil elpy))))
(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.
 )
