Skip to content

Instantly share code, notes, and snippets.

@oNguyenNgocTrung
Created June 15, 2018 08:48
Show Gist options
  • Save oNguyenNgocTrung/63d98de78a37b08dc4934d0f26e5fa01 to your computer and use it in GitHub Desktop.
Save oNguyenNgocTrung/63d98de78a37b08dc4934d0f26e5fa01 to your computer and use it in GitHub Desktop.
Emacs config
;;;; SPEED UP EMACS ====================================
;; Decrease the number of garbage collection invocations
(setq gc-cons-threshold 10000000)
(add-hook 'emacs-startup-hook 'my/set-gc-threshold)
(defun my/set-gc-threshold ()
"Reset `gc-cons-threshold' to its default value."
(setq gc-cons-threshold 800000))
;; Package configs
(require 'package)
(setq package-enable-at-startup nil)
(setq package-archives '(("org" . "http://orgmode.org/elpa/")
("gnu" . "http://elpa.gnu.org/packages/")
("melpa" . "https://melpa.org/packages/")))
(package-initialize)
;; Bootstrap `use-package`
(unless (package-installed-p 'use-package)
(package-refresh-contents)
(package-install 'use-package))
(require 'use-package)
(org-babel-load-file (expand-file-name "~/.emacs.d/my_init.org"))

interface tweaks

;; Maximize window on starting
(add-to-list 'default-frame-alist '(fullscreen . maximized))
(setq inhibit-startup-screen t)
(menu-bar-mode -1)
(scroll-bar-mode -1)
(tool-bar-mode -1)
(tooltip-mode -1)
(fset 'yes-or-no-p 'y-or-n-p)
(global-set-key (kbd "<f5>") 'revert-buffer)

;; ido-mode
(setq ido-enable-flex-matching t)
(setq ido-everywhere t)
(ido-mode 1)

;; Display line number when programming
(add-hook 'prog-mode-hook 'linum-mode)
(setq linum-format "%4d \u2502")

;; tab-indent
(setq tab-width 2)

;; Display paren (highlight matching brackets)
(show-paren-mode 1)
(setq show-paren-delay 0)

;; word wrap
(global-visual-line-mode t)

;; Set Font
(set-face-attribute 'default nil
                    :family "Source Code Pro"
                    :height 90
                    :weight 'normal
                    :width 'normal)

Package

which-key

Brings up some help

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

Org-mode stuff

Org bullets makes things look pretty

(use-package org-bullets
  :ensure t
  :config
  (add-hook 'org-mode-hook (lambda () (org-bullets-mode 1))))

Sublimity

Smooth Scrolling and attractive mode (look like Sublime Text)

(use-package sublimity
  :ensure t
  :config
  (require 'sublimity-scroll)
  ;; (require 'sublimity-map) ;; experimental
  (require 'sublimity-attractive)
  (sublimity-mode 1))

Swiper, Counsel

Replace default completion frontend with Ivy

(use-package counsel
  :ensure t
  :config (ivy-mode 1)
  :init
  (progn
    (setq ivy-use-virtual-buffers t)
    (setq enable-recursive-minibuffers t)
    (global-set-key "\C-s" 'swiper)
    (global-set-key (kbd "C-c C-r") 'ivy-resume)
    (global-set-key (kbd "<f6>") 'ivy-resume)
    (global-set-key (kbd "M-x") 'counsel-M-x)
    (global-set-key (kbd "C-x C-f") 'counsel-find-file)
    (global-set-key (kbd "<f1> f") 'counsel-describe-function)
    (global-set-key (kbd "<f1> v") 'counsel-describe-variable)
    (global-set-key (kbd "<f1> l") 'counsel-find-library)
    (global-set-key (kbd "<f2> i") 'counsel-info-lookup-symbol)
    (global-set-key (kbd "<f2> u") 'counsel-unicode-char)
    (global-set-key (kbd "C-c g") 'counsel-git)
    (global-set-key (kbd "C-c j") 'counsel-git-grep)
    (global-set-key (kbd "C-c k") 'counsel-ag)
    (global-set-key (kbd "C-x l") 'counsel-locate)
    (global-set-key (kbd "C-S-o") 'counsel-rhythmbox)
    (define-key read-expression-map (kbd "C-r") 'counsel-expression-history)))

Autocomplete

(use-package company
  :ensure t
  :config (global-company-mode t))

Snippets

(use-package yasnippet
  :ensure t
  :defer t
  :init
  (yas-global-mode 1))

Theme

(use-package doom-themes :ensure t)

all-the-icons

(use-package all-the-icons
  :ensure t)

neotree

Display a directory tree view on the left side

(use-package neotree
  :ensure t
  :config (progn
	        (setq neo-theme (if (display-graphic-p) 'icons 'arrow)))
  :bind ("C-x n o" . neotree-toggle))

Custom set

;; Comment/Uncomment
(defun xah-comment-dwim ()
  "Like `comment-dwim', but toggle comment if cursor is not at end of line."
  (interactive)
  (if (region-active-p)
      (comment-dwim nil)
    (let ((-lbp (line-beginning-position))
          (-lep (line-end-position)))
      (if (eq -lbp -lep)
          (progn
            (comment-dwim nil))
        (if (eq (point) -lep)
            (progn
              (comment-dwim nil))
          (progn
            (comment-or-uncomment-region -lbp -lep)
            (forward-line )))))))
(global-set-key (kbd "C-c c") 'xah-comment-dwim)

;; Manage buffers
(defun switch-to-previous-buffer ()
  "Switch to previously open buffer.
Repeated invocations toggle between the two most recently open buffers."
  (interactive)
  (switch-to-buffer (other-buffer (current-buffer) 1)))
(use-package key-chord
  :ensure t
  :config
  (progn
  (key-chord-mode 1)
  (setq key-chord-two-keys-delay 0.3)
  (setq key-chord-one-key-delay 0.3)
  (key-chord-define-global "jj" 'switch-to-previous-buffer)
  (key-chord-define-global "kk" 'next-buffer))
  (key-chord-define-global "gg" 'goto-line)
  (key-chord-define-global "yy" 'other-window)
  (key-chord-define-global "xx" 'kill-buffer))

;; Move between windows
(global-set-key (kbd "C-c <left>")  'windmove-left)
(global-set-key (kbd "C-c <right>") 'windmove-right)
(global-set-key (kbd "C-c <up>")    'windmove-up)
(global-set-key (kbd "C-c <down>")  'windmove-down)


(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(custom-enabled-themes (quote (doom-one)))
 '(custom-safe-themes
   (quote
    ("9d9fda57c476672acd8c6efeb9dc801abea906634575ad2c7688d055878e69d6" "a566448baba25f48e1833d86807b77876a899fc0c3d33394094cf267c970749f" default)))
)
(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment