
#+title: PANKOMACS
#+author: Artur Manuel
#+PROPERTY: header-args :tangle config.el

* Emacs window stuff
Things like turning off the menubar, etc.
#+BEGIN_SRC emacs-lisp
  (use-package emacs
    :config
    (menu-bar-mode -1)
    (scroll-bar-mode -1)
    (tool-bar-mode -1)
    (recentf-mode 1)
    :custom
    (inhibit-startup-message t)
    (initial-scratch-message nil)
    (org-startup-with-inline-images t))
#+END_SRC

* Theming
** Nerd Fonts
May or may not need nerd fonts for some of the below packages. 8)
#+BEGIN_SRC emacs-lisp
  (use-package nerd-icons
    :custom
    (nerd-icons-font-family "Symbols Nerd Font Mono"))
#+END_SRC

** Theme
Using doom-themes here because Tokyo Night isn't on MELPA.
#+BEGIN_SRC emacs-lisp
  (use-package doom-themes
    :config
    (setq doom-themes-enable-bold t
  	doom-themes-enable-italic t)
    (load-theme 'doom-tokyo-night t)

    (doom-themes-visual-bell-config)
    (doom-themes-neotree-config)
    (setq doom-themes-treemacs-theme "doom-tokyo-night")
    (doom-themes-treemacs-config)
    (doom-themes-org-config))
#+END_SRC

** Doom Modeline
Also may not need doom modeline.
#+BEGIN_SRC emacs-lisp
  (use-package doom-modeline
    :ensure t
    :hook (after-init . doom-modeline-mode))
  
#+END_SRC

* Vertico, Orderless, and more stuff
Personal favourite emacs completer, and my computer can run it! 8)
#+BEGIN_SRC emacs-lisp
      (use-package vertico
        :custom
        (vertico-count 5)
        :init
        (vertico-mode)
        (keymap-set vertico-map "?" #'minibuffer-completion-help)
        (keymap-set vertico-map "M-RET" #'minibuffer-force-complete-and-exit)
        (keymap-set vertico-map "M-TAB" #'minibuffer-complete))

      (use-package orderless
        :custom
        (completion-styles '(orderless basic))
        (completion-category-defaults nil)
        (completion-category-overrides '((file (styles partial-completion))))
        :init
        (setq completion-in-region-function
      	  (lambda (&rest args)
      	    (apply (if vertico-mode
      		       #'consult-completion-in-region
      	     #'completion--in-region)
      		   args))))

      (use-package marginalia
        :bind (:map minibuffer-local-map
      		("M-A" . marginalia-cycle))
        :init
        (marginalia-mode))

      (use-package embark
        :ensure t
        :bind
        (("C-." . embark-act)
         ("C-;" . embark-dwim)
         ("C-h B" . embark-bindings))
        :init
        (setq prefix-help-command #'embark-prefix-help-command)
        (add-hook 'eldoc-documentation-functions #'embark-eldoc-first-target)
        (setq eldoc-documentation-strategy #'eldoc-documentation-compose-eagerly)
        :config
        (add-to-list 'display-buffer-alist
      	       '("\\`\\*Embark Collect \\(Live\\|Completions\\)\\*"
      		 nil
      		 (window-parameters (mode-line-format . none)))))

    ;; Example configuration for Consult
    (use-package consult
      ;; Replace bindings. Lazily loaded by `use-package'.
      :bind (;; C-c bindings in `mode-specific-map'
             ("C-c M-x" . consult-mode-command)
             ("C-c h" . consult-history)
             ("C-c k" . consult-kmacro)
             ("C-c m" . consult-man)
             ("C-c i" . consult-info)
             ([remap Info-search] . consult-info)
             ;; C-x bindings in `ctl-x-map'
             ("C-x M-:" . consult-complex-command)     ;; orig. repeat-complex-command
             ("C-x b" . consult-buffer)                ;; orig. switch-to-buffer
             ("C-x 4 b" . consult-buffer-other-window) ;; orig. switch-to-buffer-other-window
             ("C-x 5 b" . consult-buffer-other-frame)  ;; orig. switch-to-buffer-other-frame
             ("C-x t b" . consult-buffer-other-tab)    ;; orig. switch-to-buffer-other-tab
             ("C-x r b" . consult-bookmark)            ;; orig. bookmark-jump
             ("C-x p b" . consult-project-buffer)      ;; orig. project-switch-to-buffer
             ;; Custom M-# bindings for fast register access
             ("M-#" . consult-register-load)
             ("M-'" . consult-register-store)          ;; orig. abbrev-prefix-mark (unrelated)
             ("C-M-#" . consult-register)
             ;; Other custom bindings
             ("M-y" . consult-yank-pop)                ;; orig. yank-pop
             ;; M-g bindings in `goto-map'
             ("M-g e" . consult-compile-error)
             ("M-g f" . consult-flymake)               ;; Alternative: consult-flycheck
             ("M-g g" . consult-goto-line)             ;; orig. goto-line
             ("M-g M-g" . consult-goto-line)           ;; orig. goto-line
             ("M-g o" . consult-outline)               ;; Alternative: consult-org-heading
             ("M-g m" . consult-mark)
             ("M-g k" . consult-global-mark)
             ("M-g i" . consult-imenu)
             ("M-g I" . consult-imenu-multi)
             ;; M-s bindings in `search-map'
             ("M-s d" . consult-find)                  ;; Alternative: consult-fd
             ("M-s c" . consult-locate)
             ("M-s g" . consult-grep)
             ("M-s G" . consult-git-grep)
             ("M-s r" . consult-ripgrep)
             ("M-s l" . consult-line)
             ("M-s L" . consult-line-multi)
             ("M-s k" . consult-keep-lines)
             ("M-s u" . consult-focus-lines)
             ;; Isearch integration
             ("M-s e" . consult-isearch-history)
             :map isearch-mode-map
             ("M-e" . consult-isearch-history)         ;; orig. isearch-edit-string
             ("M-s e" . consult-isearch-history)       ;; orig. isearch-edit-string
             ("M-s l" . consult-line)                  ;; needed by consult-line to detect isearch
             ("M-s L" . consult-line-multi)            ;; needed by consult-line to detect isearch
             ;; Minibuffer history
             :map minibuffer-local-map
             ("M-s" . consult-history)                 ;; orig. next-matching-history-element
             ("M-r" . consult-history))                ;; orig. previous-matching-history-element

      ;; Enable automatic preview at point in the *Completions* buffer. This is
      ;; relevant when you use the default completion UI.
      :hook (completion-list-mode . consult-preview-at-point-mode)

      ;; The :init configuration is always executed (Not lazy)
      :init

      ;; Optionally configure the register formatting. This improves the register
      ;; preview for `consult-register', `consult-register-load',
      ;; `consult-register-store' and the Emacs built-ins.
      (setq register-preview-delay 0.5
            register-preview-function #'consult-register-format)

      ;; Optionally tweak the register preview window.
      ;; This adds thin lines, sorting and hides the mode line of the window.
      (advice-add #'register-preview :override #'consult-register-window)

      ;; Use Consult to select xref locations with preview
      (setq xref-show-xrefs-function #'consult-xref
            xref-show-definitions-function #'consult-xref)

      ;; Configure other variables and modes in the :config section,
      ;; after lazily loading the package.
      :config

      ;; Optionally configure preview. The default value
      ;; is 'any, such that any key triggers the preview.
      ;; (setq consult-preview-key 'any)
      ;; (setq consult-preview-key "M-.")
      ;; (setq consult-preview-key '("S-<down>" "S-<up>"))
      ;; For some commands and buffer sources it is useful to configure the
      ;; :preview-key on a per-command basis using the `consult-customize' macro.
      (consult-customize
       consult-theme :preview-key '(:debounce 0.2 any)
       consult-ripgrep consult-git-grep consult-grep
       consult-bookmark consult-recent-file consult-xref
       consult--source-bookmark consult--source-file-register
       consult--source-recent-file consult--source-project-recent-file
       ;; :preview-key "M-."
       :preview-key '(:debounce 0.4 any))

      ;; Optionally configure the narrowing key.
      ;; Both < and C-+ work reasonably well.
      (setq consult-narrow-key "<") ;; "C-+"

      ;; Optionally make narrowing help available in the minibuffer.
      ;; You may want to use `embark-prefix-help-command' or which-key instead.
      ;; (keymap-set consult-narrow-map (concat consult-narrow-key " ?") #'consult-narrow-help)
    )

    (use-package embark-consult
      :ensure t ; only need to install it, embark loads it after consult if found
      :hook
      (embark-collect-mode . consult-preview-at-point-mode))


  (use-package consult-dir
    :ensure t
    :bind (("C-x C-d" . consult-dir)
           :map minibuffer-local-completion-map
           ("C-x C-d" . consult-dir)
           ("C-x C-j" . consult-dir-jump-file)))

  (use-package consult-dir
    :ensure t
    :bind (("C-x C-d" . consult-dir)
           :map vertico-map
           ("C-x C-d" . consult-dir)
           ("C-x C-j" . consult-dir-jump-file)))

  ;; Configure directory extension.
  (use-package vertico-directory
    :after vertico
    :ensure nil
    ;; More convenient directory navigation commands
    :bind (:map vertico-map
                ("RET" . vertico-directory-enter)
                ("DEL" . vertico-directory-delete-char)
                ("M-DEL" . vertico-directory-delete-word))
    ;; Tidy shadowed file names
    :hook (rfn-eshadow-update-overlay . vertico-directory-tidy))
  
#+END_SRC

* Setting up languages
** GENERAL LANGUAGES
*** Flycheck
I will of course need flycheck for syntax checking stuff, also used for LSPS and whatnot.
#+BEGIN_SRC emacs-lisp
  (use-package flycheck
    :ensure t
    :config
    (add-hook 'after-init-hook #'global-flycheck-mode))
  
#+END_SRC
*** LSP
Enabling Emacs-LSP to use LSPs, I am very dry on syntax highlighters right now. :(
#+BEGIN_SRC emacs-lisp
  (use-package lsp-mode
    :custom
    (lsp-keymap-prefix "C-c l")
    :hook (
  	 (c++-mode . lsp)
  	 (lsp-mode . lsp-enable-which-key-integration))
    :commands lsp)

  (use-package lsp-ui :commands lsp-ui-mode)
  (use-package lsp-treemacs :commands lsp-treemacs-errors-list)
  (use-package consult-lsp :commands consult-lsp-symbols)
#+END_SRC
** SPECIFIC LANGUAGES
*** Nix
#+BEGIN_SRC emacs-lisp
  (use-package nix-ts-mode
    :mode "\\.nix\\'")
  
#+END_SRC
*** Rust
#+BEGIN_SRC emacs-lisp
  (use-package rustic
    :mode "\\.rs\\'"
    :hook (rust-mode . (lambda () (setq indent-tabs-mode nil))))
    
#+END_SRC
* Which-key
Amazing tool, love it a bunch.
#+BEGIN_SRC emacs-lisp
  (use-package which-key
    :config
    (which-key-mode))
#+END_SRC
* Treemacs
#+BEGIN_SRC emacs-lisp

  (use-package all-the-icons
    :if (display-graphic-p))
    
  (use-package treemacs
    :ensure t
    :defer t
    :init
    (with-eval-after-load 'winum
      (define-key winum-keymap (kbd "M-0") #'treemacs-select-window))
    :config
    (progn
      (setq treemacs-collapse-dirs                   (if treemacs-python-executable 3 0)
            treemacs-deferred-git-apply-delay        0.5
            treemacs-directory-name-transformer      #'identity
            treemacs-display-in-side-window          t
            treemacs-eldoc-display                   'simple
            treemacs-file-event-delay                2000
            treemacs-file-extension-regex            treemacs-last-period-regex-value
            treemacs-file-follow-delay               0.2
            treemacs-file-name-transformer           #'identity
            treemacs-follow-after-init               t
            treemacs-expand-after-init               t
            treemacs-find-workspace-method           'find-for-file-or-pick-first
            treemacs-git-command-pipe                ""
            treemacs-goto-tag-strategy               'refetch-index
            treemacs-header-scroll-indicators        '(nil . "^^^^^^")
            treemacs-hide-dot-git-directory          t
            treemacs-indentation                     2
            treemacs-indentation-string              " "
            treemacs-is-never-other-window           nil
            treemacs-max-git-entries                 5000
            treemacs-missing-project-action          'ask
            treemacs-move-files-by-mouse-dragging    t
            treemacs-move-forward-on-expand          nil
            treemacs-no-png-images                   nil
            treemacs-no-delete-other-windows         t
            treemacs-project-follow-cleanup          nil
            treemacs-persist-file                    (expand-file-name ".cache/treemacs-persist" user-emacs-directory)
            treemacs-position                        'right
            treemacs-read-string-input               'from-child-frame
            treemacs-recenter-distance               0.1
            treemacs-recenter-after-file-follow      nil
            treemacs-recenter-after-tag-follow       nil
            treemacs-recenter-after-project-jump     'always
            treemacs-recenter-after-project-expand   'on-distance
            treemacs-litter-directories              '("/node_modules" "/.venv" "/.cask")
            treemacs-project-follow-into-home        nil
            treemacs-show-cursor                     nil
            treemacs-show-hidden-files               t
            treemacs-silent-filewatch                nil
            treemacs-silent-refresh                  nil
            treemacs-sorting                         'alphabetic-asc
            treemacs-select-when-already-in-treemacs 'move-back
            treemacs-space-between-root-nodes        t
            treemacs-tag-follow-cleanup              t
            treemacs-tag-follow-delay                1.5
            treemacs-text-scale                      nil
            treemacs-user-mode-line-format           nil
            treemacs-user-header-line-format         nil
            treemacs-wide-toggle-width               70
            treemacs-width                           35
            treemacs-width-increment                 1
            treemacs-width-is-initially-locked       t
            treemacs-workspace-switch-cleanup        nil)

      ;; The default width and height of the icons is 22 pixels. If you are
      ;; using a Hi-DPI display, uncomment this to double the icon size.
      ;;(treemacs-resize-icons 44)

      (treemacs-follow-mode t)
      (treemacs-filewatch-mode t)
      (treemacs-fringe-indicator-mode 'always)
      (when treemacs-python-executable
        (treemacs-git-commit-diff-mode t))

      (pcase (cons (not (null (executable-find "git")))
                   (not (null treemacs-python-executable)))
        (`(t . t)
         (treemacs-git-mode 'deferred))
        (`(t . _)
         (treemacs-git-mode 'simple)))

      (treemacs-hide-gitignored-files-mode nil))
    :bind
    (:map global-map
          ("M-0"       . treemacs-select-window)
          ("C-x t 1"   . treemacs-delete-other-windows)
          ("C-x t t"   . treemacs)
          ("C-x t d"   . treemacs-select-directory)
          ("C-x t B"   . treemacs-bookmark)
          ("C-x t C-t" . treemacs-find-file)
          ("C-x t M-t" . treemacs-find-tag)))

  (use-package treemacs-icons-dired
    :hook (dired-mode . treemacs-icons-dired-enable-once)
    :ensure t)

  (use-package treemacs-nerd-icons
    :config
    (treemacs-load-theme "nerd-icons"))
  
  ; (use-package treemacs-evil
  ;   :after (treemacs evil)
  ;   :ensure t)
  ; (use-package treemacs-magit
  ;   :after (treemacs magit)
  ;   :ensure t)
  ; (use-package treemacs-persp ;;treemacs-perspective if you use perspective.el vs. persp-mode
  ;   :after (treemacs persp-mode) ;;or perspective vs. persp-mode
  ;   :ensure t
  ;   :config (treemacs-set-scope-type 'Perspectives))
  ; (use-package treemacs-tab-bar ;;treemacs-tab-bar if you use tab-bar-mode
  ;   :after (treemacs)
  ;   :ensure t
  ;   :config (treemacs-set-scope-type 'Tabs))
#+END_SRC
* Magit
Git in Emacs, it saves a fuck ton of time later down the road
#+BEGIN_SRC emacs-lisp
  (use-package magit
    :ensure t
    :bind (("C-x C-g" . magit-status)
	   ("C-x g" . magit-status)))
  
#+END_SRC
* Projectile
This makes stuff a lot easier I hope.
#+BEGIN_SRC emacs-lisp
  (use-package projectile
    :ensure t
    :init
    (projectile-mode +1)
    :bind (:map projectile-mode-map
		("s-p" . projectile-command-map)
		("C-c p" . projectile-command-map)))

  (use-package treemacs-projectile
    :after (treemacs projectile)
    :ensure t)

  (use-package treemacs-magit
    :after (treemacs magit)
    :ensure t)
  
#+END_SRC
