26 KiB
EMACS Configuration.
- Configure
use-package
- Configure exec-path
- UI Preferences
- Basic Configuration
- Packages Configuration
- Programming Environments Configuration
- Setup EMACS as TWM
- Personal Configuration
Configure use-package
Always compile the packages, and use the newest version available.
(require 'use-package-ensure)
;;(use-package-always-ensure t)
(use-package auto-package-update
:custom
(auto-package-update-interval 7)
(auto-package-update-prompt-before-update t)
(auto-package-update-hide-results t)
:config
(auto-package-update-maybe)
(auto-package-update-at-time "09:00"))
(use-package general :ensure t)
Configure exec-path
(use-package exec-path-from-shell
:ensure t
:config (exec-path-from-shell-initialize))
UI Preferences
Tweak EMACS' window
Disable menu, scrollbar and minibuffer scrollbar; Enable hl-line-mode.
(if (display-graphic-p)
(progn
(tool-bar-mode -1)
(menu-bar-mode -1)
(scroll-bar-mode -1)))
(set-window-scroll-bars (minibuffer-window) nil nil)
(global-hl-line-mode 1)
(defalias 'yes-or-no-p 'y-or-n-p)
Bind frame title to the name of the current project.
(setq frame-title-format '((:eval (projectile-project-name))))
Disable stuff
(setq inhibit-startup-message t) ;; replaced afterwards
(setq ring-bell-function 'ignore)
UTF-8
(setq locale-coding-system 'utf-8)
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(set-selection-coding-system 'utf-8)
(prefer-coding-system 'utf-8)
Load theme
Set fonts.
(add-to-list 'default-frame-alist '(font . "Iosevka" ))
(set-face-attribute 'default t :font "Iosevka" )
Use modus-vivendi
theme.
(use-package modus-themes :ensure t)
(require 'modus-themes)
;; Add all your customizations prior to loading the themes
(setq modus-themes-italic-constructs t
modus-themes-bold-constructs nil
modus-themes-region '(bg-only no-extend))
;; Load the theme files before enabling a theme
;;(modus-themes-load-themes)
;; Load the theme of your choice:
;;(modus-themes-load-vivendi) ;; OR (modus-themes-load-vivendi)
(define-key global-map (kbd "<f5>") #'modus-themes-toggle)
Setup icons.
(use-package all-the-icons
:ensure t
:init)
(use-package all-the-icons-dired
:ensure t
:init (add-hook 'dired-mode-hook 'all-the-icons-dired-mode))
(use-package all-the-icons-ibuffer
:ensure t
:init (all-the-icons-ibuffer-mode 1))
Load modeline
Spaceline.
(use-package spaceline
:ensure t
:config
(require 'spaceline-config)
(setq powerline-default-separator (quote arrow))
(spaceline-spacemacs-theme))
Environment specific configuration
ORG-mode
Environment
Replace ORG-mode
ellipsis with a downward arrow.
(setq org-ellipsis "↲")
(setq org-indent-mode t)
(setq org-startup-indented t)
Basic Configuration
Use firefox
(setenv "BROWSER" "librewolf")
Change alt-key to super-key
(setq x-super-keysym 'meta)
Enable relative line numbering.
(setq display-line-numbers-type 'relative)
(defcustom display-line-numbers-exempt-modes
'(eshell-mode shell-mode term-mode ansi-term-mode org-mode)
"Major modes on which to disable line numbers."
:group 'display-line-numbers
:type 'list
:version "green")
(defun display-line-numbers--turn-on ()
"Turn on line numbers except for certain major modes.
Exempt major modes are defined in `display-line-numbers-exempt-modes'."
(unless (or (minibufferp)
(member major-mode display-line-numbers-exempt-modes))
(display-line-numbers-mode)))
(global-set-key [f4] 'display-line-numbers-mode)
(global-display-line-numbers-mode)
Increase the garbage collector threshold, to speed up some operations.
(setq gc-cons-threshold 20000000)
Treat CamelCaseSubWords as seperate words.
(add-hook 'prog-mode-hook 'subword-mode)
If a file starts with #!, make it executable.
(add-hook 'after-save-hook 'executable-make-buffer-file-executable-if-script-p)
If saving a file in a directory doesn't exist, offer to create the parent directories recursively.
(add-hook 'before-save-hook
(lambda ()
(when buffer-file-name
(let ((dir (file-name-directory buffer-file-name)))
(when (and (not (file-exists-p dir)) y-or-n-p (format "Directory %s does not exist, Create it?" dir))
(make-directory dir t ))))))
Require having a new line.
(setq require-final-newline t)
Make file sizes human-readable to dired buffers.
(setq-default dired-listing-switches "-alh")
Refresh buffer when the file is changed, stoping buffers and file getting out of sync.
(global-auto-revert-mode t)
When pressing the middle mouse button, paste where the curser is rather than where the mouse is.
(setq mouse-yank-at-point 1)
Better increase and decrease text scale.
(global-set-key (kbd "C-+") 'text-scale-increase)
(global-set-key (kbd "C--") 'text-scale-decrease)
Enable visual parantheses matching.
(show-paren-mode 1)
Keep folders clean
;; NOTE: If you want to move everything out of the ~/.emacs.d folder
;; reliably, set `user-emacs-directory` before loading no-littering!
;(setq user-emacs-directory "~/.cache/emacs")
(use-package no-littering)
;; no-littering doesn't set this by default so we must place
;; auto save files in the same path as it uses for sessions
(setq auto-save-file-name-transforms
`((".*" ,(no-littering-expand-var-file-name "auto-save/") t)))
Startup Performance
;; The default is 800 kilobytes. Measured in bytes.
(setq gc-cons-threshold (* 50 1000 1000))
(defun efs/display-startup-time ()
(message "Emacs loaded in %s with %d garbage collections."
(format "%.2f seconds"
(float-time
(time-subtract after-init-time before-init-time)))
gcs-done))
(add-hook 'emacs-startup-hook #'efs/display-startup-time)
(setq display-time-default-load-average 1)
Config edit.
(defun config-visit ()
(interactive)
(find-file "~/.config/emacs/config.org"))
(global-set-key (kbd "C-c e") 'config-visit)
Config reload.
(defun config-reload ()
(interactive)
(org-babel-load-file (expand-file-name "~/.config/emacs/config.org")))
(global-set-key (kbd "C-c r") 'config-reload)
Fix tiling window managers
(setq frame-resize-pixelwise t)
Text line stuff
(setq-default truncate-lines t)
(setq-default tab-width 4)
(setq-default fill-column 80)
(setq sentence-end-double-space nil)
Scroll
(setq redisplay-dont-pause t
scroll-margin 1
scroll-step 1
scroll-conservatively 10000
scroll-preserve-screen-position 1)
Bells
(setq visible-bell t)
(setq line-move-visual t)
Encoding
(when (fboundp 'set-charset-priority)
(set-charset-priority 'unicode)) ; pretty
(prefer-coding-system 'utf-8) ; pretty
(setq locale-coding-system 'utf-8) ; please
Packages Configuration
hungry-delete
Enable hungry-delete
.
(use-package hungry-delete
:ensure t
:config (global-hungry-delete-mode))
beacon
Enable beacon
.
(use-package beacon
:ensure t
:config (beacon-mode 1))
rainbow
Enable rainbow
.
(use-package rainbow-mode
:ensure t
:init (add-hook 'prog-mode-hook 'rainbow-mode))
(use-package rainbow-delimiters
:ensure t
:init (rainbow-delimiters-mode 1))
async
Enable async
.
(use-package async
:ensure t
:init (dired-async-mode 1))
which-key
Enable which-key
everywhere.
(use-package which-key)
(which-key-mode)
evil-mode
Enable evil-mode
everywhere.
(setq evil-want-C-i-jump nil)
(use-package evil)
(evil-mode 1)
company
Enable company-mode
everywhere.
(use-package company)
(add-hook 'after-init-hook 'global-company-mode)
Use M-/
for completion.
(global-set-key (kbd "M-/") 'company-complete-common)
company-tabnine
;;(use-package company-tabnine
;; :ensure t)
;;(require 'company-tabnine)
;;(add-to-list 'company-backends #'company-tabnine)
;;(setq company-idle-delay 0)
;;(setq company-show-numbers t)
magit
Use magit for git repos managment.
(use-package magit
:ensure t
:bind ("M-g" . magit-status))
projectile
Use projectile for useful funcationality for project management.
(use-package projectile)
(projectile-mode +1)
(define-key projectile-mode-map (kbd "C-c p") 'projectile-command-map)
undo-tree
Use undo-tree
.
(use-package undo-tree)
darkroom
Use darkroom
.
(use-package darkroom)
(global-set-key (kbd "<f3>") 'darkroom-mode)
dashboard
.
(use-package dashboard
:ensure t
:config
(dashboard-setup-startup-hook)
;;(setq dashboard-startup-banner "~/.emacs.d/img/avatar.png")
(setq dashboard-items '((recents . 5)
(projects . 5)))
(setq dashboard-banner-logo-title "ello dere!")
(setq dashboard-center-content t)
(setq initial-buffer-choice (lambda () (get-buffer "*dashboard*"))))
fancy-battery
.
(use-package fancy-battery
:ensure t
:init
(fancy-battery-mode 1)
(setq fancy-battery-show-percentage t))
diminish
(use-package diminish
:ensure
:init
(diminish 'which-key-mode)
(diminish 'linum-relative-mode)
(diminish 'hungry-delete-mode)
(diminish 'visual-line-mode)
(diminish 'subword-mode)
(diminish 'beacon-mode)
(diminish 'irony-mode)
(diminish 'page-break-lines-mode)
(diminish 'auto-revert-mode)
(diminish 'rainbow-delimiters-mode)
(diminish 'rainbow-mode)
(diminish 'yas-minor-mode)
(diminish 'flycheck-mode))
sudo-edit
(use-package sudo-edit
:ensure t
:bind ("s-e" . sudo-edit))
avy
(use-package avy
:ensure t
:bind
("M-s" . avy-goto-char))
eglot
(use-package eglot
:ensure t
:bind)
(add-hook 'foo-mode-hook 'eglot-ensure)
focus
(use-package focus
:ensure t
:bind)
LSP
(use-package lsp-mode
:init
;; set prefix for lsp-command-keymap (few alternatives - "C-l", "C-c l")
(setq lsp-keymap-prefix "C-c l")
:hook (;; replace XXX-mode with concrete major-mode(e. g. python-mode)
(XXX-mode . lsp)
;; if you want which-key integration
(lsp-mode . lsp-enable-which-key-integration))
:commands lsp)
;; optionally
(use-package lsp-ui :commands lsp-ui-mode)
;; if you are helm user
(use-package helm-lsp :commands helm-lsp-workspace-symbol)
(use-package lsp-treemacs :commands lsp-treemacs-errors-list)
;; optionally if you want to use debugger
(use-package dap-mode)
;; (use-package dap-LANGUAGE) to load the dap adapter for your language
;; optional if you want which-key integration
(use-package which-key
:config
(which-key-mode))
org-reveal
(use-package ox-reveal
:ensure t)
org-roam
(use-package org-roam
:ensure t
:init
(setq org-roam-v2-ack t)
:custom
(org-roam-directory "~/dox/roamnotes")
(org-roam-completion-everywhere t)
:bind(("C-c n l" . org-roam-buffer-toggle)
("C-c n f" . org-roam-node-find)
("C-c n i" . org-roam-node-insert)
:map org-mode-map
("C-M-i" . completion-at-point))
:config
(org-roam-setup))
simple-httpd
(use-package simple-httpd
:ensure t)
rainbow-delimiters
(use-package rainbow-delimiters)
yassnippets
(use-package yasnippet
:ensure t
:init
(yas-global-mode 1))
(use-package yasnippet-snippets :ensure t)
(use-package yasnippet-classic-snippets :ensure t)
Environment Specific Packages.
Lisp Environment
Use paredit
.
(use-package paredit)
Use rainbow-delimiters
.
(use-package rainbow-delimiters)
Web Stuff
(use-package web-mode :ensure t)
(add-hook 'html-mode-hook 'web-mode) ;; Auto-start on any markup modes
(use-package emmet-mode :ensure t)
(add-hook 'web-mode-hook 'emmet-mode)
Org mode
(defvar org-directory "~/org/")
(set-register ?i (cons 'file (concat org-directory "ideas.org")))
(set-register ?a (cons 'file (concat org-directory "agendas")))
(setq org-todo-keywords '((type "TODO(t)" "READ(r)" "PROJ(p)"
"CONTACT(c)" "HW(h)" "STUDY(s)" "SOMEDAY(S)"
"|" "DONE(d)" "CANCELLED(C)")))
(setq org-todo-keyword-faces '(("TODO" nil :foreground "orange1" :inherit fixed-pitch :weight medium)
("HW" nil :foreground "coral1" :inherit fixed-pitch :weight medium)
("STUDY" nil :foreground "plum3" :inherit fixed-pitch :weight medium)
("SOMEDAY" nil :foreground "steel blue" :inherit fixed-pitch)
("CONTACT" nil :foreground "LightSalmon2" :inherit fixed-pitch :weight medium)
("READ" nil :foreground "MediumPurple3" :inherit fixed-pitch :weight medium)
("PROJ" nil :foreground "aquamarine3" :inherit fixed-pitch :weight medium)
("DONE" nil :foreground "LawnGreen" :inherit fixed-pitch :weight medium)
("CANCELLED" nil :foreground "dark red" :inherit fixed-pitch :weight medium)))
Completion Frameworks
(use-package vertico
:ensure t
:init
(vertico-mode))
(use-package orderless
:ensure t
:init
(setq completion-styles '(orderless)
completion-category-defaults nil
completion-category-overrides '((file (styles partial-completion)))))
;; Persist history over Emacs restarts. Vertico sorts by history position.
(use-package savehist
:ensure t
:init
(savehist-mode))
;; A few more useful configurations...
(use-package emacs
:init
;; Add prompt indicator to `completing-read-multiple'.
;; Alternatively try `consult-completing-read-multiple'.
(defun crm-indicator (args)
(cons (concat "[CRM] " (car args)) (cdr args)))
(advice-add #'completing-read-multiple :filter-args #'crm-indicator)
;; Do not allow the cursor in the minibuffer prompt
(setq minibuffer-prompt-properties
'(read-only t cursor-intangible t face minibuffer-prompt))
(add-hook 'minibuffer-setup-hook #'cursor-intangible-mode)
;; Emacs 28: Hide commands in M-x which do not work in the current mode.
;; Vertico commands are hidden in normal buffers.
;; (setq read-extended-command-predicate
;; #'command-completion-default-include-p)
;; Enable recursive minibuffers
(setq enable-recursive-minibuffers t))
(use-package marginalia
:ensure t
:config (marginalia-mode))
(use-package consult
:ensure t
:general
("M-y" 'consult-yank-from-kill-ring
"C-x b" 'consult-buffer))
(recentf-mode)
(setq completion-ignore-case t)
(setq read-file-name-completion-ignore-case t)
(use-package orderless
:ensure t
:init
(setq completion-styles '(orderless)))
(use-package company
:ensure t
:config
(setq company-idle-delay 0)
(setq company-minimum-prefix-length 3)
(global-company-mode t))
(use-package embark
:ensure t
:bind
(("C-." . embark-act) ;; pick some comfortable binding
("C-;" . embark-dwim) ;; good alternative: M-.
("C-h B" . embark-bindings)) ;; alternative for `describe-bindings'
:init
;; Optionally replace the key help with a completing-read interface
(setq prefix-help-command #'embark-prefix-help-command)
:config
;; Hide the mode line of the Embark live/completions buffers
(add-to-list 'display-buffer-alist
'("\\`\\*Embark Collect \\(Live\\|Completions\\)\\*"
nil
(window-parameters (mode-line-format . none))))
)
;; Consult users will also want the embark-consult package.
(use-package embark-consult
:ensure t
:after (embark consult)
:demand t ; only necessary if you have the hook below
;; if you want to have consult previews as you move around an
;; auto-updating embark collect buffer
:hook
(embark-collect-mode . consult-preview-at-point-mode))
Programming Environments Configuration
Use 4-spaced characters for tabs by default.
(setq-default tab-width 4)
Use subword mode.
(use-package subword
:config (global-subword-mode 1))
C/C++
Environment
Set the tab width when using C/C++ mode.
(setq-default c-basic-offset 4)
Kotlin
Environment
(use-package kotlin-mode
:ensure t)
(add-to-list 'auto-mode-alist '("\\.kt\\'" . kotlin-mode))
Lisp
Environment
Uses lisp packages when lisp languages are enabled.
(setq lispy-mode-hooks
'(emacs-lisp-hook lisp-mode-hook))
(dolist (hook lispy-mode-hooks)
(add-hook hook (lambda()
(setq show-paren-style 'expression)
(paredit-mode)
(rainbow-delimeters-mode))))
Set tab with
org-mode
Environment
Enable indentation in org
source blocks.
(setq org-src-tab-acts-natively t)
Better org bullets.
(use-package org-bullets
:ensure t
:config
(add-hook 'org-mode-hook (lambda () (org-bullets-mode 1))))
Flyspell
(add-hook 'org-mode-hook 'turn-on-flyspell)
(add-hook 'org-mode-hook 'turn-on-auto-fill)
sh
Environment
Indent with 4 spaces.
(add-hook 'sh-mode-hook
(lambda ()
(setq sh-basic-offset 4
sh-indentation 4)))
markdown
Environment
Enable markdown
.
(use-package markdown-mode
:ensure t
:commands (markdown-mode gfm-mode)
:mode (("README\\.md\\'" . gfm-mode)
("\\.md\\'" . markdown-mode)
("\\.markdown\\'" . markdown-mode))
:init (setq markdown-command "multimarkdown"))
Setup EMACS as TWM
exwm
Use exwm
, and setup desktop environment.
(use-package exwm
:ensure t
:config
(require 'exwm-config)
(fringe-mode 1)
;;(server-start)
;;(exwm-config-ido)
(setq exwm-workspace-number 10)
(exwm-input-set-key (kbd "s-r") #'exwm-reset)
(exwm-input-set-key (kbd "s-k") #'exwm-workspace-delete)
(exwm-input-set-key (kbd "s-w") #'exwm-workspace-swap)
(dotimes (i 10)
(exwm-input-set-key (kbd (format "s-%d" i))
`(lambda ()
(interactive)
(exwm-workspace-switch-create ,i)
(message "Workspace %d", i))))
(exwm-input-set-key (kbd "s-&")
(lambda (command)
(interactive (list (read-shell-command "$ ")))
(start-process-shell-command command nil command)))
(setq exwm-input-simulation-keys
'(([?\C-h] . [left])
([?\C-l] . [right])
([?\C-k] . [up])
([?\C-j] . [down])
([?\C-0] . [home])
([?\C-e] . [end])
([?\M-v] . [prior])
([?\C-v] . [next])
([?\C-d] . [delete])
([?\C-k] . [S-end delete]))))
;; other stuff
(use-package desktop-environment
:ensure t
:init (desktop-environment-mode 1)
:config
(setq desktop-environment-screenlock-command "xsecurelock"))
(use-package dmenu
:ensure t
:bind
("s-SPC" . 'dmenu))
(require 'vterm)
(use-package vterm
:ensure t
:init
(global-set-key (kbd "<s-return>") 'term))
;;(require 'exwm-systemtray)
;;(exwm-systemtray-enable)
setup clock
(setq display-time-24hr-format t)
(setq display-time-format "%H:%M")
(display-time-mode 1)
elfeed
package
(use-package elfeed)
(setf url-queue-timeout 30)
;; mark all youtube entries
(add-hook 'elfeed-new-entry-hook
(elfeed-make-tagger :feed-url "youtube\\.com"
:add '(video youtube)))
;; mark all odysee entries
(add-hook 'elfeed-new-entry-hook
(elfeed-make-tagger :feed-url "odysee\\.com"
:add '(video odysee)))
;; entries older than 2 weeks are marked as read
(add-hook 'elfeed-new-entry-hook
(elfeed-make-tagger :before "2 weeks ago"
:remove 'unread))
;; use mpv
(defun altf4/play-with-mpv (start end)
"Play the link in the region with mpv"
(interactive "r")
(shell-command (concat "mpv " (buffer-substring start end) --ytdl-format=bestvideo[height<=?720][fps<=?30]+bestaudio/best"\&")))
(define-key elfeed-show-mode-map (kbd "C-c o") 'altf4/play-with-mpv)
;; elfeed feed
(setq elfeed-feeds
'(("https://lukesmith.xyz/rss.xml" blog)
("https://lukesmith.xyz/videos" video)
("https://notrelated.xyz/rss" podcast)
("https://youtube.com/feeds/videos.xml?channel_id=UCZ4AMrDcNrfy3X6nsU8-rPg" economics)
("https://youtube.com/feeds/videos.xml?channel_id=UCL_f53ZEJxp8TtlOkHwMV9Q" philosphy)
("https://youtube.com/feeds/videos.xml?channel_id=UClcE-kVhqyiHCcjYwcpfj9w" security)
("https://youtube.com/feeds/videos.xml?channel_id=UCDETFHKteb-C_EaXmRKvP4w" philosphy)
("https://youtube.com/feeds/videos.xml?channel_id=UCIveFvW-ARp_B_RckhweNJw" based politics)
("https://youtube.com/feeds/videos.xml?channel_id=UCld68syR8Wi-GY_n4CaoJGA" tech)
("https://youtube.com/feeds/videos.xml?channel_id=UCO01ytfzgXYy4glnPJm4PPQ" based politics)
("https://youtube.com/feeds/videos.xml?channel_id=UC-wBAxgUX9P0fXZ6-D0frRA" comedy based)
("https://youtube.com/feeds/videos.xml?channel_id=UCDETFHKteb-C_EaXmRKvP4w" philosphy)
("https://youtube.com/feeds/videos.xml?channel_id=UCr4kgAUTFkGIwlWSodg43QA" based politics)
("https://youtube.com/feeds/videos.xml?channel_id=UCoryWpk4QVYKFCJul9KBdyw" tech based)
("https://drewdevault.com/blog/index.xml" blog)
("https://unixsheikh.com/feed.rss" blog)))
erc
package
Configure erc
.
(setq
erc-nick "sisyphus"
erc-user-full-name "ello")
setup music
emms
(use-package emms
:ensure t
:config
(require 'emms-setup)
(require 'emms-player-mpd)
(emms-all) ; don't change this to values you see on stackoverflow questions if you expect emms to work
(setq emms-source-file-default-directory "~/muz/")
(setq emms-seek-seconds 5)
(setq emms-player-list '(emms-player-mpd))
(setq emms-info-functions '(emms-info-mpd))
(setq emms-player-mpd-server-name "localhost")
(setq emms-player-mpd-server-port "6602")
:bind
("s-m p" . emms)
("s-m b" . emms-smart-browse)
("s-m r" . emms-player-mpd-update-all-reset-cache)
("<XF86AudioPrev>" . emms-previous)
("<XF86AudioNext>" . emms-next)
("<XF86AudioPlay>" . emms-pause)
("<XF86AudioStop>" . emms-stop))
mpc
(setq mpc-host "127.0.0.1")
(defun mpd/start-music-daemon ()
"Start MPD, connects to it and syncs the metadata cache."
(interactive)
(shell-command "mpd")
(mpd/update-database)
(emms-player-mpd-connect)
(emms-cache-set-from-mpd-all)
(message "MPD Started!"))
(global-set-key (kbd "s-m c") 'mpd/start-music-daemon)
(defun mpd/kill-music-daemon ()
"Stops playback and kill the music daemon."
(interactive)
(emms-stop)
(call-process "killall" nil nil nil "mpd")
(message "MPD Killed!"))
(global-set-key (kbd "s-m k") 'mpd/kill-music-daemon)
(defun mpd/update-database ()
"Updates the MPD database synchronously."
(interactive)
(call-process "mpc" nil nil nil "update")
(message "MPD Database Updated!"))
(global-set-key (kbd "s-m u") 'mpd/update-database)
Personal Configuration
(setq user-full-name "ayham"
user-mail-address "me@ayham.xyz")