Wednesday, August 3, 2016

Emacs Preferences

In this blog, I will describe various settings that I have used to configure the default behavior of my emacs text editor. In Linux based systems, these configurations are generally stored in a file located at ~/.emacs or ~/.emacs.d/init.el

Starting the emacs server

(server-start)

Automatically loading whizzytex mode while editing Latex files

(autoload 'whizzytex-mode "/usr/local/share/whizzytex/emacs/whizzytex.el"
"WhizzyTeX, a minor-mode WYSIWIG environment for LaTeX" t)

Enable automatic spell checking using Flyspell

(add-hook 'text-mode-hook 'flyspell-mode)

(add-hook 'prog-mode-hook 'flyspell-prog-mode)

Set several useful custom variables


(custom-set-variables
  '(browse-url-browser-function (quote browse-url-conkeror))
  '(doc-view-continuous t)
  '(doc-view-resolution 300)
  '(inhibit-startup-screen t)
  '(package-selected-packages
     (quote
       (color-theme-modern eink-theme colorsarenice-theme pabbrev pdf-tools
       cdlatex latex-extra auctex)))
 '(show-paren-mode t))

Highlight current line and set a background color for the highlighted region

(defface hl-line '((t (:background "#292929")))
  "Face to use for `hl-line-face'." :group 'hl-line)
(setq hl-line-face 'hl-line)
(global-hl-line-mode t) ; turn it on for all modes by default

Set the default font family and size

(custom-set-faces
  '(default ((t (:family "unifont" :foundry "unknown" :slant normal :weight normal
   :height 120 :width normal)))))

Keyboard shortcut for starting the web browser

(global-set-key (kbd "C-x m") 'browse-url)

Enable auto refresh mode for reading pdf files in doc-view mode

 (add-hook 'doc-view-mode-hook 'auto-revert-mode)

Configure MELPA and ELPA repositories for package management

(require 'package)
(add-to-list 'package-archives
             '("melpa-stable" . "http://stable.melpa.org/packages/") t)
(package-initialize)

Set default paths (directories) to be loaded automatically

(let ((default-directory  "~/.emacs.d/elpa/"))
   (normal-top-level-add-subdirs-to-load-path))
(let ((default-directory  "~/.emacs.d/predictive/"))
   (normal-top-level-add-subdirs-to-load-path))

Enable predictive mode (word completion)

(require 'predictive)


Configure the behavior of the full screen mode

(defun my-fullscreen ()
  (interactive)
  (set-frame-parameter nil 'fullscreen 'fullboth)
  (tool-bar-mode -1)
  (scroll-bar-mode -1)
  (menu-bar-mode -1))

(defun my-non-fullscreen ()
  (interactive)
  (set-frame-parameter nil 'width 82)
  (set-frame-parameter nil 'fullscreen 'fullheight)
  (menu-bar-mode t))

(defun toggle-fullscreen ()
  (interactive)
  (if (eq (frame-parameter nil 'fullscreen) 'fullboth)
      (my-non-fullscreen)
    (my-fullscreen)))

Keyboard shortcut for turning the full screen mode on and off

(global-set-key (kbd "<f11>") 'toggle-fullscreen)

Display time on the mod line

(display-time-mode 1)



Set Color theme

(load-theme 'euphoria)

Automatically insert line break when a line becomes too long

(setq-default fill-column 130)
(add-hook 'text-mode-hook 'turn-on-auto-fill)

No comments:

Post a Comment