dotfiles/.emacs.d
Eduardo Cueto-Mendoza 94fcdc4d7b
Add new emacs configuration file
2025-01-12 17:47:41 +00:00
..
Org Add new emacs configuration file 2025-01-12 17:47:41 +00:00
.gitignore Add new emacs configuration file 2025-01-12 17:47:41 +00:00
README.org Add new emacs configuration file 2025-01-12 17:47:41 +00:00
init.el Add new emacs configuration file 2025-01-12 17:47:41 +00:00
projectile-bookmarks.eld Add new emacs configuration file 2025-01-12 17:47:41 +00:00

README.org

PACKAGE MANAGEMENT SYSTEM

STRAIGHT.EL

We are using straight.el intead of using package.el as our package manager, below is the boostrap code in order for it to work.

      ;; Install straight.el
      (defvar bootstrap-version)
      (let ((bootstrap-file
	     (expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
	    (bootstrap-version 6))
	(unless (file-exists-p bootstrap-file)
	  (with-current-buffer
	      (url-retrieve-synchronously
	       "https://raw.githubusercontent.com/radian-software/straight.el/develop/install.el"
	       'silent 'inhibit-cookies)
	    (goto-char (point-max))
	    (eval-print-last-sexp)))
	(load bootstrap-file nil 'nomessage))

USE PACKAGE

(setq straight-use-package-by-default t)

BACKUP

Put all backup files in the Trash can, by default emacs makes these annoying backup files on the filesystem and this will make it where those backups goto the trash

(setq backup-directory-alist '((".*" . "~/.local/share/Trash/files")))

PACKAGES

BEACON

BEACON is a package so you never lose your mouse cursor again, it will highlight a line where your mouse cursor is.

  (use-package beacon)
  (use-package doom-themes)

FOCUS

This is package that dims surrounding text while typing

(use-package focus)

MAGIT

Magit is a fully featured git client for emacs

(use-package magit)

RAINBOW Mode

Display the actual color for a hex value, works in all modes

(use-package rainbow-mode
:hook org-mode prog-mode)

Rainbow Delimiters

(use-package rainbow-delimiters
:hook ((org-mode . rainbow-delimiters-mode)
       (prog-mode . rainbow-delimiters-mode)))

Highlight TODO

Highlight certain words in documents and colorize them

(use-package hl-todo
  :hook ((org-mode . hl-todo-mode)
         (prog-mode . hl-todo-mode))
  :config
  (setq hl-todo-highlight-punctuation ":"
        hl-todo-keyword-faces
        `(("TODO"       warning bold)
          ("FIXME"      error bold)
          ("HACK"       font-lock-constant-face bold)
          ("REVIEW"     font-lock-keyword-face bold)
          ("NOTE"       success bold)
          ("DEPRECATED" font-lock-doc-face bold))))

WHICH-KEY

Which-key is a program to display what keys are next on your minibuffer

(use-package which-key
  :straight t
:init 
  (which-key-mode 1)
:config
(setq which-key-side-window-location 'bottom
      which-key-sort-order #'which-key-key-order
      which-key-allow-imprecise-window-fit nil
	  which-key-sort-uppercase-first nil
	  which-key-add-column-padding 1
	  which-key-max-display-columns nil
	  which-key-min-display-lines 6
	  which-key-side-window-slot -10
	  which-key-side-window-max-height 0.25
	  which-key-idle-delay 0.8
	  which-key-max-description-length 25
	  which-key-allow-imprecise-window-fit nil
	  which-key-separator " → " ))

VTERM

Vterm is a terminal emulator within in Emacs. The default shell is set to fish but it could be changed

(use-package vterm
:config
(setq shell-file-name "/bin/fish"
      vterm-max-scrollback 5000))

VTERM-TOGGLE

Vterm-toggle toggles between the vterm buffer and what ever buffer your editing

(use-package vterm-toggle
:after vterm
:config
(setq vterm-toggle-fullscreen-p nil)
(setq vterm-toggle-scope 'project)
(add-to-list 'display-buffer-alist
               '((lambda (buffer-or-name _)
                     (let ((buffer (get-buffer buffer-or-name)))
                       (with-current-buffer buffer
                         (or (equal major-mode 'vterm-mode)
                             (string-prefix-p vterm-buffer-name (buffer-name buffer))))))
                  (display-buffer-reuse-window display-buffer-at-bottom)
                  ;;(display-buffer-reuse-window display-buffer-in-direction)
                  ;;display-buffer-in-direction/direction/dedicated is added in emacs27
                  ;;(direction . bottom)
                  ;;(dedicated . t) ;dedicated is supported in emacs27
                  (reusable-frames . visible)
                  (window-height . 0.3))))

TREEMACS

(use-package treemacs
:ensure t
:defer t)

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

(use-package treemacs-persp
:after (treemacs persp-mode)
:ensure t
:config (treemacs-set-scope-type 'Perspectives))

DOOM-MODELINE

Doom-modeline is a modeline for your minibuffer, doom-modeline was inspired by 'doom-emacs'

(use-package doom-modeline
  :straight t
  :init (doom-modeline-mode 1))

ALL-THE-ICONS

All the icons is a package to display proper symbols/icons on the modeline.

(use-package all-the-icons
      :if (display-graphic-p))

(use-package all-the-icons-dired
:hook (dired-mode . (lambda () (all-the-icons-dired-mode t))))

ORG-MODE

ORG-AUTO-TANGLE

Org-auto-tangle is a package that will automaticlly tangle your org file for you when you save your .org document. Set #+auto_tangle: t in your header file.

(use-package org-auto-tangle
:defer t
:hook (org-mode . org-auto-tangle-mode))

ORG DEFINITIONS

Setting some default .org definitions.

  (add-hook 'org-mode-hook 'org-indent-mode)
(setq org-directory "~/.emacs.d/Org/"
      org-agenda-files '("~/.emacs.d/Org/agenda.org")
      org-default-notes-file (expand-file-name "notes.org" org-directory)
      org-ellipsis " ▼ "
      org-log-done 'time
      org-journal-dir "~/.emacs.d/Org/journal/"
      org-journal-date-format "%d %B, %Y (%A) "
      org-journal-file-format "%Y-%m-%d.org"
      org-hide-emphasis-markers t)
(setq org-src-preserve-indentation nil
      org-src-tab-acts-natively t
      org-edit-src-content-indentation 0
      org-src-fontify-natively t
      org-confirm-babel-evaluate nil)

TOC-ORG

This package will automaticlly generate a table of contents in org mode. use :TOC: at the end of your table of contents header.

  (use-package toc-org
     :commands toc-org-enable
     :init (add-hook 'org-mode-hook 'toc-org-enable))

ORG-MODERN-MODE

(use-package org-modern)
(with-eval-after-load 'org (global-org-modern-mode))

ORG-TEMPO

This package allows you to type '<s followed by TAB to expand a tag

  (use-package org-tempo
   :straight nil)

VERTICO

Vertico provides a performant and minimalistic vertical completion UI based on the default completion system

;;install vertico
(use-package vertico
  :init
  (vertico-mode)

  ;; Different scroll margin
  ;; (setq vertico-scroll-margin 0)

  ;; Show more candidates
  (setq vertico-count 20)

  ;; Grow and shrink the Vertico minibuffer
  (setq vertico-resize t)

  ;; Optionally enable cycling for `vertico-next' and `vertico-previous'.
  (setq vertico-cycle t))

Vertico-Directory

(use-package vertico-directory
:after vertico
:straight nil
:load-path "straight/repos/vertico/extensions/"
:bind (:map vertico-map
            ("RET" . vertico-directory-enter)
            ("DEL" . vertico-directory-delete-char)
            ("M-DEL" . vertico-directory-delete-word))

:hook (rfn-eshadow-update-overlay . vertico-directory-tidy))

COMPANY

(use-package company 
  :ensure  
  :custom
  (company-idle-delay 0.1)
  (global-company-mode t)
  :bind
  (:map company-active-map
	("C-n" . company-select-next)
	("C-p" . company-select-previous)
	("M-<" . company-select-first)
	("M->" . company-select-last))

  (:map company-mode-map
        ("<tab>" . tab-indent-or-complete)
         ("TAB" . tab-indent-or-complete)))

(defun company-yasnippet-or-completion ()
  (interactive)
  (or (do-yas-expand)
      (company-complete-common)))

(defun check-expansion ()
  (save-excursion
    (if (looking-at "\\_>") t
      (backward-char 1)
      (if (looking-at "\\.") t
        (backward-char 1)
        (if (looking-at "::") t nil)))))

(defun do-yas-expand ()
  (let ((yas/fallback-behavior 'return-nil))
    (yas/expand)))


(defun tab-indent-or-complete ()
(interactive)
(if (minibufferp)
    (minibuffer-complete)
  (if (or (not yas/minor-mode)
          (null (do-yas-expand)))
(if (check-expansion)
      (company-complete-common)
    (indent-for-tab-command)))))


(use-package company-box
  :after company
  :hook (company-mode . company-box-mode))

MARGINALIA

This package provides marginalia-mode which adds marginalia to the minibuffer completions.

;; Enable rich annotations using the Marginalia package
(use-package marginalia
  ;; Bind `marginalia-cycle' locally in the minibuffer.  To make the binding
  ;; available in the *Completions* buffer, add it to the
  ;; `completion-list-mode-map'.
  :bind (:map minibuffer-local-map
         ("M-A" . marginalia-cycle))

  ;; The :init section is always executed.
  :init

  ;; Marginalia must be actived in the :init section of use-package such that
  ;; the mode gets enabled right away. Note that this forces loading the
  ;; package.
  (marginalia-mode))

EMBARK

(use-package embark
  :straight t)

(use-package embark-consult
 :straight t
 :hook
 (embark-collection-mode . consult-preview-at-point-mode))

EVIL

Evil Mode is 'vim keybindings for EMACS. We are setting "evil-mode" by default.

(use-package evil
  :straight t
  :init
  (setq evil-want-keybinding nil)
  (setq evil-vsplit-window-right t)
  (setq evil-split-window-below t)
  :config
  (evil-mode 1))

(use-package evil-collection
  :after evil
  :straight t
  :config
  (evil-collection-init))

DASHBOARD

This is a startup dashboard for emacs, it shows recent files, projects and your org-agendas.

;;install dashboard
(use-package dashboard
   :straight t
   :init
 (setq dashboard-set-heading-icons t)
 (setq dashboard-set-file-icons t)
 (setq dashboard-banner-logo-title "emacs rocks")
 (setq dashboard-startup-banner 'logo)
 (setq dashboard-center-content nil)
 (setq dashboard-items '((recents . 5)
                         (projects . 3)
                         (agenda . 3))))
                        
 :config
(dashboard-setup-startup-hook)

Consult

(use-package consult)



(use-package consult-dir
 :straight 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)))

Perspective

This package adds workspaces for your buffers in Emacs. This package is very similiar in how a tiling window manager works with its workspaces.

(use-package perspective
  :bind
  ("C-x C-b" . persp-list-buffers)         ; or use a nicer switcher, see below
  :custom
  (persp-mode-prefix-key (kbd "C-c M-p"))  ; pick your own prefix key here
  :init
  (persp-mode))

DEVELOPMENT

LSP MODE

(use-package lsp-mode
 :ensure
 :commands lsp
 :custom
(lsp-rust-analyzer-cargo-watch-command "clippy")
(lsp-eldoc-render-all t)
(lsp-idle-delay 0.6)
(lsp-inlay-hint-enable nil)
(lsp-rust-analyzer-display-lifetime-elision-hints-enable "skip_trivial")
(lsp-rust-analyzer-display-chaining-hints nil)
(lsp-rust-analyzer-displal-lifetime-elision-hints-use-parameter-names nil) 
(lsp-rust-analyzer-display-closure-return-type-hints nil)
(lsp-rust-analyzer-display-parameter-hints nil)
(lsp-rust-analyzer-display-reborrow-hints nil)
(setq lsp-auto-guess-root nil) 
:config
(add-hook 'lsp-mode-hook 'lsp-ui-mode
          'lsp-mode-hook 'lsp-enable-which-key-integration))

(use-package lsp-ui
:ensure
:commands lsp-ui-mode
:custom
(lsp-ui-peek-always-show nil)
(lsp-ui-sideline-show-hover nil)
(lsp-ui-doc-enable nil))

Jedi for python

(use-package lsp-jedi
:ensure t)

Rustic (Rust Stuff)

(use-package rustic
:ensure 
:bind (:map rustic-mode-map
       ("M-j" . lsp-ui-imenu)
       ("M-?" . lsp-find-references))
:config
(setq lsp-format-buffer t))

CCLS

lsp for C++

(use-package ccls
  :hook ((c-mode c++-mode objc-mode cuda-mode) .
        (lambda () (require 'ccls) (lsp))))
(setq ccls-executable "/usr/bin/ccls")
;;(setq ccls-sem-highlight-method 'font-lock)
(setq ccls-use-default-rainbow-sem-highlight 'font-lock)
(ccls-code-lens-mode 1)

HASKELL-MODE

(use-package haskell-mode)

RUST-MODE

(use-package toml-mode)

(use-package rust-mode
:hook (rust-mode . lsp-mode))

FLYCHECK

(use-package flycheck
  :straight t)

Tree-Sitter-Grammers

(setq treesit-language-source-alist
'((rust "https://github.com/tree-sitter/tree-sitter-rust")))

REMAP MODES FOR TREE-SITTER

(setq major-mode-remap-alist
   '((rust-mode . rust-ts-mode)))

PROJECTILE

Projectile is a project interaction library for Emacs.

(use-package projectile)

YASNIPPET

(use-package yasnippet
:config
(yas-reload-all)
(add-hook 'prog-mode-hook 'yas-minor-mode)
(add-hook 'text-mode-hook 'yas-minor-mode))

LSP-TREEMACS

(use-package lsp-treemacs :commands lsp-treemacs-errors-list)

GARBAGE COLLECTION

GC is the process of freeing up memory from unused/used up variables. We set the threshold on the GC so emacs will be a little faster.

;; Using garbage magic hack.
 (use-package gcmh
   :config
   (gcmh-mode 1))
;; Setting garbage collection threshold
(setq gc-cons-threshold 402653184
      gc-cons-percentage 0.6)

;; Profile emacs startup
(add-hook 'emacs-startup-hook
          (lambda ()
            (message "*** Emacs loaded in %s with %d garbage collections."
                     (format "%.2f seconds"
                             (float-time
                              (time-subtract after-init-time before-init-time)))
                     gcs-done)))

;; Silence compiler warnings as they can be pretty disruptive (setq comp-async-report-warnings-errors nil)

NATIVE COMPILE

Native Compile support and silence some annoying warnings when a package gets installed.

;; Silence compiler warnings as they can be pretty disruptive
(if (boundp 'comp-deferred-compilation)
    (setq comp-deferred-compilation nil)
    (setq native-comp-deferred-compilation nil))
;; In noninteractive sessions, prioritize non-byte-compiled source files to
;; prevent the use of stale byte-code. Otherwise, it saves us a little IO time
;; to skip the mtime checks on every *.elc file.
(setq load-prefer-newer noninteractive)

USER INTERFACE ENHANCEMENTS

;; load dashboard instead of scratchpad at startup *INSTALL DASHBOARD*
(setq initial-buffer-choice (lambda () (get-buffer "*dashboard*")))
;;(load-theme 'doom-tokyo-night :no-confirm) ; Set theme
(load-theme 'doom-xcode :no-confirm) ; Set theme
(menu-bar-mode -1) ; Turn menubar off
(scroll-bar-mode -1) ; Turn scrollbar off
(tool-bar-mode -1) ; Turn tool-bar off
(global-display-line-numbers-mode 1) ; Display line numbers globally
(beacon-mode 1) ; Turn beacon on
(toggle-frame-maximized)
(setq inhibit-startup-screen t) ; Disable startup default startup screen
(setq auto-save-interval 1000)
(setq make-backup-files nil) ; Disable automatic backup files

Enabling Return for min-buffer questions

(defun y-or-n-p-with-return (orig-func &rest args)
  (let ((query-replace-map (copy-keymap query-replace-map)))
    (define-key query-replace-map (kbd "RET") 'act)
    (apply orig-func args)))        

(advice-add 'y-or-n-p :around #'y-or-n-p-with-return)

DISABLE ELECTRIC INDENT

fix some of the weird indents in org mode

(electric-indent-mode -1)
(setq org-edit-src-content-indentation 0)

Fonts and Themes

(set-face-attribute 'default nil 
		    :font "Terminess Nerd Font"
		    :height 180
		    :weight 'bold)
(set-face-attribute 'variable-pitch nil 
		    :font "Terminess Nerd Font"
		    :height 180
		    :weight 'semibold)
(set-face-attribute 'fixed-pitch nil
		    :font "Terminess Nerd Font"
		    :height 180
		    :weight 'bold)
;; Makes commented text and keywords italics.
;; This is working in emacsclient but not emacs.
;; Your font must have an italic face available.
(set-face-attribute 'font-lock-comment-face nil
		    :slant 'italic)
(set-face-attribute 'font-lock-keyword-face nil
                    :slant 'italic)

;;(add-to-list 'default-frame-alist '(font . "JetBrainsMono Nerd Font-14"))

(setq pixel-scroll-precision-mode 1)
;; Uncomment the following line if line spacing needs adjusting.
;;(setq-default line-spacing 0.12)

(add-to-list 'default-frame-alist '(alpha-background . 90))
;; Needed if using emacsclient. Otherwise, your fonts will be smaller than expected.
;;(add-to-list 'default-frame-alist '(font . "SauceCodePro Nerd Font-16" :weight 'semibold))
;; changes certain keywords to symbols, such as lamda!
(setq global-prettify-symbols-mode t)
;;(add-hook 'find-file-hook (lambda () (set-face-attribute 'default nil :height 105)))
t

Zooming IN/OUT

Zoom in with Cntrl+ and out with Cntrl-, also use mousewheel up to zoomin and mousewheel down to zoom out

(global-set-key (kbd "C-+") 'text-scale-increase)
(global-set-key (kbd "C--") 'text-scale-decrease)
;; (global-set-key (kbd "<C-wheel-up>") 'text-scale-increase)
;; (global-set-key (kbd "<C-wheel-down>") 'text-scale-decrease)

GENERAL KEYBINDS

General provides a more convenient way method for binding keys in emacs that works for both 'evil mode' and 'non-evil-mode'.

;;install general

;; (global-set-key (kbd "C-t") 'vterm-toggle)

(use-package general
  :config
  (general-evil-setup)
  
  ;; set up 'SPC' as the global leader key
  (general-create-definer ltg/leader-keys
    :states '(normal insert visual emacs)
    :keymaps 'override
    :prefix "SPC" ;; set leader
    :global-prefix "M-SPC")


    (ltg/leader-keys
    "SPC" '(execute-extended-command :wk "M-x")
    "." '(find-file :wk "Find file")
    "f f" '(find-file :wk "Find file")
    "t t" 'vterm-toggle
    "t l" 'eshell
    "=" '(perspective-map :wk "Perspective") ;; Lists all the perspective keybindings
    "TAB TAB" '(comment-line :wk "Comment lines")
    "u" '(universal-argument :wk "Universal argument"))

    (ltg/leader-keys
    "b"   '(:ignore t :wk "Buffers")
    "b i" '(ibuffer :wk "Ibuffer")
    "b p" '(previous-buffer :wk "Previous buffer")
    "b n" '(next-buffer :wk "Next buffer"))

    (ltg/leader-keys
    "d"   '(:ignore t :wk "Dired")
    "d d" '(dired :wk "Open Dired")
    "d j" '(dired-jump :wk "Dired jump to current"))

    (ltg/leader-keys
    "f"   '(:ignore t :wk "Files")
    "f c" '((lambda () (interactive) (find-file "~/.emacs.d/README.org")) :wk "Open emacs config")
    "f d" '(find-grep-dired :wk "Search for strings in files in DIR"))

    (ltg/leader-keys
    "e"   '(:ignore t :wk "Evaluate")
    "e r" '(eval-region :wk "Eval Region")
    "e b" '(eval-buffer :wk "Eval Buffer"))

)