blob: aa380907a315bf5f99547536b7092b69f7505493 (
plain) (
tree)
|
|
;;; init.el --- This is where all emacs start. -*- lexical-binding: t -*-
;;; Commentary:
;;; Code:
(setq backup-inhibited t) ;; no backups
(setq create-lockfiles nil) ;; don't use a lock file
(use-package recentf
:hook (after-init . recentf-mode)
:config
(setq recentf-max-saved-items 1000)
(setq recentf-max-menu-items 25)
(setq recentf-save-file-modes nil)
(setq recentf-keep nil)
(setq recentf-auto-cleanup nil)
(setq recentf-initialize-file-name-history nil)
(setq recentf-filename-handlers nil)
(setq recentf-show-file-shortcuts-flag nil))
;;;; Auto revert mode
(use-package autorevert
:hook (after-init . global-auto-revert-mode)
:config
(setq auto-revert-verbose t))
;;;; Display current time
(use-package time
:commands (world-clock)
:hook (after-init . display-time-mode)
:config
(setq display-time-format " %a %e %b, %H:%M ")
(setq display-time-24hr-format t)
(setq display-time-interval 60)
(setq display-time-default-load-average nil)
(setq display-time-world-list t)
;; M-x shell RET timedatectl list-timezones
(setq zoneinfo-style-world-list '(("America/Los_Angeles" "Berkeley")
("America/Chicago" "Chicago")
("UTC" "UTC")
("Europe/Paris" "Paris")))
;; M-x world-clock
(setq world-clock-list t)
(setq world-clock-time-format "%z %R %a %d %b (%Z)")
(setq world-clock-buffer-name "*world-clock*") ; Placement handled by `display-buffer-alist'
(setq world-clock-timer-enable t)
(setq world-clock-timer-second 60))
;;;; Emacs server (allow emacsclient to connect to running session)
(use-package server
:defer 1
:config
(setq server-client-instructions nil)
(unless (server-running-p)
(server-start)))
;;;; improved buffers management
(use-package ibuffer
:ensure nil
:bind ("C-x C-b" . ibuffer)
:init
(setq ibuffer-expert t) ;; set expert mode
(setq ibuffer-jump-offer-only-visible-buffers t) ;; only show visible buffers
(setq ibuffer-use-other-window t) ;; open ibuffer in other window
(setq ibuffer-filter-group-name-face '(:inherit (font-lock-string-face bold))))
;;;; magit, the best git client
(use-package magit
:bind ("C-x g" . magit-status)
:custom
(magit-diff-refine-hunk t)
(magit-repository-directories '(("~/workspace" . 1)))
(magit-repolist-column-flag-alist '((magit-untracked-files . "N")
(magit-unstaged-files . "U")
(magit-staged-files . "S")))
(magit-repolist-columns '(("Name" 25 magit-repolist-column-ident nil)
("" 3 magit-repolist-column-flag)
("Version" 25 magit-repolist-column-version
((:sort magit-repolist-version<)))
("B<U" 3 magit-repolist-column-unpulled-from-upstream
((:right-align t)
(:sort <)))
("B>U" 3 magit-repolist-column-unpushed-to-upstream
((:right-align t)
(:sort <)))
("Path" 99 magit-repolist-column-path nil)))
(magit-clone-default-directory "~/workspace/")
:config
;; show ANSI colors in the process buffer, so it's easier to read what's going on
;; for some reasons if it's in the `:custom' section it does not get set
(setq magit-process-finish-apply-ansi-colors t))
;;;; create links from a git commit to a forge
(use-package git-link
:defines git-link-remote-alist
:bind ("C-c Y" . git-link)
:commands (git-link git-link-commit git-link-homepage)
:custom
(git-link-open-in-browser t)
:config
;; sets up roblox git enterprise as a git-link handler
(add-to-list 'git-link-remote-alist '("github\\.rblx\\.com" git-link-github))
(add-to-list 'git-link-commit-remote-alist '("github\\.rblx\\.com" git-link-commit-github)))
(require 'imenu)
(require 'midnight)
(setq auto-save-default nil) ;; no auto save
(setq confirm-kill-emacs #'yes-or-no-p) ;; ask before killing emacs
(setq cursor-in-non-selected-windows nil) ;; keep cursors and highlights in current window only
(setq delete-by-moving-to-trash t) ;; delete files by moving them to the trash
(setq highlight-nonselected-windows nil) ;; don't highlight inactive windows
(setq history-delete-duplicates t) ;; delete duplicate from history
(setq imenu-auto-rescan t) ;; rescan automatically
(setq initial-major-mode 'fundamental-mode) ;; default mode for the scratch buffer
(setq initial-scratch-message "") ;; makes the scratch buffer empty
(setq midnight-period (* 3600 6)) ;; clear buffer every 6 hours
(setq mode-line-default-help-echo nil) ;; don't say anything on mode-line mouseover
(setq require-final-newline t) ;; ensure a new line is present at the bottom of files
(setq ring-bell-function 'ignore) ;; really no bell
(setq sentence-end-double-space nil) ;; it matters for filling
(setq use-short-answers t) ;; use y-or-n
(setq visible-bell nil) ;; no bell
(setq bidi-display-reordering nil) ;; disable bidirectional text support for slight performance bonus
(setq column-number-mode t) ;; show column number in the mode line
;; global minor modes
(fringe-mode '(8 . 0))
(save-place-mode t)
(which-key-mode t)
(require 'savehist)
(savehist-mode t)
(setq history-length 100
history-delete-duplicates t
savehist-save-minibuffer-history t)
;; some key bindings
(global-set-key (kbd "M-j") 'join-line)
(global-set-key (kbd "C-c y") 'git-link)
(global-set-key (kbd "C-c C-r") 'eval-region)
(global-set-key (kbd "C-c C-d") 'eval-defun)
(global-set-key (kbd "C-c C-b") 'eval-buffer)
(global-set-key (kbd "C-c ! D") 'flymake-show-project-diagnostics)
(global-set-key (kbd "C-c ! d") 'flymake-show-buffer-diagnostics)
(global-set-key (kbd "C-c ! n") 'flymake-goto-next-error)
(global-set-key (kbd "C-c ! p") 'flymake-goto-prev-error)
(global-set-key (kbd "C-c ! s") 'flymake-start)
;; load the PATH properly on macOS
(require 'exec-path-from-shell)
(let ((envs '("PATH" "GOPATH" "GOBIN")))
(exec-path-from-shell-copy-envs envs))
;; ensure we highlights whitespaces
(require 'whitespace)
(dolist (mode-hook '(prog-mode-hook text-mode-hook conf-mode-hook))
(add-hook mode-hook 'whitespace-mode))
(setq whitespace-style '(face trailing tabs))
(setq-default show-trailing-whitespace t)
;;; dired
(require 'dired)
(setq dired-use-ls-dired t
dired-clean-up-buffers-too nil
dired-dwim-target t
dired-hide-details-hide-information-lines nil
dired-hide-details-hide-symlink-targets nil
dired-recursive-copies 'always
dired-recursive-deletes 'always
dired-no-confirm '(byte-compile chgrp chmod chown copy hardlink symlink touch))
(defun my/rename-this-buffer-and-file ()
"Renames current buffer and file it is visiting."
(interactive)
(let ((name (buffer-name))
(filename (buffer-file-name))
(read-file-name-function 'read-file-name-default))
(if (not (and filename (file-exists-p filename)))
(error "Buffer '%s' is not visiting a file!" name)
(let ((new-name (read-file-name "New name: " filename)))
(cond ((get-buffer new-name)
(error "A buffer named '%s' already exists!" new-name))
(t
(rename-file filename new-name 1)
(rename-buffer new-name)
(set-visited-file-name new-name)
(set-buffer-modified-p nil)
(message "File '%s' successfully renamed to '%s'" name (file-name-nondirectory new-name))))))))
;;; rg
(require 'rg)
(setq rg-group-result t
rg-show-columns t
rg-align-line-number-field-length 3
rg-align-column-number-field-length 3
rg-align-line-column-separator "#"
rg-align-position-content-separator "|"
rg-hide-command nil
rg-align-position-numbers t
rg-command-line-flags '("--follow"))
;;; project
(require 'project)
(setq project-mode-line t
project-switch-commands '((project-find-file "Find file" f)
(project-dired "Dired" d)
(project-eshell "Eshell" e)
(magit-project-status "Magit" ?m)))
;;; prog mode related
(add-hook 'prog-mode-hook 'electric-pair-mode)
(add-hook 'prog-mode-hook 'flymake-mode)
;; compile mode
(add-hook 'compilation-filter-hook 'ansi-color-compilation-filter)
(setq compilation-always-kill t
compilation-context-lines 10
compilation-disable-input t
compilation-scroll-output 'first-error
compilation-scroll-output t
compilation-skip-threshold 2
compilation-ask-about-save nil)
;; elisp
(add-hook 'emacs-lisp-mode-hook 'eldoc-mode)
(add-hook 'emacs-lisp-mode-hook 'flymake-mode)
(setq eldoc-idle-delay 1
eldoc-documentation-strategy #'eldoc-documentation-default
eldoc-echo-area-use-multiline-p nil)
;; direnv
(require 'direnv)
(direnv-mode t)
(setq direnv-always-show-summary nil)
;; eglot
(require 'eglot)
(add-hook 'python-mode-hook 'eglot-ensure)
(add-hook 'go-mode-hook 'eglot-ensure)
(add-hook 'nix-mode-hook 'eglot-ensure)
(setq eglot-send-changes-idle-time 0.1
eglot-autoshutdown t)
(setq-default eglot-workspace-configuration
'(:pylsp (:plugins (:ruff (:enabled t)))
:nil (:formatting (:command ["nixfmt"]))
:gopls (:usePlaceholders t
:staticcheck t
:completeUnimported t
:matcher "CaseSensitive")))
;; uses https://github.com/nix-community/nixd for the LSP server instead of rnix
(with-eval-after-load 'eglot
(add-to-list 'eglot-server-programs '(nix-mode . ("nil"))))
;; flymake
(require 'flymake)
(setq flymake-start-on-save-buffer t
flymake-fringe-indicator-position 'left-fringe
flymake-suppress-zero-counters t
flymake-no-changes-timeout 9999
elisp-flymake-byte-compile-load-path load-path)
;;; completion
(require 'consult)
(require 'consult-imenu)
(require 'consult-compile)
(require 'corfu)
(require 'corfu-popupinfo)
(require 'cape)
(require 'marginalia)
(require 'orderless)
(require 'vertico)
(global-corfu-mode t)
(corfu-popupinfo-mode t)
(marginalia-mode t)
(vertico-mode t)
(setq corfu-auto t)
(setq completion-styles '(orderless basic)
completion-category-defaults nil)
(bind-key "C-x b" #'consult-buffer)
(bind-key "C-x r b" #'consult-bookmark)
(bind-key "C-x p b" #'consult-project-buffer)
(bind-key "C-c i" #'consult-imenu)
(bind-key "M-g e" #'consult-compile-error)
(bind-key "M-g M-g" #'consult-goto-line)
(bind-key "M-g m" #'consult-mark)
(bind-key "M-g k" #'consult-global-mark)
(add-hook 'after-init-mode 'global-corfu-mode)
(add-hook 'after-init-mode 'vertico-mode)
;;; theming
(require-theme 'modus-themes)
(setq modus-themes-italic-constructs t
modus-themes-bold-constructs t
modus-themes-mixed-fonts t
modus-themes-variable-pitch-ui nil
modus-themes-prompts '(italic bold)
modus-themes-completions
'((matches . (extrabold))
(selection . (semibold italic text-also))))
(load-theme 'modus-operandi-tinted :no-confirm)
;;; 1Password Integration
(defvar fcuny/op-item-cache nil)
(defun fcuny/read-op-item (op-item-path)
"Read and cache OP-ITEM-PATH item."
(or (cdr (assoc op-item-path fcuny/op-item-cache))
(let ((key (string-trim-right
(shell-command-to-string (format "op read '%s'" op-item-path)))))
(unless (string-match-p "\\[ERROR\\]" key)
(push (cons op-item-path key) fcuny/op-item-cache)
key))))
;;; gptel
(require 'gptel)
(with-eval-after-load 'gptel
(setq gptel-default-mode 'org-mode)
(gptel-make-anthropic "Claude"
:stream t
:key (lambda () (fcuny/read-op-item "op://Private/anthropic llm/credential"))))
;;; aider
(require 'aidermacs)
(global-set-key (kbd "C-c a") 'aidermacs-transient-menu)
(with-eval-after-load 'aidermacs
(setq aider-args '("--no-check-update" "--no-show-model-warnings"))
(setq aidermacs-default-model "claude-3-7-sonnet-latest")
(setenv "ANTHROPIC_API_KEY" (fcuny/read-op-item "op://Private/anthropic llm/credential")))
;;; early-init.el ends here
;; byte-compile-warnings: (not docstrings lexical noruntime)
;; End:
|