Last active
March 16, 2019 02:06
-
-
Save zazhang/3fcc181d2cac1788337a4a26a0953bfa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 20190316 | |
;; Emacs 26.1 | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
; Appearance | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;; Set default find folder path, mainly for Windows | |
;(setq default-directory "~/documents/projects/") | |
;; Set font size, 1 = 0.01pt, 160 = 16pt | |
(set-face-attribute 'default (selected-frame) :height 220) | |
;; Set visual line mode | |
(global-visual-line-mode t) | |
;; Start with full screen | |
(set-frame-parameter nil 'fullscreen 'fullboth) | |
;; monokai theme | |
(add-to-list 'custom-theme-load-path "~/.emacs.d/plugins/monokai-theme") | |
(load-theme 'monokai t) | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
; Custom Set Variables | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
(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-safe-themes | |
(quote | |
("f0c98535db38af17e81e491a77251e198241346306a90c25eb982b57e687d7c0" default))) | |
'(package-selected-packages | |
(quote | |
(auctex git-gutter latex-preview-pane py-autopep8 company polymode monokai-theme))) | |
'(safe-local-variable-values (quote ((TeX-master . 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. | |
) | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
; Package Manager | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;; package manager | |
(require 'package) | |
(add-to-list 'package-archives | |
'("melpa" . "http://melpa.org/packages/") t) | |
;(add-to-list 'package-archives | |
; '("melpa" . "https://melpa.org/packages/") t) ;; Sometimes, "https" just doesn't work, try "http" | |
(when (< emacs-major-version 24) | |
;; For important compatibility libraries like cl-lib | |
(add-to-list 'package-archives '("gnu" . "https://elpa.gnu.org/packages/"))) | |
(package-initialize) | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
; Utilities | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;; column-indicator | |
(add-to-list 'load-path "~/.emacs.d/plugins/fill-column-indicator") | |
(require 'fill-column-indicator) | |
(define-globalized-minor-mode | |
global-fci-mode fci-mode (lambda () (fci-mode 1))) | |
(global-fci-mode t) | |
;; Use the value of $PATH constructed at shell's creation | |
;; (done only when emacs started with window-system) | |
;; mostly the r startup nil problem is caused by not having this done | |
;; see [this website](https://howtos.gattaz.net/2016/01/22/install-emacs-ess-and-org-mod-on-os-x/) for reference | |
(defun set-exec-path-from-shell-PATH () | |
(let ((path-from-shell (replace-regexp-in-string | |
"[ \t\n]*$" | |
"" | |
(shell-command-to-string "$SHELL --login -i -c 'echo $PATH'")))) | |
(setenv "PATH" path-from-shell) | |
(setq eshell-path-env path-from-shell) ; for eshell users | |
(setq exec-path (split-string path-from-shell path-separator)) | |
) | |
) | |
(when window-system (set-exec-path-from-shell-PATH)) | |
;; set rename file command | |
(defun rename-file-and-buffer () | |
"Rename the current buffer and file it is visiting." | |
(interactive) | |
(let ((filename (buffer-file-name))) | |
(if (not (and filename (file-exists-p filename))) | |
(message "Buffer is not visiting a file!") | |
(let ((new-name (read-file-name "New name: " filename))) | |
(cond | |
((vc-backend filename) (vc-rename-file filename new-name)) | |
(t | |
(rename-file filename new-name t) | |
(set-visited-file-name new-name t t))))))) | |
; set the key-binding | |
(global-set-key (kbd "C-c r") 'rename-file-and-buffer) | |
;; spell check | |
(add-to-list 'exec-path "usr/local/Cellar/aspell/0.60.6.1_1/bin/") | |
(setq ispell-program-name "aspell") | |
;(setq ispell-personal-dictionary "/path/to/your/.ispell") | |
(require 'ispell) | |
(global-set-key (kbd "<f8>") 'ispell-word) | |
(global-set-key (kbd "C-<f6>") 'flyspell-mode) | |
;; git gutter | |
(global-git-gutter-mode +1) | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
; R | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;ESS configuration | |
(add-to-list 'load-path "~/.emacs.d/plugins/ess-17.11/lisp/") | |
(setq inferior-R-program-name "/usr/local/bin/R") | |
(setq ess-local-process-name "R") | |
(setq ansi-color-for-comint-mode 'filter) | |
(setq comint-scroll-to-bottom-on-input t) | |
(setq comint-scroll-to-bottom-on-output t) | |
(setq comint-move-point-for-output t) | |
(setq ess-eval-visibly-p nil) | |
(require 'ess-site) | |
;; Markdown | |
(load "~/.emacs.d/elpa/markdown-mode-20190305.319/markdown-mode.el") | |
(autoload 'markdown-mode "markdown-mode" | |
"Major mode for editing Markdown files" t) | |
(add-to-list 'auto-mode-alist '("\\.md\\'" . markdown-mode)) | |
;; R-markdown | |
(setq load-path | |
(append '("~/.emacs.d/elpa/polymode/" "~/.emacs.d/elpa/polymode/modes") | |
load-path)) | |
(require 'poly-R) | |
(require 'poly-markdown) | |
(add-to-list 'auto-mode-alist '("\\.Rmd\\'" . poly-markdown+r-mode)) | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
; Python | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;; python-mode | |
(add-to-list 'load-path "~/.emacs.d/plugins/python-mode.el-6.2.2") | |
(setq py-install-directory "~/.emacs.d/plugins/python-mode.el-6.2.2/") | |
(require 'python-mode) | |
(setq-default py-shell-name "/usr/local/bin/ipython") | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
; C++ | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
; Java | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
; LaTeX | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;; LaTeX configuration | |
;(global-visual-line-mode 1); Proper line wrapping | |
;(global-hl-line-mode 1); Highlight current row | |
(show-paren-mode 1); Matches parentheses and such in every mode | |
(set-fringe-mode '(0 . 0)); Disable fringe because I use visual-line-mode | |
;(setq inhibit-splash-screen t); Disable splash screen | |
(setq visible-bell t); Flashes on error | |
(setq calendar-week-start-day 1); Calender should start on Monday | |
(add-to-list 'default-frame-alist '(height . 59)); Default frame height. | |
;; AUCTeX | |
;; Customary Customization, p. 1 and 16 in the manual, and http://www.emacswiki.org/emacs/AUCTeX#toc2 | |
(setq TeX-parse-self t); Enable parse on load. | |
(setq TeX-auto-save t); Enable parse on save. | |
(setq-default TeX-master nil) | |
(setq TeX-PDF-mode t); PDF mode (rather than DVI-mode) | |
(setq ispell-dictionary "english"); Default dictionary. To change do M-x ispell-change-dictionary RET. | |
(add-hook 'TeX-mode-hook | |
(lambda () (TeX-fold-mode 1))); Automatically activate TeX-fold-mode. | |
(setq LaTeX-babel-hyphen nil); Disable language-specific hyphen insertion. | |
;; LaTeX-math-mode http://www.gnu.org/s/auctex/manual/auctex/Mathematics.html | |
(add-hook 'TeX-mode-hook 'LaTeX-math-mode) | |
;; RefTeX | |
;; Turn on RefTeX for AUCTeX http://www.gnu.org/s/auctex/manual/reftex/reftex_5.html | |
(add-hook 'TeX-mode-hook 'turn-on-reftex) | |
;; LaTeX preview pane | |
;(latex-preview-pane-enable) ; automatically start the mode | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
; SQL | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;; truncate long lines in SQLi mode | |
(add-hook 'sql-interactive-mode-hook | |
(lambda () | |
(toggle-truncate-lines t))) | |
;; setup default login parameters | |
;(setq sql-mysql-login-params | |
; '((user :default "root") | |
; (database :default "sakila") ; sakila is an example database | |
; (server :default "localhost") | |
; (password :default "password") | |
; (port :default 3306))) | |
;; setup multiple databases and servers login | |
(setq sql-connection-alist | |
'((server1 (sql-product 'mysql) | |
(sql-port 3306) | |
(sql-server "localhost") | |
(sql-user "root") | |
(sql-password "password") | |
(sql-database "sakila")) | |
; (server2 (sql-product 'mysql) | |
; (sql-port 3306) | |
; (sql-server "localhost") | |
; (sql-user "root") | |
; (sql-password "password") | |
; (sql-database "db2")) | |
)) | |
;; define function to enable server1 | |
(defun my-sql-server1 () | |
(interactive) | |
(my-sql-connect 'mysql 'server1)) | |
;; define function to enable server2 | |
;(defun my-sql-server2 () | |
; (interactive) | |
; (my-sql-connect 'mysql 'server2)) | |
(defun my-sql-connect (product connection) | |
;; remember to set the sql-product, otherwise, it will fail for the first time | |
;; you call the function | |
(setq sql-product product) | |
(sql-connect connection)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment