Skip to content

lucamuscat/Emacs-Config

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

98 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

My Emacs Config :)

Hi there! As you might have guessed, this is my EMACS config which I use pretty often. There are some basic plugins in here which in my opinion everyone should be using. Hope that you could learn something by going through my config.

Installation

Quick Installation

Windows

Copy the following script into your command line. Please make sure that you have git installed from before hand.

cd %appdata%
git clone https://github.com/lucamuscat/Emacs-Config.git
rename Emacs-Config .emacs.d
cd .emacs.d
rename "./.emacs" "../.emacs"

Once you paste this into your cmd, do M-x eval-expression and run the following

(require 'package)
(setq package-enable-at-startup nil)

;;; remove SC if you are not using sunrise commander and org if you like outdated packages
(setq package-archives '(("ELPA"  . "http://tromey.com/elpa/")
			 ("gnu"   . "http://elpa.gnu.org/packages/")
			 ("melpa" . "https://melpa.org/packages/")
			 ("elpa"  . "https://elpa.gnu.org/packages/")
			 ))
(package-initialize)

Then call M-x package-install use-package. After that, go into the .emacs.d file and run eval-buffer.

Initialization

GC Thresholds

Increasing gc-cons-threshold to a very high number to will decrease the load and compile time. This will later be lowered back down to a more sane value to prevent complications. (taken from J. Wiegley’s init.el)

(defconst emacs-start-time (current-time))

(defvar file-name-handler-alist-old file-name-handler-alist)

(setq package-enable-at-startup nil
      file-name-handler-alist nil
      message-log-max 16384
      gc-cons-threshold 402653184
      gc-cons-percentage 0.6
      auto-window-vscroll nil)

(add-hook 'after-init-hook
          `(lambda ()
             (setq file-name-handler-alist file-name-handler-alist-old
                   gc-cons-threshold 800000
                   gc-cons-percentage 0.1)
             (garbage-collect)) t)

Preventing the scratch buffer from triggering prog mode

By default, the scratch buffer has a prog-mode major mode, this means that any package loaded in with the prog-mode-hook will be called unnecessarily. Making the prog-mode-hook counter intuitive to begin with.

(setq initial-major-mode (quote fundamental-mode))

Benchmark

(use-package benchmark-init
  :ensure t
  :init(benchmark-init/activate))

Delete Selection when typing

(delete-selection-mode 1)

Startup optimizations

Taken from MatthewZMD

Disable package-enable-at-startup

(setq package-enable-at-startup nil)

Disable site-run-file

(setq site-run-file nil)

Theme

(use-package doom-themes
	:diminish
	:ensure t
	:config (load-theme 'doom-city-lights t)
)

Interface Settings

These are built-in UI enhancements.

Looks

Removing startup screen

The start up screen will be replaced with the dashboard package.

(setq inhibit-splash-screen t
initial-buffer-choice  nil
)

Display Line Numbers

(add-hook 'prog-mode-hook 'display-line-numbers-mode)

Disable menus and scroll bars

Replace the -1 with a 1 keep these features.

(menu-bar-mode -1)
(toggle-scroll-bar -1)
(tool-bar-mode -1)

Disable bell

I find this feature annoying, feel free to remove this line if you like the sound of computerized bells

(setq ring-bell-function 'ignore)

Clock

A clock which shows in the mode line.

(setq display-time-24hr-format t)
(setq display-time-format "%d %B %Y - %H:%M")
(display-time-mode 1)

Dashboard

(use-package dashboard
:ensure t
:config(setq dashboard-startup-banner "~/.emacs.d/images/KEC_Dark_BK.png")
(setq dashboard-banner-logo-title "Don't do the rain dance if you can't handle the thunder - Ken M")
(setq dashboard-items '((recents  . 3)
                        (bookmarks . 3)
                        (projects . 5)
                        (agenda . 0)
                        (registers . 0)))
(dashboard-setup-startup-hook)
)

Beacon

Helps user find the line which they are editing when they swap buffer.

(use-package beacon
	:ensure t
	:config
		(beacon-mode 1)
)

Customize frame name

(setq-default
frame-title-format '("Lucinda?"))

Customize font-family and font size

(set-frame-font "Consolas 14" nil t)

Treemacs

(use-package treemacs
	:ensure t
	:diminish
	:bind*("C-<tab>" . treemacs)
	:custom
	(treemacs-indentation 2)
	(treemacs-eldoc-display t)
	(treemacs-show-hidden-files t)
	(treemacs-width 35)
	(treemacs-display-in-side-window nil)
	(treemacs-pre-file-insert-predicates)
)

(use-package treemacs-projectile
	:ensure t
	:diminish
	:after treemacs projectile
)

(use-package lsp-treemacs
	:ensure t
	:diminish
	:after treemacs lsp
	:config(lsp-treemacs-sync-mode 1)
)

Functionality

Awesome pair

https://github.com/manateelazycat/awesome-pair

(use-package awesome-pair
	:load-path("~/.emacs.d/elpa/")
	:hook( (org-mode prog-mode) . awesome-pair-mode)
	:bind
	("(" . awesome-pair-open-round)
	("[" . awesome-pair-open-bracket)
	("{" . awesome-pair-open-curly)
	("=" . awesome-pair-equal)
	("M-\"" . awesome-pair-wrap-double-quote)
	("M-[" . awesome-pair-wrap-bracket)
	("M-{" . awesome-pair-wrap-curly)
	("M-(" . awesome-pair-wrap-round)
	("M-)" . awesome-pair-unwrap)
)

Projectile

(use-package projectile
	:diminish
	:ensure t
	:init(projectile-mode)
	(require 'cc-mode)
	:bind("C-x r p" . projectile-switch-project)
		 ("C-x C-M-f" . projectile-find-file)
		 ("C-x C-M-s" . projectile-save-project-buffers)
	:bind(:map c-mode-base-map
		("<f1>" . projectile-compile-project))
		("<f2>" . luca/c-debug)
)

(use-package helm-projectile
	:ensure t
	:after projectile
	:bind("C-M-s" . helm-projectile-ag)
	:init(helm-projectile-on)
)

Magit

(use-package magit
	:ensure t
	:diminish
	:commands(magit-stage-file magit-status magit-commit-create)
	:bind(:map prog-mode-map
		("C-c t" . magit-stage-file)
		("C-c s" . magit-status)
		("C-c c" . magit-commit-create)
	)
)

(use-package vc
	:no-require t
	:defer t
	:commands(vc diff)
	:bind("C-c d" . vc-diff)
)

(use-package git-gutter
	:ensure t
	:diminish
	:hook (prog-mode . git-gutter-mode)
	:hook (magit-post-refresh . git-gutter:update-all-windows)
	:bind(:map prog-mode-map
		("C-c n" . git-gutter:next-hunk)
 		("C-c p" . git-gutter:previous-hunk)
)
)

UTF-8

This is very important as sometimes you might encounter some different kinds of characters in the the package list which will start throwing annoying errors.

(prefer-coding-system 'utf-8)
(set-default-coding-systems 'utf-8)
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
;; backwards compatibility as default-buffer-file-coding-system
;; is deprecated in 23.2.
(if (boundp 'buffer-file-coding-system)
	(setq-default buffer-file-coding-system 'utf-8)
	(setq default-buffer-file-coding-system 'utf-8))

;; Treat clipboard input as UTF-8 string first; compound text next, etc.
(setq x-select-request-type '(UTF8_STRING COMPOUND_TEXT TEXT STRING))

Backups

Although backups are recommended, I don’t like how they’re implemented (it litters any directory you work in).

(setq make-backup-files nil)
(setq auto-save-default nil)

Change yes/no prompts to y/n

Normally when the user is prompted to give a yes or no answer, they will have to type out the “yes” or “no” in its entirety. This option changed it to just a “y” for yes and a “n” no (I mean we’re using EMACS, might as well save all the key strokes you can ;) )

(defalias 'yes-or-no-p 'y-or-n-p)

Line wrapping

(global-visual-line-mode)

Which-key

This is a god send for beginners and novices alike. In short, this allows the user to see what key bindings they can use on the fly.

(use-package which-key
	:ensure t
	:diminish
	:config (which-key-mode)
	)

ISpell Setup

(use-package ispell
	:no-require t
	:defer t
	:bind (:map org-mode-map("C-<return>" . ispell-word))
)

Dictionary

(use-package define-word
	:diminish
	:ensure t
	:defer t
)

helm-ag

helm-ag is used to search all of the files in a project.

(use-package helm-ag
	:ensure t
	:diminish
	:commands(helm-ag)
)

Unbind certain keys

(global-unset-key "\C-z")
(global-unset-key "\C-x\C-z")
(global-unset-key "\C-x\C-c")

Fill-region

(use-package fill
	:no-require t
	:bind("<f9>" . fill-region )
)

Undo-tree

(use-package undo-tree
	:ensure t
	:commands(undo-tree-mode)
	:defer t
)

Terminal-here

(use-package terminal-here
	:ensure t
	:commands(terminal-here terminal-here-launch terminal-here-project-launch)
)

Org Mode

(use-package org
	:mode("\\.org\\'" . org-mode)
	:bind(:map org-mode-map
		("<f1>" . org-export-dispatch)
	)
	:custom
	(org-startup-with-inline-images nil)
	(org-latex-listings 'minted)
	(org-latex-packages-alist '(("" "minted")))
	(org-latex-minted-options
		'(
			("frame" "lines")
			("linenos" "")
		))
	(org-latex-pdf-process
	'("pdflatex -shell-escape -interaction=nonstopmode %f"
	"pdflatex -shell-escape -interaction=nonstopmode %f"
	))
	(org-latex-toc-command "\\tableofcontents \\clearpage")
)

;; Call load ox-latex only when exporting
(use-package ox-latex
	:no-require t
	:commands org-export-dispatch
)

(use-package helm-org-rifle
	:ensure t
	:bind(:map org-mode-map
	("M-s" . helm-org-rifle-org-directory)
)
)

(use-package ox-twbs
	:ensure t
	:defer t
)

(use-package org-wc
	:ensure t
	:commands(org-wc-display)
)

Enable python snippets

(org-babel-do-load-languages
 'org-babel-load-languages
 '((python . t)))

Programming

C# / .NET

(use-package csharp-mode
	:mode ("\\.cs\\'" . csharp-mode)
	:ensure t
	:hook(csharp-mode . (lambda ()
		(dotnet-mode 1)
		(omnisharp-mode 1)
	))
	:config(lambda()
	(eval-after-load
	'company
	'(add-to-list 'company-backends 'company-omnisharp))
)
)

(use-package dotnet
	:ensure t
	:diminish
	:commands(dotnet-mode)
)

(use-package csproj-mode
	:mode("\\.csproj\\'" . csproj-mode)
	:ensure t
	:diminish
)

(use-package omnisharp
	:ensure t
	:after csharp-mode
	:commands(omnisharp-mode)
)

Debugging `DAP-mode

(use-package dap-mode
	:ensure  t
	:diminish
	:defer t
	:commands(dap-mode)
)

Flycheck

(use-package flycheck
	:ensure t
	:diminish
	:hook(c-mode-common . (lambda ()
	(flycheck-mode)
	(flycheck-select-checker 'c/c++-gcc)
))
	:commands(flycheck-mode)
)

Company

(use-package company
	:ensure t
	:diminish
	:hook((web-mode css-mode c-mode-common csharp-mode) . company-mode)
	:custom(comany-idle-delay 0.3)
)

(use-package company-web
	:ensure t
	:diminish
	:after company
)

(use-package company-lsp
  :defer t
  :after company lsp
  :custom (company-lsp-cache-candidates 'auto)

)

(use-package company-quickhelp
	:ensure t
	:diminish
	:after company
	:hook (company-mode . company-quickhelp-mode)
)

LSP-Mode

LSP-mode helps with managing LSP’s (Language Server Protocols)

(use-package lsp-mode
	:ensure t
	:hook((c-mode-common) . lsp)
	:bind(:map c-mode-base-map
			("<f5>" . lsp-find-definition)
			("<f6>" . lsp-find-references)
			("<f7>" . lsp-find-declaration)

)
	:config(lsp-lens-mode t)
)

(use-package flycheck-clang-analyzer
  :ensure t
  :after flycheck
  :config (flycheck-clang-analyzer-setup))

(use-package lsp-ui
	:ensure t
	:after lsp-mode
	:bind(:map lsp-ui-mode-map
		("C-f" . lsp-ui-imenu)
		([remap xref-find-definitions] . lsp-ui-peek-find-definitions)
        ([remap xref-find-references] . lsp-ui-peek-find-references)
	)
	:custom
	(lsp-ui-doc-enable t)
	(lsp-ui-doc-header nil)
	(lsp-ui-doc-include-signature t)
	(lsp-ui-doc-position 'top)
	(lsp-ui-doc-border (face-foreground 'default))
	(lsp-ui-sideline-enable nil)
	(lsp-ui-sideline-ignore-duplicate t)
	(lsp-ui-sideline-show-code-actions nil)
	:diminish
	:commands lsp-ui-mode
)

Latex

(use-package latex
	:no-require t
	:hook(latex-mode . flyspell-mode)
)

(use-package latex-extra
	:ensure t
	:after latex
)

Python Mode

(use-package python
	:mode("\\.py\\'" . python-mode)
)

(use-package jedi
	:ensure t
	:commands(company-jedi)
)

(defun my/python-mode-hook ()
  (add-to-list 'company-backends 'company-jedi))

(add-hook 'python-mode-hook 'my/python-mode-hook)

(use-package blacken
	:ensure t
	:diminish
	:defer t
)

(use-package pylint
	:ensure t
	:diminish
	:defer t
)

(use-package virtualenvwrapper
	:ensure t
	:defer t
)

C Mode

(setq c-basic-offset 4)

(use-package function-args
	:ensure t
	:diminish
	:defer t
)

(defun luca/c-debug (directory)
	"Sets up debugging environment for c"
	(interactive "sFile Path:")
	(gdb (format "gdb -i=mi %s" directory ))
	(gbd-many-windows)
)



(use-package gud
	:no-require t
	:commands luca/c-debug
	:bind(:map c-mode-base-map
		("C-<f5>" . gud-break)
		("C-<f6>" . gud-step)
		("C-<f7>" . gud-next)
)
)

HTML

(use-package web-mode
	:ensure t
	:mode("\\.html\\'")
	:mode("\\.cshtml\\'")
	:config(web-mode-toggle-current-element-highlight)
	:bind(:map web-mode-map
	("C-c C-e -" . web-mode-element-contract)
	("C-c C-e +" . web-mode-element-extract)
	("C-c C-e /" . web-mode-element-close)
	("C-c C-e a" . web-mode-element-content-select)
	("C-c C-e i" . web-mode-element-insert)
	("C-c C-e w" . web-mode-element-wrap)
	("C-c C-e k" . web-mode-element-kill)
)
)

(use-package css-mode
	:ensure t
	:mode("\\.css\\'")
)

(use-package css-comb
	:ensure t
	:commands (css-comb)
)

(use-package simple-httpd
	:no-require t
	:after web-mode
	:ensure t
	:diminish
	:hook(web-mode . httpd-start)
)

(use-package impatient-mode
	:ensure t
	:after web-mode
	:hook((web-mode css-mode) . impatient-mode)
)

(use-package zencoding-mode
	:ensure t
	:diminish
	:hook(web-mode . zencoding-mode)
	:bind(:map web-mode-map("C-`" . zencoding-expand-line))
)

(use-package web-beautify
	:ensure t
	:diminish
	:defer t
)

Yasnippet setup

To create snippets, just write it out on any buffer and leave a ‘~’ right behind the placeholder. Then highlight the region and use the command aya-create. Use aya-persist-snippet to save the created snippet.

(use-package yasnippet
	:ensure t
	:diminish
	:hook(prog-mode . yas-minor-mode)
	(org-mode . yas-minor-mode)
	:bind*("C-~" . yas-insert-snippet)
	:config
	(yas-reload-all)
	(use-package yasnippet-snippets
		:ensure t
		:after yasnippet
	)
	(use-package yasnippet-classic-snippets
		:ensure t
		:after yasnippet
	)
)

(use-package auto-yasnippet
	:ensure t
	:after yasnippet
	:commands(aya-create aya-expand aya-open-line)
	:diminish
)

Smart Compile

(use-package smart-compile
	:ensure t
	:diminish
	:commands(smart-compile)
)

So-long

This helps mitigate the slowness which comes with opening large files in emacs.

(use-package so-long
	:load-path("~/.emacs.d/packages/")
	:commands global-so-long-mode
	:init(global-so-long-mode)
)

Key Bindings

Ace Window

M-o swaps window.

(use-package ace-window
	:ensure t
	:diminish
	:commands ace-window
	:bind*("M-o" . ace-window)
)

Multi Cursors

Multicursor down: C-> Multicursor up : C-<

(use-package multiple-cursors
	:ensure t
	:commands (mc/mark-next-like-this mc/mark-previous-like-this)
	:diminish
	:bind
	("C->" . mc/mark-next-like-this)
	("C-<" . mc/mark-previous-like-this)
)

(use-package ace-mc
	:ensure t
	:commands (ace-mc-add-multiple-cursors)
	:diminish
	:bind
	("C-M->" . ace-mc-add-multiple-cursors)
	("C-M-<" . ace-mc-add-multiple-cursors)
)

Resizing Window

S-C-<left>: shrink horizontally. S-C-<right>: enlarge horizontally. S-C-<down>: shrink vertically. S-C-<up>: enlarge vertically.

(global-set-key (kbd "S-C-<left>") 'shrink-window-horizontally)
(global-set-key (kbd "S-C-<right>") 'enlarge-window-horizontally)
(global-set-key (kbd "S-C-<down>") 'shrink-window)
(global-set-key (kbd "S-C-<up>") 'enlarge-window)

Helm

To search for code there are two options. There is either helm swoop (M-s, C-x a s to search all buffers) and helm occur(C-s). M-y for the kill ring, C-x r m is to traverse through bookmarks and C-x C-f to find files.

(use-package helm
	:ensure t
	:diminish
	:bind
	("C-s" . helm-occur)
	("M-y" . helm-show-kill-ring)
	("C-x r m" . helm-bookmarks)
	("C-x C-b" . helm-buffers-list)
	("C-x C-f" . helm-find-files)
)

Ace Jump Mode

C-x C-M-s to jump through text on the current screen.

(use-package ace-jump-mode
	:ensure t
	:bind
	("C-z" . ace-jump-mode)
	("M-z" . ace-jump-mode-pop-mark)
)

Smex

Smex incorporates fuzzy finding into M-x, making working in EMACS require much less memory work.

(global-set-key (kbd "C-M-g") 'query-replace-regexp)
(use-package smex
	:ensure t
	:diminish
	:bind("M-x" . smex)
)

Delete Trailing Whitespace on Save

As the header states, this will call the delete-trailing-whitespace function whenever a save occurs.

(use-package simple
	:no-require t
	:hook(before-save . delete-trailing-whitespace)
)

ISearch

(use-package isearch
	:no-require t
	:bind
	("M-s" . isearch-forward)
	("M-r" . isearch-backward)
)

(global-set-key (kbd “C-|”) ‘comment-box) (global-set-key (kbd “C-M-|”) ‘uncomment-region)

Folding

(use-package senator
	:no-require t
	:bind*("<M-down>" . senator-transpose-tags-down)
	("<M-up>" . senator-transpose-tags-up)
)

Defers

(use-package tramp :defer t)
(use-package with-editor :defer t)
(use-package org-agenda :defer t)
(use-package speedbar :defer t)
(use-package gud :defer t)
(use-package smartscan :defer t)
(use-package ivy :diminish :defer t)

Post initialization

Lowering the GC thresholds back to a sane level.

(setq gc-cons-threshold 16777216
      gc-cons-percentage 0.1)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published