mandriota / .emacs.d

My GNU Emacs configuration

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

GNU Emacs Config

Prerequisites

  • Fish UNIX Shell (optional)
  • Git
  • GNU Aspell

Fonts

  • Fira Code
  • Georgia

Basic Environment Variables

(setenv "LDFLAGS" "-L/opt/homebrew/opt/openssl@3/lib")
(setenv "CFLAGS" "-I/opt/homebrew/opt/openssl@3/include")

(add-to-list 'exec-path "/opt/homebrew/bin")
(add-to-list 'exec-path "/usr/local/bin")
(add-to-list 'exec-path "~/.cargo/bin")
(add-to-list 'exec-path "~/go/bin")
(add-to-list 'exec-path "/opt/homebrew/Cellar/libgccjit/13.2.0/lib/gcc/current/")

(setenv "PATH"
		(concat
		 (mapconcat #'identity exec-path path-separator)
		 "/opt/homebrew/opt/llvm@14/bin" path-separator
		 "~/.emacs.d/bin" path-separator
		 "/opt/local/bin" path-separator
		 "/opt/local/sbin" path-separator
		 "/opt/homebrew/sbin" path-separator
		 "/System/Cryptexes/App/usr/bin" path-separator
		 "/usr/bin" path-separator
		 "/bin" path-separator
		 "/usr/sbin" path-separator
		 "/sbin" path-separator
		 "/usr/local/go/bin" path-separator
		 "/Library/TeX/Distributions/Programs/texbin"))

Basic Debug

Print start-up time:

(add-hook 'after-init-hook (lambda () (message (emacs-init-time))))

Basic Settings

(global-auto-revert-mode 1)
(save-place-mode 1)
(recentf-mode 1)
(setq recentf-max-menu-items 50
	  recentf-max-saved-items 50)

(setq inhibit-startup-screen t
	  use-dialog-box nil
	  ns-pop-up-frames nil)

(setq read-process-output-max (* 1024 1024))
(setq gc-cons-threshold 100000000
	  gc-cons-percentage 0.5)

(setq initial-scratch-message nil)

(setq dired-dwim-target t)

Appearance

(setq column-number-mode t)
(blink-cursor-mode -1)

(pixel-scroll-mode)
(setq pixel-dead-time 0)
(setq pixel-resolution-fine-flag t)
(setq mouse-wheel-scroll-amount '(1))
(setq mouse-wheel-progressive-speed nil)

Games

(setq gamegrid-glyph-height-mm 7)

(add-hook 'tetris-mode-hook 'visual-fill-column-mode)

Basic Shell

Set Shell Path

Try to set fish shell as a default shell. Fish is a smart and user-friendly shell:

(let ((sh-path "/opt/homebrew/bin/fish"))
  (if (file-exists-p sh-path)
	  (setq-default explicit-shell-file-name sh-path)
	(message "fish shell not found")))

Basic Keybindings

(setq ns-alternate-modifier 'meta
	  ns-right-alternate-modifier 'none)

(global-set-key (kbd "C-c r") #'recentf)

Basic Windowing

(when (fboundp 'windmove-default-keybindings)
  (windmove-default-keybindings 'control))

(setq mouse-autoselect-window t)

(global-set-key (kbd "C-x C-1") #'delete-other-windows)
(global-set-key (kbd "C-x C-2") #'split-window-below)
(global-set-key (kbd "C-x C-3") #'split-window-right)
(global-set-key (kbd "C-x C-0") #'delete-window)

(global-set-key [wheel-right] #'(lambda () (interactive) (scroll-left 4)))
(global-set-key [wheel-left] #'(lambda () (interactive) (scroll-right 4)))

Basic Text Editing

(setq visible-bell t)
(setq-default tab-width 2)

(global-set-key (kbd "C-x s") #'replace-string)

Basic Org Mode

(require 'org)

(setq org-startup-indented t
	  org-confirm-babel-evaluate nil
	  org-edit-src-content-indentation 0
	  org-image-actual-width nil
	  org-support-shift-select t)

(defun user/indent-org-block ()
  (interactive)
  (when (org-in-src-block-p)
    (org-edit-special)
    (indent-region (point-min) (point-max))
    (org-edit-src-exit)))

(define-key org-mode-map (kbd "C-i") #'user/indent-org-block)

(defun toggle-org-html-export-on-save ()
  (interactive)
  (if (memq 'org-html-export-to-html after-save-hook)
      (progn
        (remove-hook 'after-save-hook 'org-html-export-to-html t)
        (message "Disabled org html export on save for current buffer..."))
    (add-hook 'after-save-hook 'org-html-export-to-html nil t)
    (message "Enabled org html export on save for current buffer...")))

Basic C Mode

(setq c-basic-offset 2)
(setq c-indent-level 2)
(setq tab-width 2)

(defun user/outline-level ()
  "Custom outline level based on the comment labels."
  (looking-at outline-regexp)
  (let ((match (match-string 0)))
    (if (null match) 1
      (length match))))

(add-hook 'c-mode-common-hook
          (lambda ()
            (outline-minor-mode 1)
            (setq outline-regexp "//=:[a-zA-Z]+\\(:[a-zA-Z]+\\)?")
            (setq outline-level 'user/outline-level)
						(hide-body)))

(global-set-key (kbd "C-c i") 'outline-hide-body)
(global-set-key (kbd "C-c o") 'outline-hide-other)
(global-set-key (kbd "C-c p") 'outline-show-entry)
(global-set-key (kbd "C-c u") 'outline-show-all)

Basic Spell check

(setq ispell-program-name "aspell") 
(setq ispell-list-command "list")

Basic GPG

(setq epa-pinentry-mode 'loopback)

Basic Tree Sitter

(setq treesit-language-source-alist
	  '((bash "https://github.com/tree-sitter/tree-sitter-bash")
		(c "https://github.com/tree-sitter/tree-sitter-c")
		(cmake "https://github.com/uyha/tree-sitter-cmake")
		(common-lisp "https://github.com/theHamsta/tree-sitter-commonlisp")
		(cpp "https://github.com/tree-sitter/tree-sitter-cpp")
		(css "https://github.com/tree-sitter/tree-sitter-css")
		(csharp "https://github.com/tree-sitter/tree-sitter-c-sharp")
		(elisp "https://github.com/Wilfred/tree-sitter-elisp")
		(go "https://github.com/tree-sitter/tree-sitter-go")
		(go-mod "https://github.com/camdencheek/tree-sitter-go-mod")
		(html "https://github.com/tree-sitter/tree-sitter-html")
		(js . ("https://github.com/tree-sitter/tree-sitter-javascript" "master" "src"))
		(json "https://github.com/tree-sitter/tree-sitter-json")
		(lua "https://github.com/Azganoth/tree-sitter-lua")
		(make "https://github.com/alemuller/tree-sitter-make")
		(markdown "https://github.com/ikatyang/tree-sitter-markdown")
		(python "https://github.com/tree-sitter/tree-sitter-python")
		(r "https://github.com/r-lib/tree-sitter-r")
		(rust "https://github.com/tree-sitter/tree-sitter-rust")
		(toml "https://github.com/tree-sitter/tree-sitter-toml")
		(tsx . ("https://github.com/tree-sitter/tree-sitter-typescript" "master" "tsx/src"))
		(typescript . ("https://github.com/tree-sitter/tree-sitter-typescript" "master" "typescript/src"))
		(typst "https://github.com/uben0/tree-sitter-typst")
		(yaml "https://github.com/ikatyang/tree-sitter-yaml")))

(add-to-list 'auto-mode-alist '("\\.ya?ml\\'" . yaml-ts-mode))

Package Manager

Bootstrap straight. Straight is an overengineered package manager:

(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))

Add use-package support:

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

Theme

(use-package doom-themes
  :custom
  (doom-themes-enable-bold t)
  (doom-themes-enable-italic t)
  :config
  (load-theme 'doom-nord t)

  (doom-themes-visual-bell-config)
  (doom-themes-org-config))

All The Icons

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

All The Icons Dired

(use-package all-the-icons-dired
  :after all-the-icons
  :straight (:type git :host github :repo "jtbm37/all-the-icons-dired")
  :config
  (add-hook 'dired-mode-hook 'all-the-icons-dired-mode))

All The Icons Ivy Rich

(use-package all-the-icons-ivy-rich
  :after (all-the-icons ivy-rich)
  :init (all-the-icons-ivy-rich-mode 1))

Source Browsing

Projectile

(use-package projectile
  :config
  (projectile-mode +1)
  (define-key projectile-mode-map (kbd "M-p") 'projectile-command-map))

Dashboard

(use-package dashboard
  :after (projectile all-the-icons)
  :custom
  (dashboard-items '((recents  . 7)
                     (projects . 4)
                     (agenda . 2)
                     (registers . 2)
					 (bookmarks . 4)))
  (dashboard-icon-type 'all-the-icons)
  (dashboard-set-heading-icons t)
  (dashboard-set-file-icons t)
  (dashboard-startup-banner 'ascii)
  (dashboard-banner-logo-title nil)
  (dashboard-set-init-info nil)
  :config
  (dashboard-setup-startup-hook))

VTerm

(use-package vterm
	:custom
	(shell-file-name explicit-shell-file-name))

Text Editing & Navigation

Undo Tree

(use-package queue)
(use-package undo-tree
	:after queue
	:config
	(global-undo-tree-mode))

Avy Mode

(use-package avy
	:config
	(global-set-key (kbd "C-w") 'avy-goto-word-0))

God Mode

(use-package god-mode
  :config
  (global-set-key (kbd "<escape>") #'god-mode)

  (define-key god-local-mode-map (kbd "z") #'repeat)
  
  (define-key god-local-mode-map (kbd "[") #'backward-paragraph)
  (define-key god-local-mode-map (kbd "]") #'forward-paragraph))

(defun user/god-mode-update-cursor ()
  (if (or god-local-mode buffer-read-only)
	  (set-cursor-color "cyan")
	(set-cursor-color "white")))

(add-hook 'post-command-hook #'user/god-mode-update-cursor)

Multiple cursors

(use-package multiple-cursors
  :config
  (global-set-key (kbd "C-s-c") 'mc/edit-lines)
  (global-set-key (kbd "C-(") 'mc/mark-previous-like-this)
  (global-set-key (kbd "C-)") 'mc/mark-next-like-this)
  (global-set-key (kbd "C-c C-(") 'mc/mark-all-like-this)
  (global-set-key (kbd "s-<mouse-1>") 'mc/add-cursor-on-click))

Kaomoji

(use-package kaomel
  :straight  (:type git :host github :repo "gicrisf/kaomel")
	:custom
	(kaomel-path "~/.emacs.d/kaomoji.json"))

(global-set-key (kbd "C-s-k") #'kaomel-insert)

Snippets

(use-package yasnippet
  :custom
  (yas-snippet-dirs '(;; "~/.emacs.d/user_snippets"
					  "~/.emacs.d/AndreaCrotti_snippets"))
  :config
  (yas-global-mode 1))

Which Key Mode

(use-package which-key
  :config
  (which-key-mode))

Ivy

(use-package ivy
  :config
  (ivy-mode)

  (global-set-key (kbd "C-r") 'swiper-thing-at-point)
  (global-set-key (kbd "C-s") 'swiper))

Counsel

(use-package counsel
  :after ivy
  :config
  (counsel-mode))

Ivy Rich

(use-package ivy-rich
  :after ivy
  :config
  (ivy-rich-mode 1)
  (setcdr (assq t ivy-format-functions-alist) #'ivy-format-function-line))

Magit

(use-package magit)

Languages Support

Python

(setenv "PYTHONIOENCODING" "utf8")

(setq python-shell-interpreter-args "-m asyncio")

(use-package lsp-pyright
  :hook (python-mode . (lambda () (require 'lsp-pyright)))
  :init (when (executable-find "python3")
          (setq lsp-pyright-python-executable-cmd "python3")))

(use-package py-autopep8
	:custom
	(py-autopep8-options '("--max-line-length=80")))

(use-package pyvenv
  :config
  (pyvenv-tracking-mode)
  (add-hook 'pyvenv-post-activate-hooks 'lsp))

(use-package ein)

TypeScript

(use-package typescript-mode)
(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))
	:config
	(add-hook 'js2-mode-hook #'setup-tide-mode)
	;; configure javascript-tide checker to run after your default javascript checker
	(flycheck-add-next-checker 'javascript-eslint 'javascript-tide 'append))

C

(defun user/clang-format-save-hook-for-this-buffer ()
  "Create a buffer local save hook."
  (add-hook 'before-save-hook
            (lambda ()
              (when (locate-dominating-file "." ".clang-format")
                (clang-format-buffer))
              ;; Continue to save.
              nil)
            nil
            ;; Buffer local hook.
            t))

(use-package clang-format
	:hook
	((c-mode . (lambda () (user/clang-format-save-hook-for-this-buffer)))))

Rust

(use-package rustic
  :mode ("\\.rs\\'" . rustic-mode)
  :custom
  (rustic-format-on-save t))

Zig

(use-package zig-mode)

Go

(use-package go-mode)

Babel:

(use-package ob-go
	:after go-mode)

Fish

(use-package fish-mode
  :mode ("\\.fish$")
  :config
  (setq fish-enable-auto-indent t))

Babel:

(use-package ob-fish
  :straight  (:type git :host github :repo "takeokunn/ob-fish"))

CSV Mode

(use-package csv-mode)

Typst Mode

Readable LaTeX:

Load Org Babel

(org-babel-do-load-languages
 'org-babel-load-languages
 '((python . t)
   (C . t)
	 (shell . t)))

Debug

(use-package dap-mode)

Error Checking

(use-package flycheck)

LSP Mode

(use-package lsp-mode
  :ensure
  :commands lsp
  :custom
	(lsp-enable-file-watchers nil)
  (lsp-rust-analyzer-cargo-watch-command "clippy")
  (lsp-eldoc-render-all nil)
  (lsp-inlay-hint-enable t)
	(lsp-headerline-breadcrumb-enable nil)
  (lsp-rust-analyzer-display-lifetime-elision-hints-enable "skip_trivial")
  (lsp-rust-analyzer-display-chaining-hints t)
  (lsp-rust-analyzer-display-lifetime-elision-hints-use-parameter-names nil)
  (lsp-rust-analyzer-display-closure-return-type-hints t)
  (lsp-rust-analyzer-display-parameter-hints nil)
  (lsp-rust-analyzer-display-reborrow-hints nil)
	(lsp-go-analyses '((shadow . t)
                     (simplifycompositelit . :json-false)))
	:hook ((lsp-mode . lsp-enable-which-key-integration)
				 (typescript-mode . lsp)
				 (javascript-mode . lsp)
				 (python-mode . lsp)
				 (python-mode . py-autopep8-mode)
				 (elisp-mode . lsp)
				 (go-mode . lsp)
				 (rustic . lsp)
				 (c-mode . lsp)
				 (zig . lsp))
  :config
  (add-hook 'lsp-mode-hook 'lsp-ui-mode)
	(require 'dap-cpptools))

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

(use-package lsp-ivy :commands lsp-ivy-workspace-symbol)

Company Mode

(use-package company
  :custom
  (company-idle-delay 0)
  (company-minimum-prefix-length 1)
  (company-selection-wrap-around t)
  :config
  (add-hook 'after-init-hook 'global-company-mode)
  (global-set-key (kbd "C-c y") 'company-yasnippet)

  (company-tng-configure-default))

Visual Fill Column Mode

(use-package visual-fill-column
  :commands visual-fill-column-mode
  :custom
  (visual-fill-column-center-text t)
  (visual-fill-column-width 90))

EPUB reader

(use-package nov
  :custom
  (nov-text-width t)
  :config
	(defun user/nov-font-setup ()
	  (face-remap-add-relative 'variable-pitch :family "Georgia"
                               :height 1.2))
	(add-hook 'nov-mode-hook 'user/nov-font-setup)
	
  (add-hook 'nov-mode-hook 'visual-line-mode)
  (add-hook 'nov-mode-hook 'visual-fill-column-mode)

  (add-to-list 'auto-mode-alist '("\\.epub\\'" . nov-mode)))

Start Server

(unless (server-running-p)
	(server-start))

About

My GNU Emacs configuration

License:MIT License


Languages

Language:Emacs Lisp 100.0%