* Looks
** Font
#+begin_src emacs-lisp
  (set-frame-font "MonoLisa 18" nil t)
  (set-fontset-font t '(#x1f000 . #x1faff) (font-spec :family "Myne Noto Color Emoji"))
#+end_src
** Themes
#+begin_src emacs-lisp
  (use-package afternoon-theme
    :ensure t
    :config
    (load-theme 'afternoon t)
    )
  (use-package modus-themes
    :ensure t
    :config
    ;;(load-theme 'modus-operandi t)
    )
#+end_src
** UI
*** Split vertical defaul
#+begin_src emacs-lisp
  (setq split-width-threshold nil)
#+end_src
*** Lines Numbers
#+begin_src emacs-lisp
  (global-display-line-numbers-mode)
  (setq display-line-numbers-type 'relative)
#+end_src
*** Dashboard
Set up some config functions

Configure layout
#+begin_src emacs-lisp
  (defun setup-dashboard-looks ()
    "Config ideas https://github.com/emacs-dashboard/emacs-dashboard"
    (evil-define-key 'normal dashboard-mode-map (kbd "r") 'dashboard-section-1)
    (evil-define-key 'normal dashboard-mode-map (kbd "J") 'dashboard-next-section)
    (evil-define-key 'normal dashboard-mode-map (kbd "K") 'dashboard-previous-section)
    (setq dashboard-startup-banner "~/.emacs.d/OnePiece.gif")
    (setq dashboard-banner-logo-title "Lets get coddiinnngggg")
    (setq dashboard-show-shortcuts t)
    (setq dashboard-items '((recents . 5)
			    (projects . 5)))
    (setq dashboard-item-names '(("Recent Files:" . "💫 Recent Files, probably not decent:")
				 ("Projects:" . "Projects 🆓, probably also not decent:")))
    ;; Curently broken ☣️ 
    (setq dashboard-center-content nil)
    ;;(setq dashboard-set-heading-icons t)
    ;;(setq dashboard-set-file-icons t)
    (setq dashboard-footer-messages '("Sleepyyyyy 🥱"
				      "Uhhhh I am lost"
				      "🆓 Just go watch anime 🆓"
				      "Compiler Error ☣️ Upssss!"
				      "❤️ Its Coddiinnnng timee"))
    )
#+end_src

Try to make dashboard appear when opening a file as well
#+begin_src emacs-lisp
  ;;  (defun setup-dashboard-on-multiple ()
  ;;    (interactive)
  ;;    (if (> (length command-line-args) 2)
  ;;	(progn
  ;;	  (split-window-below)
  ;;	  (balance-windows)
  ;;	  (other-window 1)
  ;;	  )
  ;;	(message (concat "Got" (number-to-string (length command-line-args)))))

  (defun open-dashboard-on-split ()
    "Opens the dashboard on a new split window"
    (interactive)
    (split-window-below)
    (balance-windows)
    (other-window 1)
    (generate-new-buffer "*dashboard*")
    (switch-to-buffer "*dashboard*")
    (dashboard-insert-startupify-lists)
    (window-resize (get-buffer-window) (- (floor (* (window-total-height (get-buffer-window)) 0.4))))
    (other-window 1))

  (defun setup-dashboard-on-multiple ()
    "Setups the dashboard when args are provided"
    (interactive)
    (if (>= (length command-line-args) 2)
	(open-dashboard-on-split)))
#+end_src

Setup stuff
#+begin_src emacs-lisp
  (defun evil-dashboard-setup ()
    (setup-dashboard-looks) 
    (setup-dashboard-on-multiple))
#+end_src

#+begin_src emacs-lisp
  (use-package dashboard
    :ensure t
    :after (evil)
    :config
    (evil-dashboard-setup)
    (dashboard-setup-startup-hook))
#+end_src
*** Ivy
#+begin_src emacs-lisp
  (use-package ivy
    :ensure t
    :config
    (ivy-mode))
#+end_src
Consel
#+begin_src emacs-lisp
  (use-package counsel
    :ensure t
    :config
    (counsel-mode))
#+end_src
*** Which key
#+begin_src emacs-lisp
  (use-package which-key
    :ensure t
    :config
    (which-key-mode))
#+end_src
*** Disable Window Top bar
#+begin_src emacs-lisp
  (menu-bar-mode -1)
  (tool-bar-mode -1)
#+end_src

** Langs
Set up tree sitter
#+begin_src emacs-lisp
  (use-package tree-sitter
    :ensure t
    :hook (tree-sitter-after-on . tree-sitter-hl-mode)
    :config
    (global-tree-sitter-mode))
  (use-package tree-sitter-langs
    :ensure t)
#+end_src
*** ts
Setup typescript mode
#+begin_src emacs-lisp
  (use-package typescript-mode
    :ensure t
    :after (tree-sitter)
    :config
    ;;(define-derived-mode typescriptreact-mode typescript-mode
    ;;  "TypeScript TSX")
    ;;(add-to-list 'auto-mode-alist '("\\.tsx?\\'" . typescriptreact-mode))
    ;;(add-to-list 'tree-sitter-major-mode-language-alist '(typescriptreact-mode . tsx))
    )
#+end_src
Setup tree sitter based indentation
#+begin_src emacs-lisp
  ;; great tree-sitter-based indentation for typescript/tsx, css, json
;;  (use-package tsi
;
;;    :quelpa (tsi :fetcher github :repo "orzechowskid/tsi.el")
;;    ;; define autoload definitions which when actually invoked will cause package to be loaded
;;    :commands (tsi-typescript-mode tsi-json-mode tsi-css-mode)
;;    :init
;;    (add-hook 'typescript-mode-hook (lambda () (tsi-typescript-mode 1)))
;;    (add-hook 'json-mode-hook (lambda () (tsi-json-mode 1)))
;;    (add-hook 'css-mode-hook (lambda () (tsi-css-mode 1)))
;;    (add-hook 'scss-mode-hook (lambda () (tsi-scss-mode 1))))
#+end_src
*** tsx
#+begin_src emacs-lisp
;;  (use-package coverlay
;;	:ensure t)
;;
;;  (use-package origami
;;	:ensure t)
;;
;;  (use-package css-in-js-mode
;;	:straight '(css-in-js-mode
;;		:type git
;;		:host github
;;		:repo "orzechowskid/tree-sitter-css-in-js"))
;;
;;  (use-package corfu
;;	:ensure t)
;;  
;;  (setq eglot-server-programs '())
;;  (use-package tsx-mode
;;	:straight '(tsx-mode
;;		:type git
;;		:host github
;;		:repo "orzechowskid/tsx-mode.el"
;;		:branch "emacs29")
;;	:config
;;	(add-to-list 'auto-mode-alist '("\\.tsx?\\'" . tsx-mode)))
#+end_src
*** webmode
#+begin_src emacs-lisp
  (use-package web-mode
    :ensure t
    :config
    ;;(add-to-list 'auto-mode-alist '("\\.tsx?\\'" . web-mode))
    )
#+end_src
* Settings
** Backup files
#+begin_src emacs-lisp
  (setq
   make-backup-files nil
   backup-directory-alist '(("." . "/tmp/"))
   auto-save-file-name-transforms '((".*" "/tmp/" t)))
#+end_src
** Startup screen
#+begin_src emacs-lisp
  (setq inhibit-splash-screen t)
#+end_src

** Tabs
#+begin_src emacs-lisp
  (setq-default tab-width 4)
#+end_src
* Evil
** Base Functions
#+begin_src emacs-lisp
  (defun my-evil-quit (old-fun &rest args)
    (if (eq major-mode 'org-src-mode)
      (org-edit-src-exit)
      (apply old-fun args)))

  (defun my-evil-save (old-fun &rest args)
    (if (eq major-mode 'org-src-mode)
      (org-edit-src-save)
      (apply old-fun args)))

  (advice-add #'evil-save :around #'my-evil-save)
  (advice-add #'evil-quit :around #'my-evil-quit)
#+end_src
** Base
*** Configure
#+begin_src emacs-lisp
  (defun setup-evil-mode ()
	(evil-define-key 'insert global-map (kbd "C-SPC") 'company-complete)
	(evil-define-key 'normal global-map
	  (kbd "]e") 'flycheck-next-error
	  (kbd "[e") 'flycheck-previous-error
	  (kbd "gd") 'lsp-find-definition
	  (kbd "K") 'lsp-ui-doc-show
	  (kbd "gr") 'lsp-find-references)
	)
#+end_src
*** Install
#+begin_src emacs-lisp
  (use-package evil
    :ensure
    :after (evil-leader)
    :config
    (setup-evil-mode)
    (evil-mode 1))
#+end_src
** Leader
#+begin_src emacs-lisp
  (use-package evil-leader
    :ensure t
    :config
    (global-evil-leader-mode)
    ; Set leader
    (evil-leader/set-leader "<SPC>")
    (evil-leader/set-key
      "f" 'find-file
      "SPC" 'projectile-find-file
      "d" 'dired
      "b" 'ivy-switch-buffer

      "c" '("config" . (keymap))
      "cf" '("config file" . (lambda ()(interactive) (find-file (expand-file-name "~/.emacs.d/settings.org"))))
      "c+" '("config file" . (lambda ()(interactive) (text-scale-increase)))
      "c-" '("config file" . (lambda ()(interactive) (text-scale-decrease)))

      "p" '("project" . (keymap))
      "pf" '("file" . (lambda () (interactive)(projectile-find-file)))

      "g" '("goto" . (keymap))
      "gg" 'magit
      "gd" '("Goto Definition" . (lambda () (interactive)(evil-goto-definition)))

      )
    (evil-leader/set-key-for-mode 'org-mode
      "is" 'org-insert-structure-template
      "e" 'org-edit-src-code)
    )
#+end_src
** Org Mode
#+begin_src emacs-lisp
  (use-package evil-org
    :ensure t
    :after (org evil)
    :hook (org-mode . evil-org-mode))
#+end_src

* Projects
** Projectile
#+begin_src emacs-lisp
  (use-package projectile
    :ensure t
    :config
    (define-key projectile-mode-map (kbd "C-c p") 'projectile-command-map)
    ;;(setq projectile-git-command "git-ls-all-files")
    (projectile-mode +1))
#+end_src
** Magit
#+begin_src emacs-lisp
  (use-package magit
    :ensure t)
#+end_src
Auto complete
* LSP
** Company
#+begin_src emacs-lisp
  (use-package company
    :ensure t
    :config
    (global-company-mode))
#+end_src
*** Comapny box
#+begin_src emacs-lisp
  (use-package company-box
	:ensure t
	:hook (company-mode . company-box-mode))
#+end_src
** LSP
Set up lsp
#+begin_src emacs-lisp
  (use-package lsp-mode
	:init
	(setq lsp-keymap-prefix "C-c l")
	:ensure t
	:hook (
		   ;;(XXX-mode . lsp-mode)

		   ;;(typescriptreact-mode	. lsp-mode)
		   ;;(tsx-mode				. lsp-mode)
		   ;;(tsx-ts-mode			. lsp-mode)
		   (typescript-mode		. lsp-mode)
		   (web-mode				. lsp-mode)

		   (lsp-mode . lsp-enable-which-key-integration))
	:commands  lsp
	:config
	;;(add-hook 'tsx-mode-hook 'lsp-mode)
	)
#+end_src
Set up lsp ui
#+begin_src emacs-lisp
  (use-package lsp-ui
	:ensure t
	:commands lsp-ui-mode
	:config
	;; sideline
	(setq lsp-ui-sideline-show-diagnostics nil)
	(setq lsp-ui-sideline-show-code-actions nil)
	(setq lsp-ui-sideline-show-hover t)
	(setq lsp-ui-sideline-delay 0)
	;; ui-doc
	(setq lsp-ui-doc-enable t)
	(setq lsp-ui-doc-delay 1)
	(setq lsp-ui-doc-show-with-cursor t)
	(setq lsp-ui-doc-show-with-mouse nil)
	(setq lsp-ui-doc-position 'at-point)
	)
#+end_src
Set up ivy
#+begin_src emacs-lisp
  (use-package lsp-ivy
    :ensure t
    :commands lsp-ivy-workspace-symbol)
#+end_src
** Flycheck
*** Helper function
#+begin_src emacs-lisp
  (defun define-level-info (name severity compilation-level margin-str)
	  (flycheck-define-error-level name
		:severity severity
		:compilation-level compilation-level
		:overlay-category 'flycheck-info-overlay
		:margin-spec (flycheck-make-margin-spec margin-str 'flycheck-fringe-info)
		:fringe-bitmap'flycheck-fringe-bitmap-double-arrow
		:fringe-face 'flycheck-fringe-info
		:error-list-face 'flycheck-error-list-info))
#+end_src
*** Flycheck
#+begin_src emacs-lisp
  (use-package flycheck
	:ensure t
	:init(global-flycheck-mode)
	:config
	;; Show indicators in the left margin
	(setq flycheck-indication-mode 'left-margin)

	;; Adjust margins and fringe widths…
	(defun my/set-flycheck-margins ()
	  (setq left-fringe-width 0 right-fringe-width 0
		left-margin-width 2 right-margin-width 0)
	  (setq flycheck-default-margin-str "🆓")
	  (flycheck-refresh-fringes-and-margins))

	(flycheck-define-error-level 'error
	  :severity 100
	  :compilation-level 2
	  :overlay-category 'flycheck-error-overlay
	  :margin-spec (flycheck-make-margin-spec "❤️" 'flycheck-fringe-error)
	  :fringe-bitmap 'flycheck-fringe-bitmap-double-arrow
	  :fringe-face 'flycheck-fringe-error
	  :error-list-face 'flycheck-error-list-error)

	(flycheck-define-error-level 'warning
	  :severity 10
	  :compilation-level 1
	  :overlay-category 'flycheck-warning-overlay
	  :margin-spec (flycheck-make-margin-spec "😞" 'flycheck-fringe-warning)
	  :fringe-bitmap'flycheck-fringe-bitmap-double-arrow
	  :fringe-face 'flycheck-fringe-warning
	  :error-list-face 'flycheck-error-list-warning)

	(define-level-info 'info -10 0 "🅰")
	(define-level-info 'lsp-flycheck-info-unnecessary -10 0 "🅰")
	(define-level-info 'hint -20 -1 "🆓")

	;; …every time Flycheck is activated in a new buffer
	(add-hook 'flycheck-mode-hook #'my/set-flycheck-margins)
	)
#+end_src
Fly check post tip
#+begin_src emacs-lisp
;;  (use-package flycheck-pos-tip
;;    :ensure t
;;    :hook (flycheck-mode . flycheck-pos-tip-mode))
#+end_src
Fly check inline (disabled because was getting annoyed)
#+begin_src emacs-lisp
;;  (use-package flycheck-posframe
;;	:ensure t
;;	:after flycheck
;;	:hook (flycheck-mode . flycheck-posframe-mode)
;;	:config
;;	(flycheck-posframe-configure-pretty-defaults)
;;	(setq flycheck-posframe-error-prefix "☣️❤️")
;;	(setq flycheck-posframe-warning-prefix "🅰😞")
;;	(setq flycheck-posframe-info-prefix "🅰🆓")
;;	(set-face-attribute 'flycheck-posframe-error-face
;;			nil
;;			:inherit nil
;;			:foreground "#b72c01")
;;	(set-face-attribute 'flycheck-posframe-warning-face
;;			nil
;;			:foreground "#b77401")
;;
;;	(set-face-attribute 'flycheck-posframe-info-face
;;			nil
;;			:foreground "#0156b7")
;;
;;	(setq flycheck-posframe-border-width 1)
;;	(setq flycheck-posframe-position 'point-top-left-corner)
;;
;;	(set-face-attribute 'flycheck-posframe-border-face
;;			nil
;;			:foreground "#dc752f")
;;	(add-to-list 'flycheck-posframe-inhibit-functions #'(lambda () company-backend)))
#+end_src
** TIDE
#+begin_src emacs-lisp
  (use-package tide
	:ensure t
	:after (typescript-mode company flycheck)
	:hook ((typescript-mode . tide-setup)
	   (typescript-mode . tide-hl-identifier-mode)
	   (before-save . tide-format-before-save)))

  (add-to-list 'auto-mode-alist '("\\.tsx?\\'" . typescript-mode))
#+end_src
