22 KiB
Emacs Configuration
- Personal Information
- Sane defaults
- Packages
- Dashboard
- PDFTools
- ORG Mode
- Doom-modeline
- Ace window
- Which-key
- Swiper
- Beacon
- Async
- Page-break-lines
- Undoo-tree
- Saveplace
- Eldoc
- Try
- Auto-complete
- Neotree
- Color-theme-modern
- Flycheck
- Recentf
- Expand region
- Smoothscrolling
- Webmode
- Emmet
- Scratch major mode
- Shell pop
- Quickrun
- terminal-here
- Whitespace
- Ivy
- Packages config
I've been using emacs for a while now and dicided that it is time to convert my configs to org mode.
This configuration uses the use-package package from John Wiegley, which is a fantastic way to manage package configurations.
Personal Information
(setq user-full-name "b2r1s8"
user-mail-address "")
Sane defaults
The default emacs config is ugly and not efficient.
Startup Performance
Make startup faster by reducing the frequency of garbage collection and then use a hook to measure Emacs startup time.
;; The default is 800 kilobytes. Measured in bytes.
(setq gc-cons-threshold (* 50 1000 1000))
;; 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)))
Customizing emacs
;; Fist things first
(setq inhibit-startup-message t)
(tool-bar-mode -1) ;; Remove tool bar C-x u undo | C-w cut | M-w copy | C-y paste
(menu-bar-mode -1) ;; Remove menus
(scroll-bar-mode -1) ;; Remove scroll bar
(global-hl-line-mode t) ;; Show current line
(global-prettify-symbols-mode t) ;; Prettify symbols mode
(set-face-attribute 'default nil :height 80) ;; Font size
(column-number-mode 1) ;; Colummns numeration
(show-paren-mode 1) ;; Show parent parentesis
(setq visible-bell t) ;; Visible bell
;;(setq-default header-line-format mode-line-format)
(setq-default mode-line-format nil)
(setq-default header-line-format nil)
(setq
backup-by-copying t ; don't clobber symlinks
backup-directory-alist
'(("." . "~/.emacs.d/backups/")) ; don't litter my fs tree
delete-old-versions t
kept-new-versions 6
kept-old-versions 2
version-control t) ; use versioned backups
;; Tabbar
(use-package tabbar)
(tab-bar-mode 1) ;; Additing tabs
;; Show time and date on the mode line
(setq display-time-day-and-date t)
(setq display-time-format "%a %b %F %R")
(display-time-mode 1)
;; Frame tansparency
(set-frame-parameter (selected-frame) 'alpha '(75 . 75))
(add-to-list 'default-frame-alist '(alpha . (75 . 75)))
(set-frame-parameter (selected-frame) 'fullscreen 'maximized)
(add-to-list 'default-frame-alist '(fullscreen . maximized))
;; Line numbers
(global-linum-mode t)
(setq linum-format "%2d \u2502")
(dolist (mode '(org-mode-hook
term-mode-hook
shell-mode-hook
treemacs-mode-hook
eshell-mode-hook))
(add-hook mode (lambda () (display-line-numbers-mode 0))))
;; Border
(setq frame-resize-pixelwise t)
(set-frame-parameter nil 'fullscreen 'fullboth)
;; Keep all backup and auto-save files in one directory
(setq backup-directory-alist '(("." . "~/.emacs.d/backups")))
(setq auto-save-file-name-transforms '((".*" "~/.emacs.d/auto-save-list/" t)))
;; UTF-8 please
(setq locale-coding-system 'utf-8) ; pretty
(set-terminal-coding-system 'utf-8) ; pretty
(set-keyboard-coding-system 'utf-8) ; pretty
(set-selection-coding-system 'utf-8) ; please
(prefer-coding-system 'utf-8) ; with sugar on top
;; Identation:
(setq-default tab-width 2)
(setq-default standard-indent 2)
(setq c-basic-offset tab-width)
(setq-default electric-indent-inhibit t)
(setq-default indent-tabs-mode nil)
(setq backward-delete-char-untabify-method 'nil)
;; Enable bracket pair-matching
(setq electric-pair-pairs '(
(?\{ . ?\})
(?\( . ?\))
(?\[ . ?\])
(?\" . ?\")
))
(electric-pair-mode t)
Changing how focus work
This fuction change the focus to the new window
;;; Mude o foco p/ novas janelas
(defun split-and-follow-horizontally ()
(interactive)
(split-window-below)
(balance-windows)
(other-window 1))
(defun split-and-follow-vertically ()
(interactive)
(split-window-right)
(balance-windows)
(other-window 1))
Alias
Some alias that make my life easier
;; Alias
(defalias 'yes-or-no-p 'y-or-n-p)
(defalias 'open 'find-file-other-window)
(defalias 'clean 'eshell/clear-scrollback)
(defalias 'list-buffers 'ibuffer)
Key binds
Some key binds to make my life easier
(global-unset-key (kbd "C-z")) ;; Unbind C-z
(global-unset-key (kbd "C-Z")) ;; Unbind C-Z
(global-set-key (kbd "s-<up>") 'windmove-up)
(global-set-key (kbd "s-<down>") 'windmove-down)
(global-set-key (kbd "s-<right>") 'windmove-right)
(global-set-key (kbd "s-<left>") 'windmove-left)
(global-set-key (kbd "C-<tab>") 'other-window)
(global-set-key (kbd "C-x 3") 'split-and-follow-vertically)
(global-set-key (kbd "C-x 2") 'split-and-follow-horizontally)
(global-set-key (kbd "C-c l") 'org-store-link)
(global-set-key (kbd "C-c a") 'org-agenda)
(global-set-key (kbd "C-c c") 'org-capture)
Functions
Some Functions that I use.
Dashboard
;; Open new tab on the dashboard
(defun new-tab ()
(interactive)
(tab-new-to)
(switch-to-buffer (get-buffer-create "*dashboard*")))
(global-set-key (kbd "s-x") 'new-tab)
(global-set-key (kbd "s-X") 'tab-close)
Midnight + cleanbuffer-list
;; Configuring desktop
;;(require 'desktop)
;; (desktop-save-mode 1)
;; (defun my-desktop-save ()
;; (interactive)
;; ;; Don't call desktop-save-in-desktop-dir, as it prints a message.
;; (if (eq (desktop-owner) (emacs-pid))
;; (desktop-save desktop-dirname)))
;; (add-hook 'auto-save-hook 'my-desktop-save)
;;
;;(setq clean-buffer-list-delay-general 1)
;;
;;;; Configuring midnight
;;(require 'midnight)
;;(midnight-delay-set 'midnight-delay "6:30am")
Packages
Some packages that I use.
Dashboard
A beatiful and usefull dashboard.
(use-package dashboard
:ensure t
:defer nil
:preface
(defun init-edit ()
"Edit initialization file."
(interactive)
(find-file "~/.emacs.d/init.el"))
(defun conf-edit ()
"Edit configuration file."
(interactive)
(find-file "~/.emacs.d/config.org"))
(defun create-scratch-buffer ()
"Create a scratch buffer."
(interactive)
(switch-to-buffer (get-buffer-create "*scratch*"))
(lisp-interaction-mode))
:config
(dashboard-setup-startup-hook)
(setq dashboard-items '((recents . 25)))
(setq dashboard-banner-logo-title "Welcome to Emacs!")
(setq dashboard-startup-banner "~/.emacs.d/img/emacs.png")
(setq dashboard-center-content t)
(setq dashboard-show-shortcuts nil)
(setq dashboard-set-init-info t)
(setq dashboard-init-info (format "%d packages loaded in %s"
(length package-activated-list) (emacs-init-time)))
(setq dashboard-set-footer nil)
(setq dashboard-set-navigator t)
(setq dashboard-navigator-buttons
`(((,nil
"Open init.el file."
"Open Emacs initialization file for easy editing."
(lambda (&rest _) (init-edit))
'default)
(nil
"Open config.org file."
"Open Emacs configuration file for easy editing."
(lambda (&rest _) (conf-edit))
'default)
(nil
"Open scratch buffer."
"Switch to the scratch buffer."
(lambda (&rest _) (create-scratch-buffer))
'default)))))
PDFTools
Change viewdoc to pdfview with pdftools
(use-package pdf-tools
:defer t
:commands (pdf-view-mode pdf-tools-install)
:mode ("\\.[pP][dD][fF]\\'" . pdf-view-mode)
:load-path "site-lisp/pdf-tools/lisp"
:magic ("%PDF" . pdf-view-mode)
:config
(pdf-tools-install)
(define-pdf-cache-function pagelabels)
:hook ((pdf-view-mode-hook . (lambda () (display-line-numbers-mode -1)))
(pdf-view-mode-hook . pdf-tools-enable-minor-modes)))
(use-package pdf-view-restore
:after pdf-tools
:config
(add-hook 'pdf-view-mode-hook 'pdf-view-restore-mode))
;;(use-package org-pdftools
;; :hook (org-load-hook . org-pdftools-setup-link))
(add-hook 'pdf-view-mode-hook (lambda() (linum-mode -1)))
ORG Mode
Org mode configurantion.
;; Org init
(use-package org
:config
(add-hook 'org-mode-hook
'(lambda ()
(visual-line-mode 1)))
(setq org-display-inline-images t)
(setq org-redisplay-inline-images t)
(setq org-startup-with-inline-images "inlineimages")
(setq org-directory "~/.emacs.d/org")
(setq org-agenda-files (list "inbox.org"))
(global-set-key (kbd "C-<f1>") (lambda()
(interactive)
(outline-show-all))))
(use-package org-bullets
:config
(add-hook 'org-mode-hook (lambda () (org-bullets-mode 1))))
(use-package htmlize
:ensure t)
;; src exec
(org-babel-do-load-languages 'org-babel-load-languages
'(
(shell . t)
)
)
(setq org-src-fontify-natively t
org-src-window-setup 'current-window
org-src-strip-leading-and-trailing-blank-lines t
org-src-preserve-indentation t
org-src-tab-acts-natively t)
(require 'org-tempo)
;; And that'll allow you to type "<sh", "<el", "<py", "<conf" followed by tab to create src blocks for those languages, and you can add as many others as you want.
(add-to-list 'org-structure-template-alist '("sh" . "src shell"))
(add-to-list 'org-structure-template-alist '("el" . "src emacs-lisp"))
(add-to-list 'org-structure-template-alist '("py" . "src python"))
(add-to-list 'org-structure-template-alist '("conf" . "src conf"))
;; Org default head
;;(add-to-list 'org-structure-template-alist
;; '("p" "#+title:\n#+author: b2r1s8@gen2\n#+date:\n#+startup: hidestars odd overview\n\n? "))
Doom-modeline
Default Doom-modeline
(use-package doom-modeline
:ensure t
:init (doom-modeline-mode 1))
(setq doom-modeline-height 5)
;; Hide mode-line when is not usefull
(setq doom-hide-modeline-mode t)
;; The limit of the window width.
;; If `window-width' is smaller than the limit, some information won't be displayed.
(setq doom-modeline-window-width-limit fill-column)
;; Whether display the icon for `major-mode'. It respects `doom-modeline-icon'.
(setq doom-modeline-major-mode-icon t)
;; Whether display the colorful icon for `major-mode'.
;; It respects `all-the-icons-color-icons'.
(setq doom-modeline-major-mode-color-icon t)
;; Whether display the icon for the buffer state. It respects `doom-modeline-icon'.
(setq doom-modeline-buffer-state-icon t)
;; Whether display the modification icon for the buffer.
;; It respects `doom-modeline-icon' and `doom-modeline-buffer-state-icon'.
(setq doom-modeline-buffer-modification-icon t)
;; Whether display the buffer encoding.
(setq doom-modeline-buffer-encoding t)
;; If non-nil, only display one number for checker information if applicable.
(setq doom-modeline-checker-simple-format t)
;; Whether display the workspace name. Non-nil to display in the mode-line.
(setq doom-modeline-workspace-name t)
Ace window
This packages make easy to move around windows.
- x -> delete window
- m -> swap windows
- M -> move window
- c -> copy window
- j -> select buffer
- n -> select the previous window
- u -> select buffer in the other window
- c -> split window fairly, either vertically or horizontally
- v -> split window vertically
- b -> split window horizontally
- o -> maximize current window
- ? -> show these command bindings
(use-package ace-window
:ensure t
:bind (("C-o" . ace-window)))
Which-key
(use-package which-key
:ensure t
:diminish which-key-mode
:init
(which-key-mode)
:config
(setq which-key-idle-delay 0.3))
Swiper
(use-package swiper
:ensure t
:bind ("s-s" . 'swiper))
Beacon
(use-package beacon
:ensure t
:diminish beacon-mode
:init
(beacon-mode 1))
Async
(use-package async
:ensure t
:init
(dired-async-mode 1))
Page-break-lines
(use-package page-break-lines
:ensure t
:diminish (page-break-lines-mode visual-line-mode))
Undoo-tree
(use-package undo-tree
:ensure t
:diminish undo-tree-mode)
Saveplace
(use-package saveplace
:defer nil
:config
(save-place-mode))
Eldoc
(use-package eldoc
:diminish eldoc-mode)
Try
(use-package try
:ensure t)
Auto-complete
(use-package auto-complete
:ensure t
:init
(progn
(ac-config-default)
(global-auto-complete-mode t)))
Neotree
(use-package neotree
:ensure t
:bind (("C-\\" . 'neotree-toggle))) ;; Ativa a tree
Color-theme-modern
(use-package color-theme-modern
:ensure t)
Flycheck
(use-package flycheck
:ensure t
:init (global-flycheck-mode t))
Recentf
(use-package recentf
:config
(recentf-mode t)
(setq recentf-max-saved-items 500))
Expand region
(use-package expand-region
:ensure t
:bind ("C-@" . er/expand-region))
Smoothscrolling
This makes it so C-n
-ing and C-p
-ing won't make the buffer jump
around so much.
(use-package smooth-scrolling
:ensure t
:config
(smooth-scrolling-mode))
Webmode
(use-package web-mode
:ensure t)
Emmet
According to their website, "Emmet — the essential toolkit for web-developers."
(use-package emmet-mode
:ensure t
:commands emmet-mode
:config
(add-hook 'html-mode-hook 'emmet-mode)
(add-hook 'css-mode-hookg 'emmet-mode))
Scratch major mode
Convenient package to create *scratch*
buffers that are based on the
current buffer's major mode. This is more convienent than manually
creating a buffer to do some scratch work or reusing the initial
*scratch*
buffer.
(use-package scratch
:ensure t
:commands scratch)
Shell pop
(use-package shell-pop
:ensure t
:bind ("M-<f12>" . shell-pop))
Quickrun
(use-package quickrun
:defer 10
:ensure t
:bind ("C-c r" . quickrun))
terminal-here
(use-package terminal-here
:ensure t
:bind (("C-c o t" . terminal-here-launch)
("C-c o p" . terminal-here-project-launch)))
Whitespace
(use-package whitespace)
(require 'whitespace)
(setq whitespace-line-column 80) ;; limit line length
(setq whitespace-style '(face lines-tail))
;; Automatically clean whitespace
(use-package ws-butler
:hook ((text-mode . ws-butler-mode)
(prog-mode . ws-butler-mode)))
Ivy
I currently use Ivy, Counsel, and Swiper to navigate around files, buffers, and projects super quickly. Here are some workflow notes on how to best use Ivy:
- While in an Ivy minibuffer, you can search within the current results by using
S-Space
. - To quickly jump to an item in the minibuffer, use
C-'
to get Avy line jump keys. - To see actions for the selected minibuffer item, use
M-o
and then press the action's key. - Super useful: Use
C-c C-o
to openivy-occur
to open the search results in a separate buffer. From there you can click any item to perform the ivy action.
(use-package ivy
:diminish
:bind (("C-s" . swiper)
:map ivy-minibuffer-map
("TAB" . ivy-alt-done)
("C-f" . ivy-alt-done)
("C-l" . ivy-alt-done)
("C-j" . ivy-next-line)
("C-k" . ivy-previous-line)
:map ivy-switch-buffer-map
("C-k" . ivy-previous-line)
("C-l" . ivy-done)
("C-d" . ivy-switch-buffer-kill)
:map ivy-reverse-i-search-map
("C-k" . ivy-previous-line)
("C-d" . ivy-reverse-i-search-kill))
:init
(ivy-mode 1)
:config
(setq ivy-use-virtual-buffers t)
(setq ivy-wrap t)
(setq ivy-count-format "(%d/%d) ")
(setq enable-recursive-minibuffers t)
;; Use different regex strategies per completion command
(push '(completion-at-point . ivy--regex-fuzzy) ivy-re-builders-alist) ;; This doesn't seem to work...
(push '(swiper . ivy--regex-ignore-order) ivy-re-builders-alist)
(push '(counsel-M-x . ivy--regex-ignore-order) ivy-re-builders-alist)
;; Set minibuffer height for different commands
(setf (alist-get 'counsel-projectile-ag ivy-height-alist) 15)
(setf (alist-get 'counsel-projectile-rg ivy-height-alist) 15)
(setf (alist-get 'swiper ivy-height-alist) 15)
(setf (alist-get 'counsel-switch-buffer ivy-height-alist) 7))
(use-package ivy-hydra
:defer t
:after hydra)
(use-package ivy-rich
:init
(ivy-rich-mode 1)
:after counsel
:config
(setq ivy-format-function #'ivy-format-function-line)
(setq ivy-rich-display-transformers-list
(plist-put ivy-rich-display-transformers-list
'ivy-switch-buffer
'(:columns
((ivy-rich-candidate (:width 40))
(ivy-rich-switch-buffer-indicators (:width 4 :face error :align right)); return the buffer indicators
(ivy-rich-switch-buffer-major-mode (:width 12 :face warning)) ; return the major mode info
(ivy-rich-switch-buffer-project (:width 15 :face success)) ; return project name using `projectile'
(ivy-rich-switch-buffer-path (:width (lambda (x) (ivy-rich-switch-buffer-shorten-path x (ivy-rich-minibuffer-width 0.3)))))) ; return file path relative to project root or `default-directory' if project is nil
:predicate
(lambda (cand)
(if-let ((buffer (get-buffer cand)))
;; Don't mess with EXWM buffers
(with-current-buffer buffer
(not (derived-mode-p 'exwm-mode)))))))))
(use-package counsel
:after ivy
:bind (("M-x" . counsel-M-x)
("C-x b" . counsel-ibuffer)
("C-x C-f" . counsel-find-file)
("C-M-j" . counsel-switch-buffer)
("C-M-l" . counsel-imenu)
:map minibuffer-local-map
("C-r" . 'counsel-minibuffer-history))
:custom
(counsel-linux-app-format-function #'counsel-linux-app-format-function-name-only)
:config
(setq ivy-initial-inputs-alist nil)) ;; Don't start searches with ^
(use-package flx ;; Improves sorting for fuzzy-matched results
:after ivy
:defer t
:init
(setq ivy-flx-limit 10000))
(use-package wgrep)
(use-package ivy-posframe
:disabled
:custom
(ivy-posframe-width 115)
(ivy-posframe-min-width 115)
(ivy-posframe-height 10)
(ivy-posframe-min-height 10)
:config
(setq ivy-posframe-display-functions-alist '((t . ivy-posframe-display-at-frame-center)))
(setq ivy-posframe-parameters '((parent-frame . nil)
(left-fringe . 8)
(right-fringe . 8)))
(ivy-posframe-mode 1))
(use-package prescient
:after counsel
:config
(prescient-persist-mode 1))
(use-package ivy-prescient
:after prescient
:config
(ivy-prescient-mode 1))
;;(dw/leader-key-def
;; "r" '(ivy-resume :which-key "ivy resume")
;; "f" '(:ignore t :which-key "files")
;; "ff" '(counsel-find-file :which-key "open file")
;; "C-f" 'counsel-find-file
;; "fr" '(counsel-recentf :which-key "recent files")
;; "fR" '(revert-buffer :which-key "revert file")
;; "fj" '(counsel-file-jump :which-key "jump to file"))
Packages config
Configuration for packages
;; Dired
(require 'dired-x)
(setq dired-omit-files "^\\...+$")
(add-hook 'dired-mode-hook (lambda () (dired-omit-mode 1)))
(add-hook 'dired-mode-hook 'auto-revert-mode)
(setq global-auto-revert-non-file-buffers t)
(setq auto-revert-verbose nil)
;; Elpher
(advice-add 'eww-browse-url :around 'elpher:eww-browse-url)
;; eww
(defun elpher:eww-browse-url (original url &optional new-window)
"Handle gemini links."
(cond ((string-match-p "\\`\\(gemini\\|gopher\\)://" url)
(require 'elpher)
(elpher-go url))
(t (funcall original url new-window))))
;;; Eshell
(setq eshell-prompt-regexp "^[^αλ\n]*[αλ] ")
(setq eshell-prompt-function
(lambda nil
(concat
(if (string= (eshell/pwd) (getenv "HOME"))
(propertize "~" 'face `(:foreground "#99CCFF"))
(replace-regexp-in-string
(getenv "HOME")
(propertize "~" 'face `(:foreground "#99CCFF"))
(propertize (eshell/pwd) 'face `(:foreground "#99CCFF"))))
(if (= (user-uid) 0)
(propertize " α " 'face `(:foreground "#FF6666"))
(propertize " λ " 'face `(:foreground "#A6E22E"))))))
(setq eshell-highlight-prompt nil)
(require 'emms-setup)
(emms-all)
(emms-default-players)
(setq emms-source-file-default-directory "~/songs/")
(setq emms-info-asynchronously nil)
(setq emms-playlist-buffer-name "*Music*")
;; ERC
;;(erc :server "irc.freenode.net" :port 6667 :nick "b2r1s8")
;;(setq erc-autojoin-channels-alist
;; '(("freenode.net" "#gentoo" "#gentoo-chat" "#ratpoison" "#perl" "#monero" "#emacs" "#emacs-beginners" "#emacs-offtopic" "#org-mode")))