Skip to content

Instantly share code, notes, and snippets.

@ZelphirKaltstahl
Last active March 10, 2017 18:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ZelphirKaltstahl/75736d22088a2a83694c18d44b3af9cd to your computer and use it in GitHub Desktop.
Save ZelphirKaltstahl/75736d22088a2a83694c18d44b3af9cd to your computer and use it in GitHub Desktop.
GNU Emacs 24 config file
;; deactivate version control integration, so that emacs starts up faster
(setq vc-handled-backends ())
;(setq-default vc-handled-backends nil)
;(eval-after-load "vc" '(remove-hook 'find-file-hooks 'vc-find-file-hook))
;; Installation of el-get
(add-to-list 'load-path "~/.emacs.d/el-get/el-get")
(unless (require 'el-get nil 'noerror)
(with-current-buffer
(url-retrieve-synchronously "https://raw.githubusercontent.com/dimitri/el-get/master/el-get-install.el")
(goto-char (point-max))
(eval-print-last-sexp)))
(add-to-list 'el-get-recipe-path "~/.emacs.d/el-get-user/recipes")
(el-get 'sync)
;; other stuff
(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.
'(ansi-color-names-vector
["#212526" "#ff4b4b" "#b4fa70" "#fce94f" "#729fcf" "#ad7fa8" "#8cc4ff" "#eeeeec"])
'(column-number-mode t)
'(custom-enabled-themes (quote (suscolors)))
'(custom-safe-themes
(quote
("b9b1a8d2ec1d5c17700e1a09256f33c2520b26f49980ed9e217e444c381279a9" default)))
'(flycheck-python-flake8-executable "/home/xiaolong/apps/anaconda3/envs/emacs-env/bin/flake8")
'(flycheck-python-pylint-executable "/home/xiaolong/apps/anaconda3/envs/emacs-env/bin/pylint")
'(flycheck-racket-executable "/usr/bin/raco")
'(lisp-body-indent 2)
'(lisp-indent-offset 2)
'(neo-hidden-regexp-list
(quote
("^\\." "\\.pyc$" "~$" "^#.*#$" "\\.elc$" ".*~$" "__pycache__.*")))
'(neo-show-hidden-files nil)
'(neo-theme (quote ascii))
'(neo-window-fixed-size t)
'(org-agenda-files (quote ("~/development/notes.org")))
'(python-indent-guess-indent-offset nil)
'(python-indent-trigger-commands (quote (indent-for-tab-command)))
'(python-shell-buffer-name "Python Console")
'(python-shell-exec-path
(quote
("/home/xiaolong/apps/anaconda3/envs/emacs-env/bin/" "/home/xiaolong/apps/anaconda3/bin/")))
'(python-shell-interpreter "/home/xiaolong/apps/anaconda3/bin/python")
'(python-shell-virtualenv-path "/home/xiaolong/apps/anaconda3/envs/emacs-env/")
'(send-mail-function (quote smtpmail-send-it))
'(show-paren-mode t)
'(size-indication-mode t)
'(smtpmail-smtp-server "smtp.gmail.com")
'(smtpmail-smtp-service 25)
'(tool-bar-mode nil)
'(word-wrap t))
(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.
'(cursor ((t (:background "gold" :foreground "#151718"))))
'(mode-line ((t (:background "black" :foreground "#4499FF"))))
'(neo-dir-link-face ((t (:foreground "deep sky blue" :slant normal :weight bold :height 120 :family "Fantasque Sans Mono"))))
'(neo-file-link-face ((t (:foreground "White" :weight normal :height 120 :family "Fantasque Sans Mono"))))
'(neo-root-dir-face ((t (:foreground "lightblue" :weight bold))))
'(show-paren-match ((t (:background "#000000" :foreground "spring green" :underline nil :weight ultra-bold))))
'(show-paren-mismatch ((t (:foreground "red" :weight bold)))))
;; MELPA
(require 'package) ;; You might already have this line
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/"))
(add-to-list 'package-archives '("melpa-stable" . "https://melpa.org/packages/"))
(when (< emacs-major-version 24)
;; For important compatibility libraries like cl-lib
(add-to-list 'package-archives '("gnu" . "http://elpa.gnu.org/packages/")))
(package-initialize) ;; You might already have this line
; SAVE SESSIONS - save sessions to restore buffers on next startup
(desktop-save-mode 1)
;; remember cursor position in file
(require 'saveplace)
(setq-default save-place t)
; load theme on startup
;;(add-hook 'emacs-startup-hook (load-theme 'seti))
(add-hook 'emacs-startup-hook (load-theme 'suscolors))
(set-face-attribute 'region nil :foreground "#FF00FF" :background "#000")
;; ===== FONT SETTINGS =====
(set-default-font "Inconsolata LGC-10:weight=normal:antialias=1")
;; functions for having buffer specific fonts
;; Use variable width font faces in current buffer
(defun my-buffer-face-mode-variable ()
"Set font to a variable width (proportional) fonts in current buffer"
(interactive)
(setq buffer-face-mode-face '(:family "Ubuntu Light" :height 120 :weight light)) ;;light thin regular book
(buffer-face-mode))
;; Use monospaced font faces in current buffer
(defun my-buffer-face-mode-fixed ()
"Sets a fixed width (monospace) font in current buffer"
(interactive)
(setq buffer-face-mode-face '(:family "Inconsolata LGC" :height 100 :weight normal))
(buffer-face-mode))
;; Set default font faces for Info and ERC modes
(add-hook 'rst-mode-hook 'my-buffer-face-mode-variable)
;; ===== turn on highlighting current line =====
(global-hl-line-mode 1)
(set-face-background 'hl-line "#303030")
(set-face-foreground 'highlight nil) ;; To keep syntax highlighting in the current line
;; highlight matching parenthesis
(show-paren-mode 1)
(setq-default show-paren-delay 0) ;; 0 delay
(setq-default show-paren-style 'parenthesis) ;;'parenthesis is another possible value, only highlighting the brackets
;; TAB WIDTH
(setq-default tab-width 4)
(setq-default indent-tabs-mode nil)
(setq-default tab-stop-list (number-sequence 4 200 4))
(defvaralias 'c-indent-level 'tab-width)
(defvaralias 'c-basic-offset 'tab-width)
(defvaralias 'sgml-indent-level 'tab-width)
(defvaralias 'sgml-basic-offset 'tab-width)
(setq whitespace-style
'(trailing tabs newline tab-mark newline-mark))
(add-hook 'racket-mode-hook
(function
(lambda ()
(setq whitespace-mode 1))))
(add-hook 'python-mode-hook
(function
(lambda ()
(setq whitespace-mode 1))))
(add-hook 'racket-mode-hook
(function
(lambda ()
(setq indent-tabs-mode nil tab-width 2))))
(add-hook 'python-mode-hook
(function (lambda ()
(setq indent-tabs-mode nil tab-width 4)
(setq-default python-indent 4))))
;; word wrap
;; for reStructuredText mode
(add-hook 'rst-mode-hook
(function (lambda ()
(setq word-wrap t))))
(add-hook 'org-mode-hook
(function (lambda ()
(global-set-key (kbd "C-c t") 'toggle-truncate-lines))))
;; make return key also do indent, globally
(electric-indent-mode 1)
;; SCROLL SPEED
(setq-default mouse-wheel-scroll-amount '(5 ((shift) . 5))) ;; two lines at a time
(setq-default mouse-wheel-progressive-speed nil) ;; don't accelerate scrolling
(setq-default mouse-wheel-follow-mouse 't) ;; scroll window under mouse
(setq-default scroll-step 5) ;; keyboard scroll one line at a time
(scroll-bar-mode -1)
;; case-insensitive minibuffer completion
(setq read-buffer-completion-ignore-case t)
(setq read-file-name-completion-ignore-case t)
;; MULTIPLE CURSORS
(require 'multiple-cursors)
;; LINE NUMBERS
(require 'linum)
(add-hook 'prog-mode-hook 'linum-on)
;; set fontsize
(eval-after-load "linum"
'(set-face-attribute 'linum nil :height 80))
;; the following code is for appropriately zooming line numbers
;; (defun linum-update-window-scale-fix (win)
;; "fix linum for scaled text"
;; (set-window-margins win
;; (ceiling (* (if (boundp 'text-scale-mode-step)
;; (expt text-scale-mode-step
;; text-scale-mode-amount) 1)
;; (if (car (window-margins))
;; (car (window-margins)) 1)
;; ))))
;; (advice-add #'linum-update-window :after #'linum-update-window-scale-fix)
;; DELETE SELECTED TEXT WHEN TYPING
(delete-selection-mode 1)
;; DEFINE A FUNCTION FOR DUPLICATING A LINE
(defun duplicate-line()
(interactive)
(move-beginning-of-line 1)
(kill-line)
(yank)
(newline)
(yank))
;; INDENT / UNINDENT REGION
(defun my-indent-region (N)
(interactive "p")
(if (use-region-p)
(progn (indent-rigidly (region-beginning) (region-end) (* N 4))
(setq deactivate-mark nil))
(self-insert-command N)))
(defun my-unindent-region (N)
(interactive "p")
(if (use-region-p)
(progn (indent-rigidly (region-beginning) (region-end) (* N -4))
(setq deactivate-mark nil))
(self-insert-command N)))
;; This function toggles the case of the selected text.
(defun toggle-case ()
(interactive)
(when (region-active-p)
(let
((i 0)
(return-string "")
(input (buffer-substring-no-properties (region-beginning) (region-end))))
(while (< i (- (region-end) (region-beginning)))
(let
((current-char (substring input i (+ i 1))))
(if
(string= (substring input i (+ i 1)) (downcase (substring input i (+ i 1))))
(setq return-string
(concat return-string (upcase (substring input i (+ i 1)))))
(setq return-string
(concat return-string (downcase (substring input i (+ i 1)))))))
(setq i (+ i 1)))
(delete-region (region-beginning) (region-end))
(insert return-string))))
(setq hippie-expand-try-functions-list
'(try-expand-dabbrev
try-expand-dabbrev-all-buffers
try-expand-dabbrev-from-kill
;; try-complete-file-name-partially
;; try-complete-file-name
try-expand-all-abbrevs
;; try-expand-list
;; try-expand-line
try-complete-lisp-symbol-partially
;;try-complete-lisp-symbol)
))
;; PDF VIEWING
(setq-default doc-view-pdfdraw-program "mudraw")
(setq-default doc-view-continuous t)
;; SPELLING
(require 'ispell)
(add-to-list 'ispell-local-dictionary-alist '("deutsch-hunspell"
"[[:alpha:]]"
"[^[:alpha:]]"
"[']"
t
("-d" "de_DE"); Dictionary file name
nil
iso-8859-1))
(add-to-list 'ispell-local-dictionary-alist '("english-hunspell"
"[[:alpha:]]"
"[^[:alpha:]]"
"[']"
t
("-d" "en_US")
nil
iso-8859-1))
(setq ispell-program-name "hunspell" ; Use hunspell to correct mistakes
ispell-dictionary "deutsch-hunspell") ; Default dictionary to use
(defun switch-dictionary-de-en ()
"Switch german and english dictionaries."
(interactive)
(let* ((dict ispell-current-dictionary)
(new (if (string= dict "deutsch-hunspell") "english-hunspell"
"deutsch-hunspell")))
(ispell-change-dictionary new)
(message "Switched dictionary from %s to %s" dict new)))
;; PREFERRED ENCODING
(prefer-coding-system 'utf-8)
;; GENERAL OPTIONS FOR DISPLAY OF "WIDGETS"
(line-number-mode)
(column-number-mode)
;; ORG MODE
;;;; BETTER ORG MODE LISTS
(add-hook 'org-mode-hook (lambda () (org-autolist-mode)))
;;;; automatically mark supertask as done when subtasks are done
;; (defun org-summary-todo (n-done n-not-done)
;; "Switch entry to DONE when all subentries are done, to TODO otherwise."
;; (let (org-log-done org-log-states) ; turn off logging
;; (org-todo (if (= n-not-done 0) "DONE" "TODO"))))
;; (add-hook 'org-after-todo-statistics-hook 'org-summary-todo)
;;;; holidays
(setq calendar-holidays nil)
;; SHELL
(add-hook 'shell-mode-hook
(lambda ()
(text-scale-decrease 1.2)))
(setq ansi-color-for-comint-mode-on t)
;; RELOADING FILES
;; Source: http://www.emacswiki.org/emacs-en/download/misc-cmds.el
(defun revert-buffer-no-confirm ()
"Revert buffer without confirmation."
(interactive)
(revert-buffer :ignore-auto :noconfirm))
;; ORG MODE CONFIG
;; agenda
(setq org-agenda-span 24)
(setq org-agenda-start-on-weekday 1)
(setq org-agenda-include-diary t)
(setq european-calendar-style t) ; without this diary will work with the useless not logical date format MM-DD-YYYY
;; &%%(diary-schedule 22 4 2003 1 8 2003 2) 18:00 History
(defun diary-schedule (m1 d1 y1 m2 d2 y2 dayname)
"Entry applies if date is between dates on DAYNAME.
Order of the parameters is M1, D1, Y1, M2, D2, Y2 if
`european-calendar-style' is nil, and D1, M1, Y1, D2, M2, Y2 if
`european-calendar-style' is t. Entry does not apply on a history."
(let
((date1
(calendar-absolute-from-gregorian
(if
european-calendar-style
(list d1 m1 y1)
(list m1 d1 y1))))
(date2
(calendar-absolute-from-gregorian
(if
european-calendar-style
(list d2 m2 y2)
(list m2 d2 y2))))
(d (calendar-absolute-from-gregorian date)))
(if
(and
(<= date1 d)
(<= d date2)
(= (calendar-day-of-week date) dayname)
(not (check-calendar-holidays date)))
entry)))
;; &%%(diary-countdown 22 4 2003 15) Conference deadline
(defun diary-countdown (m1 d1 y1 n)
"Reminder during the previous n days to the date.
Order of parameters is M1, D1, Y1, N if
`european-calendar-style' is nil, and D1, M1, Y1, N otherwise."
(diary-remind
'(diary-date m1 d1 y1)
(let
(value)
(dotimes
(number n value)
(setq value (cons number value))))))
;; DUMB JUMP - jump to definitions
(dumb-jump-mode)
;; NEOTREE CONFIG
(setq neo-smart-open t)
;; FLYCHECK - linter
(global-flycheck-mode)
(setq-default flycheck-flake8-maximum-line-length 100)
;; PYTHON INTERPRETER
(setq py-python-command "/home/xiaolong/apps/anaconda3/bin/python")
;; EMACS BACKUP FILES
(setq backup-directory-alist `(("." . "~/.emacs-backups")))
(setq backup-by-copying t)
(setq delete-old-versions t
kept-new-versions 6
kept-old-versions 10
version-control t)
;; BASH ALIASES AND PATH
(setq shell-file-name "bash")
(setq shell-command-switch "-ic")
;; W3M BROWSER CONFIG
(setq browse-url-browser-function 'w3m-goto-url-new-session)
;; (setq w3m-user-agent “Mozilla/5.0 (Linux; U; Android 2.3.3; zh-tw; HTC_Pyramid Build/GRI40) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.”)
(defun web-hacker-news ()
(interactive)
(browse-url "http://news.ycombinator.com"))
(defun web-github ()
(interactive)
(browse-url "http://news.ycombinator.com"))
;; WORD CHARACTERS
;; (require 'misc)
;; (defvar my-restructuredtext-syntax-table
;; (let
;; ((table (make-syntax-table)))
;;
;; (modify-syntax-entry ?- "w" table)
;; table))
;;
;; (add-hook 'rst-mode-hook
;; (lambda ()
;; (set-syntax-table my-restructuredtext-syntax-table)))
;;KEY DEFINITIONS
;;unsetting keys which are predefined
;; (dolist (key '("\C-a" "\C-b" "\C-c" "\C-d" "\C-e" "\C-f" "\C-g"
;; "\C-h" "\C-k" "\C-l" "\C-n" "\C-o" "\C-p" "\C-q"
;; "\C-t" "\C-u" "\C-v" "\C-x" "\C-z" "\e"))
;; (global-unset-key key))
(dolist (key '("\C-g"))
(global-unset-key key))
(define-key global-map (kbd "RET") 'newline-and-indent)
(define-key global-map (kbd "<C-return>") 'newline)
(global-set-key (kbd "<C-mouse-5>") (lambda () (interactive) (text-scale-decrease 1)))
(global-set-key (kbd "<C-mouse-4>") (lambda () (interactive) (text-scale-increase 1)))
(global-set-key (kbd "C-S-c C-S-c") 'mc/edit-lines)
(global-set-key (kbd "C-n") 'set-mark-command)
(global-set-key (kbd "C-d") 'duplicate-line)
(global-set-key (kbd "C->") 'my-indent-region)
(global-set-key (kbd "C-<") 'my-unindent-region)
(global-set-key (kbd "<C-tab>") 'hippie-expand)
(global-set-key (kbd "<f8>") 'neotree-toggle)
(global-set-key (kbd "C-~") 'toggle-case)
(global-set-key (kbd "C-d") 'kill-whole-line)
(global-set-key (kbd "M-<left>") 'backward-sexp)
(global-set-key (kbd "M-<right>") 'forward-sexp)
;; moving between windows
(global-set-key (kbd "s-<left>") 'windmove-left)
(global-set-key (kbd "s-<right>") 'windmove-right)
(global-set-key (kbd "s-<up>") 'windmove-up)
(global-set-key (kbd "s-<down>") 'windmove-down)
;; rebinding combination for zap-to-char to the installed zop-to-char
(global-set-key [remap zap-to-char] 'zop-up-to-char)
(global-set-key (kbd "C-g l") 'goto-last-change)
;; spelling change dictionary
(global-set-key (kbd "C-c d") 'switch-dictionary-de-en)
(global-set-key (kbd "C-c S-h") 'highlight-regexp)
(global-set-key (kbd "C-c h") 'highlight-phrase)
(global-set-key (kbd "C-c u") 'unhighlight-regexp)
;; multiple cursor bindings with ctrl+c and m
(global-set-key (kbd "C-c m") 'set-rectangular-region-anchor)
;; reload file
(global-set-key (kbd "C-c r") 'revert-buffer-no-confirm)
(global-set-key (kbd "C-c a") 'org-agenda)
;; STARTUP
;; use the following command for creating a starter
;; to support dead keys and
;; fcitx input method
;; /bin/bash -c "XMODIFIERS=@im=fcitx LC_CTYPE=\"zh_CN.UTF-8\" emacs"
(put 'downcase-region 'disabled nil)
(put 'upcase-region 'disabled nil)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment