Verified Commit a3c6b8b3 authored by peacerebel's avatar peacerebel
Browse files

Add emacs config

;;; config.el --- Emacs configurations
;;; Code:
;; Configs
(require 'use-package-ensure)
(setq use-package-always-ensure t)
;; Load sensible defaults
;; Thanks, HRS.
(load-file "~/.emacs.d/sensible-defaults.el")
;; Set personal info
(setq user-full-name "Bipin"
user-mail-address "")
;; Disable toolbar, menu and scrollbar
(tool-bar-mode 0)
(menu-bar-mode 0)
(scroll-bar-mode -1)
;; Save location in file
(save-place-mode t)
;; Indent with space
(setq-default indent-tabs-mode nil
tab-width 2)
;; Disable scrollbar in minibuffer
(set-window-scroll-bars (minibuffer-window) nil nil)
;; Enable pretty symbols globally
(global-prettify-symbols-mode t)
;; Open emacs config
(defun pr/visit-emacs-config ()
"Opens file with Emacs configurations."
(find-file "~/.emacs.d/config.el"))
(global-set-key (kbd "C-c e") 'pr/visit-emacs-config)
;; Utils
(defun pr/append-to-path (path)
"Add a path both to the $PATH variable and to Emacs' `exec-path'."
(setenv "PATH" (concat (getenv "PATH") ":" path))
(add-to-list 'exec-path path))
(defun pr/add-auto-mode (mode &rest patterns)
"Add entries to `auto-mode-alist' to use `MODE' for all given file `PATTERNS'."
(dolist (pattern patterns)
(add-to-list 'auto-mode-alist (cons pattern mode))))
;; Move around open windows
(global-set-key (kbd "M-o") 'other-window)
(use-package windmove
(global-set-key (kbd "s-[") 'windmove-left) ;; Super + [ go to left window
(global-set-key (kbd "s-]") 'windmove-right) ;; Super + ] go to right window
(global-set-key (kbd "s-{") 'windmove-up) ;; Super + Shift + { go to upper window
(global-set-key (kbd "s-}") 'windmove-down)) ;; Super + Shift + } go to down window
;; Move between buffers
(global-set-key (kbd "s-<") 'previous-buffer)
(global-set-key (kbd "s->") 'next-buffer)
;; Show line number
(require 'display-line-numbers)
(defcustom display-line-numbers-exempt-modes '(vterm-mode eshell-mode shell-mode term-mode ansi-term-mode)
"Major modes on which to disable the linum mode, exempts them from global requirement."
:group 'display-line-numbers
:type 'list
:version "green")
(defun display-line-numbers--turn-on ()
"Turn on line numbers but excempting certain majore modes defined in `display-line-numbers-exempt-modes'."
(if (and
(not (member major-mode display-line-numbers-exempt-modes))
(not (minibufferp)))
;; Keystroke suggestion
(use-package which-key
(setq which-key-popup-type 'minibuffer)
(use-package cyberpunk-theme)
;; Font settings
(defvar pr/default-font "DejaVu Sans Mono")
(defvar pr/default-font-size 7)
(defvar pr/current-font-size pr/default-font-size)
(defvar pr/font-change-increment 1.0)
(defun pr/font-code ()
"Return a string representing the current font (like \"Inconsolata-14\")."
(concat pr/default-font "-" (number-to-string pr/current-font-size)))
(defun pr/set-font-size ()
"Set the font to `pr/default-font' at `pr/current-font-size'.
Set that for the current frame, and also make it the default for
other, future frames."
(let ((font-code (pr/font-code)))
(if (assoc 'font default-frame-alist)
(setcdr (assoc 'font default-frame-alist) font-code)
(add-to-list 'default-frame-alist (cons 'font font-code)))
(set-frame-font font-code)))
(defun pr/reset-font-size ()
"Change font size back to `pr/default-font-size'."
(setq pr/current-font-size pr/default-font-size)
;; Highlight current line
;; Disable visual/audio bell
(setq ring-bell-function 'ignore)
;; Scroll only as far as the buffer point
(setq scroll-conservatively 100)
;; Regular undo-redo.
(use-package undo-fu
(global-unset-key (kbd "C-z"))
(global-set-key (kbd "C-z") 'undo-fu-only-undo)
(global-set-key (kbd "C-S-z") 'undo-fu-only-redo))
;; Upcase word and region using the same keys.
(global-set-key (kbd "M-u") 'upcase-dwim)
(global-set-key (kbd "M-l") 'downcase-dwim)
;; Setup windows to be in golden ratio
(use-package zoom
'(zoom-mode t)
'(zoom-size '(0.618 . 0.618))))
;; modline
(use-package doom-modeline
:ensure t
(setq doom-modeline-height 20)
(setq doom-modeline-bar-width 3)
(setq doom-modeline-project-detection 'project)
(setq doom-modeline-buffer-file-name-style 'auto)
(setq doom-modeline-icon (display-graphic-p))
(setq doom-modeline-major-mode-icon t)
(setq doom-modeline-major-mode-color-icon t)
(setq doom-modeline-buffer-state-icon t)
(setq doom-modeline-buffer-modification-icon t)
(setq doom-modeline-minor-modes nil)
(setq doom-modeline-enable-word-count nil)
(setq doom-modeline-buffer-encoding t)
(setq doom-modeline-indent-info nil)
(setq doom-modeline-checker-simple-format t)
(setq doom-modeline-workspace-name t)
(setq doom-modeline-lsp t)
(setq doom-modeline-modal-icon t)
(doom-modeline-mode 1))
;; minor mode
(use-package minions
(minions-mode t))
;; Use deadgrep
(use-package deadgrep
(global-set-key (kbd "<f5>") #'deadgrep))
;; Dumb-jump
(use-package dumb-jump
(setq dumb-jump-force-searcher 'rg)
(add-hook 'xref-backend-functions #'dumb-jump-xref-activate))
;; Company-mode
(use-package company
(setq company-frontends
company-require-match 'never)
(add-hook 'after-init-hook 'global-company-mode)
(eval-after-load 'company
(lambda ()
:background (face-attribute 'company-preview-common :background)))))
;; Company documentation view
(use-package company-quickhelp
("M-h" . company-quickhelp-manual-begin)
company-quickhelp-delay nil
company-quickhelp-color-foreground "grey"
company-quickhelp-color-background "black"
company-quickhelp-use-propertized-text t)
(company-quickhelp-mode t))
;; Language servers
(use-package lsp-mode
(setq gc-cons-threshold 100000000) ;; Why? Visit:
(setq lsp-completion-provider :capf)
:hook ((js-mode . lsp))
:commands lsp)
(use-package lsp-ui :commands lsp-ui-mode)
(use-package lsp-ivy :commands lsp-ivy-workspace-symbol)
;; Counsel
(use-package counsel
("M-x" . 'counsel-M-x)
("C-s" . 'swiper)
("C-x C-f" . 'counsel-find-file)
("<f1> f" . 'counsel-describe-function)
("<f1> v" . 'counsel-describe-variable)
("<f1> l" . 'counsel-find-library)
("<f1> i" . 'counsel-info-lookup-symbol)
("C-c k" . 'counsel-rg)
(ivy-mode 1)
ivy-use-virtual-buffers t
ivy-count-format "(%d/%d) "
ivy-initial-inputs-alist nil
ivy-re-builders-alist '((swiper . ivy--regex-plus)
(t . ivy--regex-fuzzy)
(counsel-rg . ivy--regex-plus))))
;; Projectile
(use-package projectile
:ensure t
("s-p" . projectile-command-map)
(setq projectile-require-project-root t)
(setq projectile-completion-system 'ivy)
(projectile-mode t))
;; Fuzzy match
(use-package flx)
;; Better M-x
(use-package smex)
;; Electric pair
(electric-pair-mode t)
;; Engine mode - Editor to browser search
(use-package engine-mode
(engine-mode t))
(defengine duckduckgo
:keybinding "d")
;; Flycheck
(use-package flycheck
:ensure t
:init (global-flycheck-mode))
(use-package flycheck-color-mode-line
(flycheck-mode . flycheck-color-mode-line-mode))
;; Language specific setup
;; Lua
(use-package lua-mode
(autoload 'lua-mode "lua-mode" "Lua editing mode." t)
(add-to-list 'auto-mode-alist '("\\.lua$" . lua-mode))
(add-to-list 'interpreter-mode-alist '("lua" . lua-mode)))
;; Rust
;; Typescript
(use-package typescript-mode
(add-to-list 'auto-mode-alist '("\\.ts$" . typescript-mode)))
(use-package tide
(setq company-tooltip-align-annotations t)
(add-hook 'before-save-hook 'tide-format-before-save)
(add-hook 'typescript-mode-hook #'setup-tide-mode)
(defun setup-tide-mode ()
(flycheck-mode +1)
(setq flycheck-check-syntax-automatically '(save mode-enabled))
(eldoc-mode +1)
(tide-hl-identifier-mode +1)
(company-mode +1)))
;;; config.el ends here
;; Configure package.el to include MELPA.
(require 'package)
(add-to-list 'package-archives '("gnu" . ""))
(add-to-list 'package-archives '("melpa" . ""))
(add-to-list 'package-archives '("org" . ""))
(setq gnutls-algorithm-priority "NORMAL:-VERS-TLS1.3")
;; Ensure that use-package is installed.
;; If use-package isn't already installed, it's extremely likely that this is a
;; fresh installation! So we'll want to update the package repository and
;; install use-package before loading the literate configuration.
(when (not (package-installed-p 'use-package))
(package-install 'use-package))
(load-file "~/.emacs.d/config.el")
;; Save custom setting in ~/.emacs.d/custom.el
(setq custom-file "~/.emacs.d/custom.el")
(load custom-file)
;;; init.el ends here
;;; sensible-defaults.el --- Reasonable settings for getting started.
;; Author: Harry R. Schwartz <>
;; Version: 1.0.0
;; URL:
;; This file is NOT part of GNU Emacs.
;;; License:
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <>.
;;; Code:
;; Utility functions:
(defun sensible-defaults/comment-or-uncomment-region-or-line ()
"Comments or uncomments the region or the current line if
there's no active region."
(let (beg end)
(if (region-active-p)
(setq beg (region-beginning) end (region-end))
(setq beg (line-beginning-position) end (line-end-position)))
(comment-or-uncomment-region beg end)))
(defun sensible-defaults/reset-text-size ()
(text-scale-set 0))
;; Settings:
(defun sensible-defaults/open-files-from-home-directory ()
"When opening a file, start searching at the user's home
(setq default-directory "~/"))
(defun sensible-defaults/increase-gc-threshold ()
"Allow 20MB of memory (instead of 0.76MB) before calling
garbage collection. This means GC runs less often, which speeds
up some operations."
(setq gc-cons-threshold 20000000))
(defun sensible-defaults/delete-trailing-whitespace ()
"Call DELETE-TRAILING-WHITESPACE every time a buffer is saved."
(add-hook 'before-save-hook 'delete-trailing-whitespace))
(defun sensible-defaults/treat-camelcase-as-separate-words ()
"Treat CamelCaseSubWords as separate words in every programming
(add-hook 'prog-mode-hook 'subword-mode))
(defun sensible-defaults/automatically-follow-symlinks ()
"When opening a file, always follow symlinks."
(setq vc-follow-symlinks t))
(defun sensible-defaults/make-scripts-executable ()
"When saving a file that starts with `#!', make it executable."
(add-hook 'after-save-hook
(defun sensible-defaults/single-space-after-periods ()
"Don't assume that sentences should have two spaces after
periods. This ain't a typewriter."
(setq sentence-end-double-space nil))
(defun sensible-defaults/offer-to-create-parent-directories-on-save ()
"When saving a file in a directory that doesn't exist, offer
to (recursively) create the file's parent directories."
(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)))))))
(defun sensible-defaults/apply-changes-to-highlighted-region ()
"Turn on transient-mark-mode."
(transient-mark-mode t))
(defun sensible-defaults/overwrite-selected-text ()
"If some text is selected, and you type some text, delete the
selected text and start inserting your typed text."
(delete-selection-mode t))
(defun sensible-defaults/ensure-that-files-end-with-newline ()
"If you save a file that doesn't end with a newline,
automatically append one."
(setq require-final-newline t))
(defun sensible-defaults/confirm-closing-emacs ()
"Ask if you're sure that you want to close Emacs."
(setq confirm-kill-emacs 'y-or-n-p))
(defun sensible-defaults/quiet-startup ()
"Don't present the usual startup message, and clear the scratch
(setq inhibit-startup-message t)
(setq initial-scratch-message nil))
(defun sensible-defaults/make-dired-file-sizes-human-readable ()
"Add file sizes in human-readable units (KB, MB, etc) to dired
(setq-default dired-listing-switches "-alh"))
(defun sensible-defaults/shorten-yes-or-no ()
"Don't ask `yes/no?', ask `y/n?'."
(fset 'yes-or-no-p 'y-or-n-p))
(defun sensible-defaults/always-highlight-code ()
"Turn on syntax highlighting whenever possible."
(global-font-lock-mode t))
(defun sensible-defaults/refresh-buffers-when-files-change ()
"When something changes a file, automatically refresh the
buffer containing that file so they can't get out of sync."
(global-auto-revert-mode t))
(defun sensible-defaults/show-matching-parens ()
"Visually indicate matching pairs of parentheses."
(show-paren-mode t)
(setq show-paren-delay 0.0))
(defun sensible-defaults/flash-screen-instead-of-ringing-bell ()
"When you perform a problematic operation, flash the screen
instead of ringing the terminal bell."
(setq visible-bell t))
(defun sensible-defaults/set-default-line-length-to (line-length)
"Set the default line length to LINE-LENGTH."
(setq-default fill-column line-length))
(defun sensible-defaults/open-clicked-files-in-same-frame-on-mac ()
"When you double-click on a file in the Mac Finder open it as a
buffer in the existing Emacs frame, rather than creating a new
frame just for that file."
(setq ns-pop-up-frames nil))
(defun sensible-defaults/yank-to-point-on-mouse-click ()
"When middle-clicking the mouse to yank from the clipboard,
insert the text where point is, not where the mouse cursor is."
(setq mouse-yank-at-point t))
(defun sensible-defaults/use-all-settings ()
"Use all of the sensible-defaults settings."
(sensible-defaults/set-default-line-length-to 80)
;; Keybindings:
(defun sensible-defaults/bind-commenting-and-uncommenting ()
"Comment or uncomment a region by hitting M-;."
(global-set-key (kbd "M-;")
(defun sensible-defaults/bind-home-and-end-keys ()
"Make <home> and <end> move point to the beginning and end of
the line, respectively."
(global-set-key (kbd "<home>") 'move-beginning-of-line)
(global-set-key (kbd "<end>") 'move-end-of-line))
(defun sensible-defaults/bind-keys-to-change-text-size ()
"Bind C-+ and C-- to increase and decrease text size,
(define-key global-map (kbd "C-)") 'sensible-defaults/reset-text-size)
(define-key global-map (kbd "C-+") 'text-scale-increase)
(define-key global-map (kbd "C-=") 'text-scale-increase)
(define-key global-map (kbd "C-_") 'text-scale-decrease)
(define-key global-map (kbd "C--") 'text-scale-decrease))
(defun sensible-defaults/use-all-keybindings ()
"Use all of the sensible-defaults keybindings."
;; Non-default settings:
(defun sensible-defaults/backup-to-temp-directory ()
"Store backups and auto-saved files in
TEMPORARY-FILE-DIRECTORY (which defaults to /tmp on Unix),
instead of in the same directory as the file. This means we're
still making backups, but not where they'll get in the way.
WARNING: on most Unix-like systems /tmp is volatile, in-memory
storage, so your backups won't survive if your computer crashes!
If you're not willing to take this risk, you shouldn't enable
this setting."
(setq backup-directory-alist
`((".*" . ,temporary-file-directory)))
(setq auto-save-file-name-transforms
`((".*" ,temporary-file-directory t))))
;;; sensible-defaults.el ends here
# My personal configuration files for application I use.
I use bare git repository to manage these files. (
Contains configs for:
1. Emacs
# Refs
1. sensible-defaults:
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment