Emacs config in org mode
Table of Contents
- Startup Performance
- π¦ Package management
- π¨ Theme
- π Terminal specific settings
- β Mode line
- π¦ Basic UX settings
- Startup screen
- Neo tree side buffer
- Fancy icons in GUI
- Transient mark mode
- Which key
- Yes or no ==> y or n
- No saving backups. We don't need them :D
- Beacon mode
- Camel Case (Make it only for prog mode)
- Electric pairs
- Hungry delete
- Sudo edit
- Rainbo delimiters
- Fancy killring
- Pretty characters mode
- Open maximised
- Escape to quit prompt
- No menu bar, tool bar, and scroll bar
- CUA mode ( for copy paste )
- Auto line number
- Move custom files outside
init.el
- Text wrapping
- π¦ Org mode
- πΆπ½ Moving around
- 𦦠Others
- πΏ Custom functions
- 𧬠lsp-mode
- π‘ To do someday
[0/7]
- π Archives
- πΎ Apply changes
Startup Performance
Reduce garbage collection frequency and print startup time on every startup.
;; 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)))
π¦ Package management
Use MELPA for package archive
Adding melpa package repository and initializint
(require 'package) (setq package-archives '(("melpa" . "https://melpa.org/packages/") ("melpa-stable" . "https://stable.melpa.org/packages/") ("elpa" . "https://elpa.gnu.org/packages/"))) (package-initialize)
Note that you'll need to run M-x package-refresh-contents
or M-x package-list-packages
to ensure that Emacs has fetched the MELPA package list before you can install packages with M-x package-install or similar. Following does that automatically
(unless package-archive-contents (package-refresh-contents))
Make sure that use-package
is loaded
This downloads use-package
package if not installed.
(unless (package-installed-p 'use-package) (package-install 'use-package)) (require 'use-package) (setq use-package-always-ensure t)
π¨ Theme
VSCode dark theme
(use-package vscode-dark-plus-theme :ensure t :config (load-theme 'vscode-dark-plus t))
Doom theme
(use-package doom-themes :ensure t :config ;; Global settings (defaults) (setq doom-themes-enable-bold t ; if nil, bold is universally disabled doom-themes-enable-italic t) ; if nil, italics is universally disabled (load-theme 'doom-tomorrow-night t) ;; Enable flashing mode-line on errors (doom-themes-visual-bell-config) ;; Enable custom neotree theme (all-the-icons must be installed!) (doom-themes-neotree-config) ;; or for treemacs users (setq doom-themes-treemacs-theme "doom-atom") ; use "doom-colors" for less minimal icon theme (doom-themes-treemacs-config) ;; Corrects (and improves) org-mode's native fontification. (doom-themes-org-config))
Zenburn theme
(add-to-list 'custom-theme-load-path "~/.emacs.d/themes/") (load-theme 'zenburn-theme t)
π Terminal specific settings
No background in terminal mode
Do not use theme background in terminal mode So we can use classic terminal view
;; No background when in terminal mode (to use default terminal background ) (defun on-after-init () (unless (display-graphic-p (selected-frame)) (set-face-background 'default "unspecified-bg" (selected-frame)))) (add-hook 'window-setup-hook 'on-after-init)
Enable Xterm-mouse-mode
(defun enable-xterm-mouse-mode/rambo () (unless (display-graphic-p (selected-frame)) (xterm-mouse-mode t))) (add-hook 'window-setup-hook 'enable-xterm-mouse-mode/rambo)
β Mode line
Doom modeline
Description
(use-package doom-modeline :ensure t :hook (after-init . doom-modeline-mode))
π¦ Basic UX settings
Startup screen
Startup do not include help page
;; Disable the splash screen (to enable it agin, replace the t with 0) (setq inhibit-splash-screen 0)
Neo tree side buffer
Using neotree to show current dir (Don't know how to use dired) First config command adds neotree to startup hook so that it loads on startup Second config command adds multiline mode to neotree so that long file names are shown by textwrap
(use-package neotree :ensure t :config (add-hook 'emacs-startup-hook 'neotree) (add-hook 'neotree-mode-hook 'visual-line-mode))
Fancy icons in GUI
Display fancy icons when in gui
(when (display-graphic-p) (require 'all-the-icons))
Transient mark mode
Don't know what it is
(transient-mark-mode 1)
Which key
(use-package which-key :ensure t :init (which-key-mode) :config (setq which-key-idle-delay 0.7))
Yes or no ==> y or n
Instead of typing full yes or no, we just write y or n. Save some time for your girl.
(defalias 'yes-or-no-p 'y-or-n-p)
No saving backups. We don't need them :D
(setq make-backup-files nil) (setq auto-save-default nil)
Beacon mode
(use-package beacon :ensure t :init (beacon-mode 1))
Camel Case (Make it only for prog mode)
(global-subword-mode 1)
Electric pairs
Closing matching brackets and quotes.
(setq electric-pair-pairs '( (?\( . ?\)) (?\[ . ?\]) (?\" . ?\") (?\{ . ?\}) )) (add-hook prog-mode-hook electric-pair-mode)
Hungry delete
To remove all lagging spaces all at once
(use-package hungry-delete :ensure t :config (global-hungry-delete-mode))
Sudo edit
Do I really need it?
(use-package sudo-edit :ensure t :bind ("s-e" . sudo-edit))
Rainbo delimiters
Only for prog mode?
(use-package rainbow-delimiters :ensure t :hook ((prog-mode . rainbow-delimiters-mode))) ; (org-mode . rainbow-delimiters-mode)))
Fancy killring
(use-package popup-kill-ring :ensure t :bind ("M-y" . popup-kill-ring))
Pretty characters mode
(when window-system (use-package pretty-mode :ensure t :config (global-pretty-mode 1)))
Open maximised
(add-to-list 'initial-frame-alist '(fullscreen . maximized)) (add-to-list 'default-frame-alist '(fullscreen . fullheight))
Escape to quit prompt
Press ESC
to quit the prompt
(global-set-key (kbd "<escape>") 'keyboard-escape-quit)
No menu bar, tool bar, and scroll bar
Removing tool bar on top. Let's be honest, who uses it. …
(tool-bar-mode -1) (menu-bar-mode -1) (scroll-bar-mode -1)
CUA mode ( for copy paste )
Usual C-c C-v for copy paste
;;; Auto CUA mode (cua-mode t) (setq cua-auto-tabify-rectangles nil) ;; Don't tabify after rectangle commands (transient-mark-mode 1) ;; No region when it is not highlighted (setq cua-keep-region-after-copy t) ;; Standard Windows behaviour
Auto line number
To always have line numbers on the side
(column-number-mode 1) (line-number-mode 1) (global-display-line-numbers-mode t) ;; Disable line numbers for some modes (dolist (mode '(term-mode-hook eshell-mode-hook neotree-mode-hook)) (add-hook mode (lambda () (display-line-numbers-mode 0))))
Showing relative line numbers
(setq display-line-numbers-type 'relative)
Move custom files outside init.el
Move all custom-*
stuff into custom.config.el
. Do not put them in init.el
.
(setq custom-file "~/.emacs.d/custom.conf.el") (load-file custom-file)
Text wrapping
Turn on visual-line-moe for text and org files. This wraps words by word boundaries.
(add-hook 'text-mode-hook 'visual-line-mode) (add-hook 'org-mode 'visual-line-mode)
π¦ Org mode
Pin Org mode
(use-package org :pin elpa)
Capture
Location where all captured notes will go. All the org roam files are also in the same folder
(setq org-default-notes-file "~/notes/inbox.org")
Agenda
(setq org-agenda-files '("~/notes/"))
Org bable
Org bable load languages
(org-babel-do-load-languages 'org-babel-load-languages '( (python . t) (shell . t) (js . t) ))
Org bable no confirmation for following languages
(defun my-org-confirm-babel-evaluate (lang body) (not (member lang '("python" )))) (setq org-confirm-babel-evaluate 'my-org-confirm-babel-evaluate)
- Language specific commands
Python command
(setq org-babel-python-command "python3")
- Org html export, preserve indentation in src blocks
(setq ;org-edit-src-content-indentation 0 ;org-src-tab-acts-natively t org-src-preserve-indentation t)
Org todo->done log time stamp
Log a timestamp when a TODO is changed to DONE state
(setq org-log-done 'time)
And log it to a drawer
(setq org-log-into-drawer t)
Org Bullets
(use-package org-bullets :after org :hook (org-mode . org-bullets-mode)) ; :custom (org-bullet-list '("" "" "" "" )) ; :config ; (add-hook 'org-mode-hook (lambda () (org-bullets-mode)))
Elipsis
The end of the heading character that will show that the heading is folded
(setq org-ellipsis " ⤵")
Other interesting characters are βΌ, β΄, β¬, β€·, and β±
Leading stars and indentation
(setq org-startup-indented t org-hide-leading-stars t)
Hide emphasis markers
Hide the code
, italics and bold u+nderline verbatim strike-through
(setq org-hide-emphasis-markers t)
Pretty symbols
Show pretty symbols like λ instead of \ lambda
(setq org-pretty-entities t)
Custom faces for different headline level
These are having some issues with toto font size being too small so check it out
(custom-theme-set-faces 'user `(org-level-4 ((t ( :height 1.1 )))) `(org-level-3 ((t ( :height 1 )))) `(org-level-2 ((t ( :height 1.1 )))) `(org-level-1 ((t ( :height 1.25 )))) `(org-document-title ((t ( :height 1.5 :underline nil)))))
(dolist (face '((org-level-1 . 1.3) (org-level-2 . 1.1) (org-level-3 . 1.05) (org-level-4 . 1.0) (org-level-5 . 1.1) (org-level-6 . 1.1) (org-level-7 . 1.1) (org-level-8 . 1.1))) (set-face-attribute (car face) nil :weight 'regular :height (cdr face)))
Variable pitch mode ? Ye kya hai re bava?
;(add-hook 'org-mode-hook 'variable-pitch-mode)
Snippets
(add-to-list 'org-structure-template-alist '("el" "#+BEGIN_SRC emacs-lisp\n?\n#+END_SRC")) (add-to-list 'org-structure-template-alist '("py" "#+BEGIN_SRC python\n?\n#+END_SRC")) (add-to-list 'org-structure-template-alist '("sh" "#+BEGIN_SRC shell\n?\n#+END_SRC")) (add-to-list 'org-structure-template-alist '("js" "#+BEGIN_SRC js\n?\n#+END_SRC")) (add-to-list 'org-structure-template-alist '("html" "#+BEGIN_SRC html\n?\n#+END_SRC")) (add-to-list 'org-structure-template-alist '("css" "#+BEGIN_SRC css\n?\n#+END_SRC"))
Org tempo can also be used.
(require 'org-tempo)
Gen config
Src edit window no split
Do not split while editing src
with C-c '
(setq org-src-window-setup 'current-window)
Emoji in org buffer
To make org documents more beautiful, add support for emoji with emojify package.
(use-package emojify :hook (org-mode . emojify-mode) :commands emojify-mode)
Org-roam
(use-package org-roam :ensure t :custom (org-roam-directory "~/notes") :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)) :config (org-roam-setup))
πΆπ½ Moving around
Ido
I do this and I do that
C-x C-f
for using IDO to find file
(setq ido-enable-flex-matching nil) (setq ido-create-new-buffer 'always) (setq ido-everywhere t) (ido-mode 1)
For simply switching buffer
(global-set-key (kbd "C-x b") 'ido-switch-buffer)
Verticle Ido
Seems nice. But this depends on Ido, so keep the Ido section
(use-package ido-vertical-mode :ensure t :init (ido-vertical-mode 1))
Ibuffer
To enter Ibuffer (gives a bit detailed view)
(global-set-key (kbd "C-x C-b") 'ibuffer)
Smex
For easy M-x
(use-package smex :ensure t :init (smex-initialize) :bind ("M-x" . smex))
Ace jump mode
To jump around buffer/windows
(use-package ace-jump-mode :ensure t :bind ("M-s" . 'ace-jump-char-mode) ("C-x o" . 'ace-window))
Split window improvement
This change willnot just split window but also follow to the new window.
(defun split-and-follow-horizontally () (interactive) (split-window-below) (balance-windows) (other-window 1)) (global-set-key (kbd "C-x 2") 'split-and-follow-horizontally) (defun split-and-follow-vertically () (interactive) (split-window-right) (balance-windows) (other-window 1)) (global-set-key (kbd "C-x 3") 'split-and-follow-vertically)
Swiper for search
(use-package swiper :ensure t :bind ("C-s" . swiper))
Ivy
(use-package ivy :diminish :bind (("C-x b" . ivy-switch-buffer) :map ivy-minibuffer-map ("TAB" . 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)) :config (ivy-mode 1))
Counsel for minibuffer help comes with ivy
(use-package counsel :ensure t :bind (("M-x" . counsel-M-x) ("C-x f" . counsel-find-file) :map minibuffer-local-map ("C-r" . 'counsel-minibuffer-history)) :config (setq ivy-initial-inputs-alist nil) ;Removes initial ^ )
Ivy rich
Some helpful transformations for Ivy
and Counsel
(use-package ivy-rich :init (ivy-rich-mode 1) :config (setq ivy-format-function #'ivy-format-function-line))
Helpful
(use-package helpful :custom (counsel-describe-function-function #'helpful-callable) (counsel-describe-variable-function #'helpful-variable) :bind ([remap describe-function] . counsel-describe-function) ([remap describe-symbol] . helpful-symbol) ([remap describe-variable] . counsel-describe-variable) ([remap describe-command] . helpful-command) ([remap describe-key] . helpful-key))
𦦠Others
Rainbow
For generative work (shows colors with that color background)
(use-package rainbow-mode :ensure t :init (add-hook prog-mode-hook 'rainbow-mode))
Yasnippet
For inserting standard snippets and making
(use-package yasnippet :ensure t :config (use-package yasnippet-snippets :ensure t) (yas-reload-all) :hook (prog-mode . yas-minor-mode))
Magit
(use-package magit)
HTMLIZE
(use-package htmlize) ; (use-package ox-publish) (setq org-html-htmlize-output-type 'css ;; Instead of using inline css for each element org-html-doctype "html5" org-html-html5-fancy nil)
Git gutter
(use-package git-gutter ;:straight git-gutter-fringe :diminish :hook ((text-mode . git-gutter-mode) (prog-mode . git-gutter-mode)) :config (setq git-gutter:update-interval 2) ;; These characters are used in terminal mode (setq git-gutter:modified-sign "≡") (setq git-gutter:added-sign "≡") (setq git-gutter:deleted-sign "≡") (set-face-foreground 'git-gutter:added "LightGreen") (set-face-foreground 'git-gutter:modified "LightGoldenrod") (set-face-foreground 'git-gutter:deleted "LightCoral")) (use-package git-gutter-fringe :config (define-fringe-bitmap 'git-gutter-fr:added [224] nil nil '(center repeated)) (define-fringe-bitmap 'git-gutter-fr:modified [224] nil nil '(center repeated)) (define-fringe-bitmap 'git-gutter-fr:deleted [128 192 224 240] nil nil 'bottom))
πΏ Custom functions
Kill word improvement
(defun kill-whole-word () (interactive) (backward-word) (kill-word 1)) (global-set-key (kbd "M-d") 'kill-whole-word)
𧬠lsp-mode
This mode helps design IDE for different programming interfaces.
(defun rambo/lsp-mode-setup () (setq lsp-headerline-breadcrumb-segments '(path-up-to-project file symbols)) (lsp-headerline-breadcrumb-mode)) (use-package lsp-mode :commands (lsp lsp-deferred) :hook (lsp-mode . rambo/lsp-mode-setup) :init (setq lsp-keymap-prefix "C-c l") :config (lsp-enable-which-key-integration t) )
Company mode
(use-package company :after lsp-mode :hook (lsp-mode . company-mode) :bind (:map company-active-map ("<tab>" . company-indent-or-complete-common)) (:map lsp-mode-map ("<tab>" . company-indent-or-complete-common)) :custom (company-minimum-prefix-length 1) (company-idle-delay 0.0))
(use-package company-box :hook (company-mode . company-box-mode))
lsp-ui
(use-package lsp-ui :hook (lsp-mode . lsp-ui-mode) ;:custom ;(lsp-ui-doc-position 'bottom) )
lsp-ivy
(use-package lsp-ivy)
Python lsp
(use-package python-mode :ensure t :hook (python-mode . lsp-deferred) :custom (python-shell-interpreter "python3"))
π‘ To do someday [0/7]
Geleral.el For managing keybindings
π Archives
The configuration wihich is not in use anymore
Ivy switch buffer improvement
(use-package ivy :diminish :bind (("C-x b" . ivy-switch-buffer) :map ivy-minibuffer-map ("TAB" . 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)) :config (ivy-mode 1))
Counsel with helpful
(use-package counsel :ensure t :bind ("M-x" . counsel-M-x)) :config ((setq counsel-describe-function-function #'helpful-callable) (setq counsel-describe-variable-function #'helpful-variable)))
πΎ Apply changes
Copy the file to the required location
Go to the code below and press C-c
and then confirm yes
cp config.org ~/.emacs.d/config.org
And reload the emacs config