emacs/.emacs

307 lines
8.6 KiB
Plaintext
Raw Normal View History

2025-01-28 17:49:01 +01:00
;; ===========================
;; Package Management Setup
;; ===========================
(require 'package)
;; Add MELPA, Org, and GNU package archives
2025-01-28 17:49:01 +01:00
(setq package-archives '(("melpa" . "https://melpa.org/packages/")
("org" . "https://orgmode.org/elpa/")
("gnu" . "https://elpa.gnu.org/packages/")))
(package-initialize)
;; Refresh package list if it's not already available
(unless package-archive-contents
(package-refresh-contents))
;; Install use-package if it's not already installed
(unless (package-installed-p 'use-package)
(package-install 'use-package))
(require 'use-package)
(setq use-package-always-ensure t) ;; Always ensure packages are installed
;; ===========================
;; Theme Configuration
;; ===========================
;; Define your preferred light and dark themes
(setq dark-theme 'zenburn)
(setq light-theme 'solarized-light)
;; Install Themes
(use-package solarized-theme
:ensure t)
(use-package zenburn-theme
:ensure t)
2025-01-28 21:11:36 +01:00
(defun my/get-system-appearance ()
(cond
;; ---------------------------
;; macOS
;; ---------------------------
((eq system-type 'darwin)
(if (string= (shell-command-to-string "defaults read -g AppleInterfaceStyle 2>/dev/null") "Dark\n")
'dark
'light))
;; ---------------------------
;; Windows
;; ---------------------------
((eq system-type 'windows-nt)
;; NOTE: For Windows 10/11, “AppsUseLightTheme” is under:
;; HKCU\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize
;; Value of 1 => Light, 0 => Dark
(let ((output (shell-command-to-string
"reg query \"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize\" /v AppsUseLightTheme 2>nul")))
(cond
((string-match "0x1" output) 'light)
((string-match "0x0" output) 'dark)
(t nil))))
;; ---------------------------
;; GNOME-based Linux
;; ---------------------------
((eq system-type 'gnu/linux)
;; If you're on GNOME 42+, `color-scheme` often shows 'prefer-dark' or 'prefer-light'.
;; If the user is using an older system or a different DE, this may fail or return an empty string.
(let ((gsettings-output (string-trim
(shell-command-to-string
"gsettings get org.gnome.desktop.interface color-scheme 2>/dev/null"))))
(cond
((string-match "dark" gsettings-output) 'dark)
((string-match "light" gsettings-output) 'light)
(t nil))))
;; ---------------------------
;; Otherwise, undetermined
;; ---------------------------
(t nil)))
2025-01-28 17:49:01 +01:00
(defun my/set-theme-based-on-appearance ()
2025-01-28 21:11:36 +01:00
"Set Emacs theme based on system appearance if possible, otherwise fallback."
(let ((appearance (my/get-system-appearance)))
2025-01-28 17:49:01 +01:00
;; Disable all currently enabled themes to prevent conflicts
(mapc #'disable-theme custom-enabled-themes)
(pcase appearance
('dark
(load-theme dark-theme t))
('light
(load-theme light-theme t))
(_
2025-01-28 21:11:36 +01:00
;; If we cannot detect the theme, default to light
(load-theme light-theme t)))))
2025-01-28 17:49:01 +01:00
;; Apply theme at startup
(my/set-theme-based-on-appearance)
;; ===========================
;; UI Customizations
;; ===========================
;; Replace yes-no prompts to y-n
2025-01-28 23:39:08 +01:00
(defalias 'yes-or-no-p 'y-or-n-p)
2025-01-28 17:49:01 +01:00
;; Disable unnecessary UI elements
(tool-bar-mode -1) ;; Hide the toolbar
(menu-bar-mode -1) ;; Hide the menu bar
(scroll-bar-mode -1) ;; Hide the scroll bar
;; Enable useful UI features
(column-number-mode 1) ;; Show column numbers
(global-display-line-numbers-mode 1) ;; Enable global line numbers
;; Enable visual line mode globally
(global-visual-line-mode 1)
;; Disable line numbers for some modes
(dolist (mode '(dired-mode-hook
doc-view-mode-hook
eshell-mode-hook
comint-mode-hook
inferior-python-mode-hook
org-mode-hook
shell-mode-hook
term-mode-hook))
(add-hook mode (lambda () (display-line-numbers-mode 0))))
;; Complete parentheses, quotes, etc
(electric-pair-mode 1)
2025-01-28 17:49:01 +01:00
;; Set Default Font to Iosevka 18pt
2025-01-29 16:08:36 +01:00
;;(set-face-attribute 'default nil :family "Iosevka" :height 150)
;; Set font
(set-face-attribute 'default nil
:family "JetBrains Mono Nerd Font"
:height 140
:weight 'normal
:width 'normal)
;; Line spacing
(setq-default line-spacing 0)
2025-01-28 17:49:01 +01:00
;; Backup files -> ~/.emacs.d/backups/
(setq backup-directory-alist `(("." . "~/.emacs.d/backups"))
backup-by-copying t ;; Don't delink hardlinks
version-control t ;; Use version numbers on backups
delete-old-versions t ;; Automatically delete excess backups
kept-new-versions 6
kept-old-versions 2)
;; ===========================
;; macOS Specific Settings
;; ===========================
(when (eq system-type 'darwin)
;; Use Command key as Meta
(setq mac-command-modifier 'meta
mac-option-modifier 'none)
;; Better font rendering on macOS
(setq ns-use-srgb-colorspace t)
;; Add homebrew
(add-to-list 'exec-path "/opt/homebrew/bin")
)
;; ===========================
;; Evil Mode Configuration
;; ===========================
(use-package evil
:ensure t
:init
(setq evil-want-integration t)
(setq evil-want-keybinding nil)
:config
(evil-mode 1)) ;; Enable Evil Mode globally
(use-package evil-collection
:init
:after evil
:ensure t
:config
(evil-collection-init))
(keymap-global-set "C-u" 'evil-scroll-up)
;; ===========================
;; Additional Packages
;; ===========================
;; Install and enable Helm
(use-package helm
:config
(helm-mode 1))
;; Install and enable Company Mode globally
(use-package company
:init
(global-company-mode 1)
:config
;; Integrate Company with LSP
(setq company-minimum-prefix-length 1
company-idle-delay 0.0)) ;; Show completions immediately
;; Install and configure Projectile
(use-package projectile
:init
(projectile-mode +1)
:bind (:map projectile-mode-map
("s-p" . projectile-command-map)))
2025-01-28 17:49:01 +01:00
;; Install and bind Magit
(use-package magit
:bind ("C-x g" . magit-status))
;; Install and enable Which-Key
(use-package which-key
:config
(which-key-mode))
(use-package rainbow-delimiters
:ensure t
:hook (prog-mode . rainbow-delimiters-mode))
2025-01-28 17:49:01 +01:00
;; ===========================
;; LSP Configuration
;; ===========================
(use-package lsp-mode
:hook ((python-mode . lsp)
(kotlin-mode . lsp)
(c++-mode . lsp)
2025-01-28 21:11:36 +01:00
(c-mode . lsp)
2025-01-28 17:49:01 +01:00
(rust-mode . lsp))
:commands lsp
:config
(setq lsp-prefer-flymake nil) ;; Use lsp-ui and flycheck instead of flymake
2025-01-28 21:11:36 +01:00
(setq lsp-enable-snippet t) ;; Disable snippet support if not needed
2025-01-28 17:49:01 +01:00
(setq lsp-headerline-breadcrumb-enable nil)) ;; Disable breadcrumb for performance
(use-package lsp-ui
:commands lsp-ui-mode
:config
(setq lsp-ui-doc-enable t
lsp-ui-doc-delay 0.2
lsp-ui-sideline-enable t
lsp-ui-imenu-enable t))
(use-package lsp-treemacs
:commands lsp-treemacs-errors-list)
(use-package flycheck
:init (global-flycheck-mode))
;; ===========================
;; Language-Specific Configurations
;; ===========================
;; Python
(use-package lsp-pyright
:ensure t
:custom (lsp-pyright-langserver-command "pyright") ;; or basedpyright
:hook (python-mode . (lambda ()
(require 'lsp-pyright)
(lsp)))) ; or lsp-deferred
(use-package python
:ensure nil
:hook (python-mode . lsp)
:config
(setq python-shell-interpreter "python3")
)
(use-package poetry :ensure t)
;; Kotlin
(use-package kotlin-mode
:mode "\\.kt\\'"
:config
)
;; C++
(use-package cc-mode
:ensure nil
:config
)
;; Rust
(use-package rust-mode
:hook (rust-mode . lsp)
:config
(setq rust-format-on-save t)
)
(message "Emacs init loaded.")
(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.
'(helm-minibuffer-history-key "M-p")
'(package-selected-packages
'(rainbow-delimiters rainbow-delimiter catppuccin-theme lsp-pyright zenburn-theme which-key solarized-theme rust-mode projectile poetry magit lsp-ui lsp-treemacs kotlin-mode helm flycheck evil-collection dracula-theme company better-defaults)))
2025-01-28 17:49:01 +01:00
(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.
)