Hide bars
;; Turn off mouse interface early in startup to avoid momentary display
(if (fboundp 'menu-bar-mode) (menu-bar-mode -1))
(if (fboundp 'tool-bar-mode) (tool-bar-mode -1))
(if (fboundp 'scroll-bar-mode) (scroll-bar-mode -1))
Inhibit startup messages for default buffers
(setq inhibit-splash-screen t)
(setq inhibit-startup-message t
inhibit-startup-echo-area-message t)
(setq initial-scratch-message nil)
Select default theme
(use-package nord-theme
:ensure t
:config
(add-hook 'after-make-frame-functions
(lambda (frame)
(select-frame frame)
(load-theme 'nord t)))
)
;; Use automatic
(use-package smartparens
:ensure t
:config (use-package smartparens-config))
Use spaceline and all-the-icons-theme for modeline but remember to install fonts with M-x all-the-icons-install-fonts.
(use-package spaceline-config
:ensure spaceline
:config
(spaceline-helm-mode 1)
)
(use-package spaceline-all-the-icons
:ensure t
:after spaceline-config
:config
(setq spaceline-all-the-icons-icon-set-flycheck-slim 'dots
spaceline-all-the-icons-flycheck-alternate t
spaceline-all-the-icons-highlight-file-name t
spaceline-all-the-icons-hide-long-buffer-path t
spaceline-all-the-icons-separator-type (quote wave)
spaceline-responsive nil
)
(spaceline-toggle-all-the-icons-bookmark-on)
(spaceline-toggle-all-the-icons-dedicated-on)
(spaceline-toggle-all-the-icons-fullscreen-on)
(spaceline-toggle-all-the-icons-buffer-position-on)
(spaceline-all-the-icons--setup-package-updates)
(spaceline-all-the-icons-theme)
)
Don’t blink cursor
(blink-cursor-mode -1)
Show column numbers
(setq column-number-mode t)
Automatic indentation same as original file
(use-package dtrt-indent
:ensure t
:config
(dtrt-indent-mode)
(setq dtrt-indent-min-quality 60
dtrt-indent-verbosity 3)
)
Allow toggling to full-screen mode by f11 key-binding
(global-set-key (kbd "<f11>") 'toggle-frame-fullscreen)
Add easier key-bindings for cycling between buffers
(global-set-key (kbd "C-<prior>") 'previous-buffer) ; Same as Ctrl+PageDown.
(global-set-key (kbd "C-<next>") 'next-buffer) ; Same as Ctrl+PageUp.
Short cut for yes or no answers
(defalias 'yes-or-no-p 'y-or-n-p)
Keep history of commands
(setq savehist-file "~/.emacs.d/savehist")
(savehist-mode 1)
(setq history-length t)
(setq history-delete-duplicates t)
(setq savehist-save-minibuffer-history 1)
Instead of current directory use dedicated folder for backups
(setq backup-directory-alist '(("." . "~/.emacs.d/backups")))
;; Don't ask to delete old backup
(setq delete-old-versions t)
Use version control for storing them
(setq version-control t)
(setq vc-make-backup-files t)
(setq auto-save-file-name-transforms '((".*" "~/.emacs.d/auto-save-list/" t)))
Use flycheck to highlight the code
(use-package flycheck
:ensure t
:diminish flycheck-mode
:init (global-flycheck-mode)
:config
(setq flycheck-check-syntax-automatically '(mode-enabled save idle-change))
(setq flycheck-highlighting-mode 'lines)
(setq flycheck-indication-mode 'left-fringe)
(setq flycheck-checker-error-threshold 2000)
)
Use snippets as one of company back-ends
(use-package yasnippet
:ensure t
:diminish yas-minor-mode
:config
(setq yas-snippet-dirs
(append yas-snippet-dirs
'("~/.emacs.d/snippets/")))
;; Disable yasnippet default key bindings
;; in favour of company-yasnippet back-end
(define-key yas-minor-mode-map [(tab)] nil)
(define-key yas-minor-mode-map (kbd "TAB") nil)
;; Global mode
(yas-global-mode 1))
Use company-mode for all sorts of completions. First load company package and re-define some of key-bindings.
;; Core company package
(use-package company
:ensure t
:diminish company-mode
:config
(setq company-tooltip-align-annotations t)
(setq company-selection-wrap-around t)
(setq company-tooltip-flip-when-above t)
(setq company-idle-delay 0.1)
(setq company-dabbrev-downcase nil)
(setq company-minimum-prefix-length 3)
(setq company-show-numbers t)
(delete 'company-dabbrev company-backends)
(add-to-list 'company-backends 'company-yasnippet)
(add-hook 'after-init-hook 'global-company-mode)
:bind
(
;; Global keys
("C-<tab>" . company-complete)
("C-c y" . company-yasnippet)
;; Only when completion is active
:map company-active-map
;; Key to abort completion
("ESC" . company-abort)
("SPC" . company-abort)
;; RET complete common candidate or cycle if more candidates
("<return>" . company-complete-common-or-cycle)
;; C-RET complete selected candidate
("<C-return>" . company-complete-selection)
)
)
Display help for completion as popup
;; Display help for functions
(use-package company-quickhelp
:after company
:ensure t
:init
:config
(company-quickhelp-mode 1)
(setq company-quickhelp-delay 0)
)
Manage projects with projectile
(use-package projectile
:ensure projectile
:config (projectile-global-mode t)
:diminish projectile-mode)
Use helm for incremental searching
(use-package helm
:ensure t
:diminish helm-mode
;; Rebind default keys to used helm
:bind (("C-c h" . helm-command-prefix)
("M-x" . helm-M-x)
("C-x C-f" . helm-find-files)
("C-x b" . helm-mini))
:config
;; Use fuzzy matching
(setq helm-M-x-fuzzy-match t)
(setq helm-buffers-fuzzy-matching t
helm-recentf-fuzzy-match t)
;; Restore tab to do persistent action
(define-key helm-map (kbd "<tab>") 'helm-execute-persistent-action)
;; Make tab work in terminal
(define-key helm-map (kbd "C-i") 'helm-execute-persistent-action)
;; List actions with another key
(define-key helm-map (kbd "C-z") 'helm-select-action)
;; Use helm kill ring for yanking
(global-set-key (kbd "M-y") 'helm-show-kill-ring)
;; Use helm mini for buffers
(global-set-key (kbd "C-x b") 'helm-mini)
;; Use helm globally
(use-package helm-mode
:init (helm-mode 1))
)
Add helm backend to company
(use-package helm-company
:ensure t
:after company
:config
(define-key company-mode-map (kbd "C-:") 'helm-company)
(define-key company-active-map (kbd "C-:") 'helm-company)
;; File completion key-binding
(define-key global-map (kbd "C-u") 'helm-complete-file-name-at-point)
)
By default load projectile and enable all commands under C-c p
(use-package helm-projectile
:ensure t
:config
;; All projectile commands start with C-c p
(projectile-global-mode)
(setq projectile-completion-system 'helm)
(helm-projectile-on)
)
;; Use org-projectile for todo
(use-package org-projectile
:bind (("C-c n p" . org-projectile-project-todo-completing-read)
("C-c c" . org-capture))
:config
(progn
(setq org-projectile-projects-file
"~/Dropbox/projects.org")
(setq org-agenda-files (append org-agenda-files (org-projectile-todo-files)))
(push (org-projectile-project-todo-entry) org-capture-templates))
:ensure t)
Instead of default isearch use helm-swoop for searching buffer
(use-package helm-swoop
:ensure helm-swoop
:bind (("C-s" . helm-swoop)
("M-s" . helm-multi-swoop)))
Use visual regex for replacing with C-M-g key
(use-package visual-regexp-steroids
:ensure t
:config
(define-key global-map (kbd "C-c C-g") 'vr/query-replace)
)
Show tree with C-x u short-key
(use-package undo-tree
:ensure t
:diminish undo-tree-mode
:init (global-undo-tree-mode))
Configure flyspell
(use-package flyspell
:ensure t
:defer t
:init
(progn
;; Add hooks
(add-hook 'prog-mode-hook 'flyspell-prog-mode)
(add-hook 'text-mode-hook 'flyspell-mode)
)
:config
(defun flyspell-check-next-highlighted-word ()
"Custom function to spell check next highlighted word"
(interactive)
(flyspell-goto-next-error)
(ispell-word)
)
;; Sets flyspell correction
(global-set-key (kbd "C-<f8>") 'flyspell-check-next-highlighted-word)
)
Tool to check grammar
(use-package langtool
:ensure t
:bind (("\C-x4w" . langtool-check)
("\C-x4W" . langtool-check-done)
("\C-x4l" . langtool-switch-default-language)
("\C-x44" . langtool-show-message-at-point)
("\C-x4c" . langtool-correct-buffer))
:config
(setq langtool-language-tool-jar "/opt/LanguageTool-4.0/languagetool-commandline.jar")
(setq langtool-default-language "en-US")
)
Define global key C-c m for starting Emacs’s git client
(use-package magit
:ensure t
:config
(setq magit-last-seen-setup-instructions "1.4.0")
;; Add global key-binding to bring up magit interface
(global-set-key (kbd "C-c m") 'magit-status)
)
Install package and assign key-binding for easy gist pasting
(use-package gist
:ensure t
:bind ("C-c M-g" . gist-region-or-buffer-private))
Load elpy for python-mode.
(use-package python-mode
:ensure t
:defer t
:mode ("\\.py" . python-mode)
:config
;; Load elpy
(use-package elpy
:ensure t
:init
(elpy-enable)
:config
;; Use pyenv
(setq pyenv-path "~/pyenv")
(when (file-exists-p pyenv-path)
(pyvenv-activate pyenv-path))
;; Set default indent
(setq python-indent-offset 4)
;; Use jedi as compeltion backend
(setq elpy-rpc-backend "jedi")
;; Use Python to run the RPC process
(setq elpy-rpc-python-command "python3")
;; Default shell interpreter
(setq python-shell-interpreter "ipython3")
(setq python-shell-interpreter-args "--simple-prompt --pprint")
;; Enable company as completion backend
(setq company-auto-complete t)
;; Remove flymake module since we use flycheck
(remove-hook 'elpy-modules 'elpy-module-flymake)
(add-hook 'elpy-mode-hook 'flycheck-mode)
;; Hookup company mode
(add-hook 'elpy-mode-hook 'company-mode)
;; Hookup jedi setup
(add-hook 'elpy-mode-hook 'jedi:setup)
)
)
Load syntax highlighting according to PEP8
(use-package py-autopep8
:after elpy
:ensure t
:config
(add-hook 'elpy-mode-hook 'py-autopep8-enable-on-save)
)
Use Jedi completion with company
;; Python auto completion
(use-package company-jedi
:ensure t
:init
(setq company-jedi-python-bin "python3")
:config
(add-to-list 'company-backends 'company-jedi)
)
R for statistics and Julia for numerical computations with ESS (Emacs speaks statistics).
;; Set path to latest julia
(setq inferior-julia-program-name "~/Downloads/julia")
(use-package ess-site
:ensure ess
:defer t
:mode (("\\.[rR]\\'" . R-mode)
("\\.jl\\'" . ess-julia-mode))
:commands (R-mode ess-julia-mode)
:config
;; Use company completion
(setq ess-use-company t)
(setq ess-tab-complete-in-script t)
;; Use default directory
(setq ess-ask-for-ess-directory nil)
)
Load Org-mode on demand.
(use-package org
:ensure org-plus-contrib
:pin org
:config
;; Max indent of list description
(setq org-list-description-max-indent 4)
;; Sublevels inherit property from parents
(setq org-use-property-inheritance t)
;; Fontify src blocks
(setq org-src-fontify-natively t)
;; Press enter to follow links
(setq org-return-follows-link t)
;; Use prefix key as tag selection
(setq org-use-fast-todo-selection t)
;; Add time-stamps when todo is closed
(setq org-log-done t)
;; Remove XHTML validation link
(setq org-html-validation-link nil)
;; No automatic subscripts
(setq org-export-with-sub-superscripts nil)
;; Subscripts in org only with parens
(setq org-use-sub-superscripts '{})
;; Standard line wrapping
(setq org-startup-truncated nil)
;; You want this to have completion in blocks
(setq org-src-tab-acts-natively t)
;; Hide the *,=, or / markers
(setq org-hide-emphasis-markers t)
;; To have \alpha, \to and others display
(setq org-pretty-entities t)
;; Don't ask for confirmation to evaluate source blocks
(setq org-confirm-babel-evaluate nil)
;; Update and display inline images after block evaluation
(add-hook 'org-babel-after-execute-hook 'org-display-inline-images 'append)
)
;; Load julia for org-mode
;; (load "~/.emacs.d/ob-julia/ob-julia.el")
;; Supported languages
(org-babel-do-load-languages
'org-babel-load-languages
'((R . t)
(emacs-lisp . t)
(python . t)
(sh . t)
))
Highlight syntax in exported HTML
(use-package htmlize
:ensure t)
Support drag and drop
(use-package org-download
:ensure t
:defer 2
:config
(setq-default org-download-image-dir "~/Dropbox/Pictures/")
)
Use RevealJS for presentations
(use-package ox-reveal
:ensure ox-reveal
:config
(setq org-reveal-root "http://cdn.jsdelivr.net/reveal.js/3.0.0/")
)
Configure org-ref for handling references
(use-package org-ref
:ensure t
:pin melpa
:config
(setq reftex-default-bibliography '("~/Dropbox/Research/references.bib"))
(setq org-default-notes-file "~/Dropbox/Research/notes.org")
(setq org-ref-bibliography-notes "~/Dropbox/Research/notes.org"
org-ref-default-bibliography '("~/Dropbox/Research/references.bib")
org-ref-pdf-directory "~/Dropbox/Research/papers/")
;; Customize bibtex key generation (useful for doi importer)
(setq bibtex-align-at-equal-sign t
bibtex-autokey-name-year-separator ""
bibtex-autokey-year-title-separator ""
bibtex-autokey-titleword-first-ignore '("the" "a" "if" "and" "an")
bibtex-autokey-titleword-length 10
bibtex-autokey-titlewords 1)
)
Manage bibliography with aid of helm
(use-package helm-bibtex
:ensure t
:after org-ref
:commands helm-bibtex
:config
(setq helm-bibtex-bibliography "~/Dropbox/Research/references.bib")
(setq helm-bibtex-notes-path "~/Dropbox/Research/notes.org")
(setq helm-bibtex-library-path "~/Dropbox/Research/papers/")
(setq helm-bibtex-pdf-open-function
(lambda (fpath)
(start-process "open" "*open*" "open" fpath)))
)
Add mode to view TSV files in Emacs, without lines wrapping around.
;; CSV mode config
(use-package csv-mode
:ensure t
:mode "\\.tab$"
:init
(setq csv-separators '("\t"))
;:bind
;(("M-f" . csv-forward-field)
;("M-b" . csv-backward-field))
)