Skip to content

Instantly share code, notes, and snippets.

@ship561
Last active February 26, 2021 18:31
Show Gist options
  • Save ship561/3691502 to your computer and use it in GitHub Desktop.
Save ship561/3691502 to your computer and use it in GitHub Desktop.
init file for my emacs setup
;;; init.el --- Where all the magic begins
;;
;; Part of the Emacs Starter Kit
;;
;; This is the first thing to get loaded.
;;
;; "Emacs outshines all other editing software in approximately the
;; same way that the noonday sun does the stars. It is not just bigger
;; and brighter; it simply makes everything else vanish."
;; -Neal Stephenson, "In the Beginning was the Command Line"
;; Turn off mouse interface early in startup to avoid momentary display
;; You really don't need these; trust me.
;;(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))
;; Load path etc.
(setq dotfiles-dir (file-name-directory
(or (buffer-file-name) load-file-name)))
;; Load up ELPA, the package manager
(add-to-list 'load-path dotfiles-dir)
(add-to-list 'load-path (concat dotfiles-dir "/elpa-to-submit"))
(setq autoload-file (concat dotfiles-dir "loaddefs.el"))
(setq package-user-dir (concat dotfiles-dir "elpa"))
(setq custom-file (concat dotfiles-dir "custom.el"))
(require 'package)
(add-to-list 'package-archives
'("marmalade" . "http://marmalade-repo.org/packages/"))
(add-to-list 'package-archives
'("melpa" . "http://melpa.org/packages/") t)
(package-initialize)
(require 'starter-kit-elpa)
;; These should be loaded on startup rather than autoloaded on demand
;; since they are likely to be used in every session
(require 'cl)
(require 'saveplace)
(require 'ffap)
(require 'uniquify)
(require 'ansi-color)
(require 'recentf)
(require 'uniquify)
;; backport some functionality to Emacs 22 if needed
(require 'dominating-file)
;; Load up starter kit customizations
(require 'starter-kit-defuns)
(require 'starter-kit-bindings)
(require 'starter-kit-misc)
(require 'starter-kit-registers)
(require 'starter-kit-eshell)
(require 'starter-kit-lisp)
(require 'starter-kit-perl)
(require 'starter-kit-ruby)
(require 'starter-kit-js)
(regen-autoloads)
(load custom-file 'noerror)
;; You can keep system- or user-specific customizations here
(setq system-specific-config (concat dotfiles-dir system-name ".el")
user-specific-config (concat dotfiles-dir user-login-name ".el")
user-specific-dir (concat dotfiles-dir user-login-name))
(add-to-list 'load-path user-specific-dir)
(if (file-exists-p system-specific-config) (load system-specific-config))
(if (file-exists-p user-specific-dir)
(mapc #'load (directory-files user-specific-dir nil ".*el$")))
(if (file-exists-p user-specific-config) (load user-specific-config))
;;backup stuff
(setq make-backup-files t ; backup of a file the first time it is saved.
backup-by-copying t ; don't clobber symlinks
version-control t ; version numbers for backup files
delete-old-versions t ; delete excess backup files silently
delete-by-moving-to-trash t
kept-old-versions 6 ; oldest versions to keep when a new numbered backup is made (default: 2)
kept-new-versions 9 ; newest versions to keep when a new numbered backup is made (default: 2)
auto-save-default t ; auto-save every buffer that visits a file
)
;;color theme
;(require 'color-theme-tango)
;(color-theme-tango)
(require 'color-theme)
(require 'color-theme-solarized)
(color-theme-solarized-dark)
(defun unfill-paragraph ()
(interactive)
(let ((fill-column (point-max)))
(fill-paragraph nil)))
(defun unfill-region ()
(interactive)
(let ((fill-column (point-max)))
(fill-region (region-beginning) (region-end) nil)))
(defun kill-to-beginning-of-line ()
"Delete from current point to beginning of line"
(interactive)
(save-excursion
(let ( (beg (point)) )
(beginning-of-line)
(delete-region beg (point)))))
(global-set-key (kbd "M-Q") 'unfill-paragraph)
(global-set-key [?\C-u] 'kill-to-beginning-of-line)
(require 'wc)
(global-set-key (kbd "M-=") 'wc)
;;paste key binding redefine
(global-set-key (kbd "C-v") 'yank)
(global-set-key "\C-f" 'forward-sexp)
(global-set-key "\C-b" 'backward-sexp)
(global-set-key (kbd "C-;") 'comment-or-uncomment-region)
;; Unbind Pesky Sleep Button
(global-unset-key [(control z)])
(global-unset-key [(control x)(control z)])
;;imenu to call up function names
(global-set-key [mouse-8] 'imenu)
;; easy spell check
(global-set-key (kbd "<f8>") 'ispell-word)
(global-set-key (kbd "C-S-<f8>") 'flyspell-mode)
(global-set-key (kbd "C-M-<f8>") 'flyspell-buffer)
(global-set-key (kbd "C-<f8>") 'flyspell-check-previous-highlighted-word)
(defun flyspell-check-next-highlighted-word ()
"Custom function to spell check next highlighted word"
(interactive)
(flyspell-goto-next-error)
(ispell-word)
)
(global-set-key (kbd "M-<f8>") 'flyspell-check-next-highlighted-word)
;;pomodoro
(global-set-key (kbd "<f12>") 'tomatinho)
;;ralee mode settings
(add-to-list 'load-path (concat dotfiles-dir "ralee-0.61/elisp"))
(autoload 'ralee-mode "ralee-mode" "Yay! RNA things" t)
(setq auto-mode-alist (cons '("\\.sto$" . ralee-mode) auto-mode-alist))
;;org mode load path
(add-to-list 'load-path (concat dotfiles-dir "org-mode/lisp"))
(add-to-list 'load-path (concat dotfiles-dir "org-mode/contrib/lisp"))
;; cider
(add-to-list 'load-path (concat dotfiles-dir "cider"))
(add-to-list 'load-path (concat dotfiles-dir "clojure-mode"))
(require 'clojure-mode)
(require 'clojure-mode-extra-font-locking)
(require 'cider)
(setq cider-repl-use-clojure-font-lock t)
(setq cider-show-error-buffer 'except-in-repl) ; or
(add-hook 'cider-mode-hook 'cider-turn-on-eldoc-mode)
(setq cider-repl-display-in-current-window t)
(setq cider-prefer-local-resources t)
(setq cider-repl-wrap-history t)
(setq cider-repl-history-size 1000) ; the default is 500
(setq cider-repl-history-file "~/.lein-repl-history")
;; make repl highlighting same as clojure-mode highlighting
;; (add-hook 'cider-repl-mode-hook (lambda ()
;; (set-syntax-table clojure-mode-syntax-table)))
;; (add-hook 'cider-repl-mode-hook
;; (lambda () (font-lock-mode nil)
;; (clojure-font-lock-setup)
;; (font-lock-mode t)))
(eval-after-load 'clojure-mode
'(font-lock-add-keywords
'clojure-mode
(mapcar
(lambda (pair)
`(,(car pair)
(0 (progn (compose-region
(match-beginning 0) (match-end 0)
,(cadr pair))
nil))))
`(("\\<\\\(fn\\\) " ?ƒ)
("\\<\\\(comp\\) " ?∘)
("\\<\\\(partial\\) " ?þ)
("\\<\\\(complement\\) " ?¬)))
t))
(require 'highlight-parentheses)
(add-hook 'clojure-mode-hook 'highlight-parentheses-mode)
(add-hook 'cider-repl-mode-hook 'highlight-parentheses-mode)
;; Turn off paredit mode by default
(require 'paredit)
;(add-hook 'clojure-mode-hook (lambda () disable-paredit-mode))
;(require 'smartparens)
(add-to-list 'load-path (concat dotfiles-dir "smartparens"))
(require 'smartparens-config)
(add-hook 'cider-repl-mode-hook 'smartparens-mode)
(define-key sp-keymap (kbd "M-<up>") 'sp-splice-sexp-killing-backward)
(sp-pair "(" ")" :wrap "M-(")
(define-key sp-keymap (kbd "C-k") 'sp-kill-sexp)
(define-key sp-keymap (kbd "M-d") 'sp-kill-word)
(define-key sp-keymap (kbd "M-RET") 'sp-newline)
(define-key sp-keymap (kbd "C-<right>") 'sp-forward-slurp-sexp)
(define-key sp-keymap (kbd "C-<left>") 'sp-forward-barf-sexp)
;; ess for R in emacs
(add-to-list 'load-path (concat dotfiles-dir "ess-13.05/lisp"))
(require 'ess-site)
;;clojurescript
(setq inferior-lisp-program "/home/kitia/bin/clojurescript/script/browser-repl")
(add-to-list 'auto-mode-alist '("\\.cljs$" . clojure-mode))
;;tramp mode
;;(setq tramp-default-method "ssh")
;; (defvar *roz-tramp-path*
;; "/ssh:peis@roz.bc.edu:")
;; (defvar *current-tramp-path* nil)
;; (defun connect-to-host (path port)
;; (setq *current-tramp-path* path)
;; (setq slime-from-lisp-filename-function
;; (lambda (f) f))
;; (setq slime-to-lisp-filename-function
;; (lambda (f)
;; (substring f (length *current-tramp-path*))))
;; (slime-connect "localhost" port))
;; (defun my-box-slime (port)
;; (interactive (list (read-from-minibuffer "Port: " (format "%d" 4005))))
;; (connect-to-host *roz-tramp-path* port))
;;extend clojure, slime, and tramp customization in emacs
;; (add-to-list 'load-path (concat dotfiles-dir "clojure-emacs-hacks"))
;; (require 'clojure-mode-ext)
;; (require 'clojure-mode-slime)
;; (require 'clojuredocs)
;;org capture
(setq org-directory "~/org/")
(setq org-default-notes-file (concat org-directory "/notes.org"))
(define-key global-map "\C-cr" 'org-capture)
(setq org-use-sub-superscripts "{}")
(custom-set-variables
'(ess-swv-pdflatex-commands (quote ("pdflatex" "texi2pdf" "make")))
'(ess-swv-plug-into-AUCTeX-p t)
'(ess-swv-processor (quote knitr))
'(org-agenda-files (quote ("~/org/tasks.org")))
'(org-default-notes-file "~/org/notes.org")
'(org-agenda-ndays 7)
'(org-deadline-warning-days 14)
'(org-agenda-show-all-dates t)
'(org-agenda-skip-deadline-if-done t)
'(org-agenda-skip-scheduled-if-done t)
'(org-agenda-start-on-weekday nil)
'(org-reverse-note-order t)
'(org-fast-tag-selection-single-key (quote expert))
'(org-agenda-custom-commands
(quote (("d" todo "DELEGATED" nil)
("c" todo "DONE|DEFERRED|CANCELLED" nil)
("w" todo "WAITING" nil)
("W" agenda "" ((org-agenda-ndays 21)))
("A" agenda ""
((org-agenda-skip-function
(lambda nil
(org-agenda-skip-entry-if (quote notregexp) "\\=.*\\[#A\\]")))
(org-agenda-ndays 1)
(org-agenda-overriding-header "Today's Priority #A tasks: ")))
("u" alltodo ""
((org-agenda-skip-function
(lambda nil
(org-agenda-skip-entry-if (quote scheduled) (quote deadline)
(quote regexp) "\n]+>")))
(org-agenda-overriding-header "Unscheduled TODO entries: ")))))))
(defun capture-bib (path)
(let ((name (read-string "Name: ")))
(expand-file-name (format "%s.bib" name) path)))
(setq org-capture-templates
'(("t" "Todo" entry (file+headline "~/org/tasks.org" "Tasks")
"** TODO %^{Brief Description} %?\n %u" )
("i" "Ideas" entry (file "~/org/ideas.org") "** %^{Title} %U\n%?\n" )
("b" "Bibtex citation" plain (file (capture-bib "~/research/refs/")))
("B" "Bibtex citation to all" plain (file "~/research/all.bib"))))
(setq org-todo-keyword-faces
'(
("TODO" . (:foreground "#ff4500" :weight bold))
("IN-PROGRESS" . (:foreground "yellow" :weight bold))
("WAITING" . (:foreground "purple" :weight bold))
("DONE" . (:foreground "light steel blue" :weight bold))
("READ" . (:foreground "light steel blue" :weight bold))
("NEED-NOTES" . (:foreground "yellow" :weight bold))))
(setq org-todo-keywords
'((sequence "TODO" "IN-PROGRESS" "WAITING" "DONE")))
(setq org-tag-alist
'(("reading" . ?r) ("coding" . ?c) ("analysis" . ?a) ("misc" . ?m)))
(add-hook 'org-mode-hook '(lambda ()
;; C-TAB for expanding
(local-set-key (kbd "C-<tab>")
'yas/expand-from-trigger-key)
;; keybinding for editing source code blocks
(local-set-key (kbd "C-c s e")
'org-edit-src-code)
;; keybinding for inserting code blocks
(local-set-key (kbd "C-c s i")
'org-insert-src-block)
))
(setq load-path (cons "~/.emacs.d/metaweblog/" load-path))
(setq load-path (cons "~/.emacs.d/elpa/xml-rpc-1.6.8/" load-path))
(setq load-path (cons "~/.emacs.d/org2blog/" load-path))
(require 'org2blog-autoloads)
(add-hook 'org-mode-hook
(lambda () (local-set-key (kbd "C-c d") #'org2blog/wp-post-buffer)))
(setq org2blog/wp-blog-alist
'(("wordpress"
:url "http://wing561.wordpress.com/xmlrpc.php"
:username "wing561"
;:default-title "Hello World"
;:default-categories ("org2blog" "emacs")
;:tags-as-categories nil
)
))
;;clojure literate programming
(require 'ob-clojure)
(require 'ob-tangle)
(setq org-babel-clojure-backend 'cider)
(setq org-src-fontify-natively t)
; We only need Emacs Lisp and Clojure in this tutorial:
(org-babel-do-load-languages
'org-babel-load-languages
'((emacs-lisp . t)
(clojure . t)
(R . t)))
;; Let's have pretty source code blocks
(setq org-edit-src-content-indentation 0
org-src-tab-acts-natively t
org-src-fontify-natively t
org-confirm-babel-evaluate nil)
(require 'tex)
(TeX-global-PDF-mode t)
(setq reftex-plug-into-AUCTeX t)
;; Pull in the htmlize library for pretty source code in HTML output
(require 'htmlize)
(defun org-mode-reftex-setup ()
(load-library "reftex")
(and (buffer-file-name) (file-exists-p (buffer-file-name))
(progn
;enable auto-revert-mode to update reftex when bibtex file changes on disk
(auto-revert-mode t)
(reftex-parse-all)
;add a custom reftex cite format to insert links
(reftex-set-cite-format
'((?b . "[[bib:%l][%l-bib]]")
(?n . "*** [[notes:%l][notes-%l]]")
(?p . "** [[papers:%j/%A_%y_%t][%l]]: %t\n")
(?t . "%t")
(?h . "** %t\n:PROPERTIES:\n:Custom_ID: %l\n:END:\n[[papers:%l][%l-paper]]")))))
(define-key org-mode-map (kbd "C-c )") 'reftex-citation)
(define-key org-mode-map (kbd "C-c (") 'org-mode-reftex-search))
(add-hook 'org-mode-hook 'org-mode-reftex-setup)
(defun org-mode-reftex-search ()
;;jump to the notes for the paper pointed to at from reftex search
(interactive)
(org-open-link-from-string (format "[[notes:%s]]" (first (reftex-citation t)))))
(setq org-link-abbrev-alist
'(("bib" . "~/research/all.bib::%s")
("notes" . "~/org/paper-notes.org::#%s")
("papers" . "~/Dropbox/papers/%s.pdf")))
;; Fontify source code in org-latex export to PDF
;; (require 'org-latex)
;; (setq org-export-latex-listings 'minted)
;; (add-to-list 'org-export-latex-packages-alist '("" "minted"))
;; (setq org-export-latex-custom-lang-environments
;; '(
;; (emacs-lisp "common-lispcode")
;; ))
;; (setq org-export-latex-minted-options
;; '(("fontsize" "\\scriptsize")
;; ("linenos" "false")))
;; (setq org-latex-to-pdf-process '("pdflatex -interaction nonstopmode -shell-escape -output-directory %o %f"
;; "bibtex %b"
;; "pdflatex -interaction nonstopmode -shell-escape -output-directory %o %f"
;; # "pdflatex -interaction nonstopmode -shell-escape -output-directory %o %f"))
(defun org-insert-src-block (src-code-type)
"Insert a `SRC-CODE-TYPE' type source code block in org-mode."
(interactive
(let ((src-code-types
'("emacs-lisp" "python" "C" "sh" "java" "js" "clojure" "C++" "css"
"calc" "asymptote" "dot" "gnuplot" "ledger" "lilypond" "mscgen"
"octave" "oz" "plantuml" "R" "sass" "screen" "sql" "awk" "ditaa"
"haskell" "latex" "lisp" "matlab" "ocaml" "org" "perl" "ruby"
"scheme" "sqlite")))
(list (ido-completing-read "Source code type: " src-code-types))))
(progn
(newline-and-indent)
(insert (format "#+BEGIN_SRC %s\n" src-code-type))
(newline-and-indent)
(insert "#+END_SRC\n")
(previous-line 2)
(org-edit-src-code)))
(require 'clj-refactor)
(add-hook 'clojure-mode-hook (lambda ()
(clj-refactor-mode 1)
;; insert keybinding setup here
))
(add-to-list 'load-path (concat dotfiles-dir "company-mode"))
(require 'company)
(add-hook 'after-init-hook 'global-company-mode)
;(global-company-mode)
;;(eval-after-load 'company '(add-to-list 'company-transformers
;; 'company-sort-by-occurrence))
;;(setq company-backends '(company-dabbrev (company-keywords company-dabbrev-code) company-files))
;; (defun clojure-company-backends ()
;; (setq company-backends '((company-capf company-dabbrev))))
;; (add-hook 'clojure-mode-hook 'clojure-company-backends)
;; (add-hook 'cider-repl-mode-hook 'clojure-company-backends)
;;(setq company-begin-commands '(self-insert-command org-self-insert-command c-electric-lt-gt c-electric-colon))
(setq company-idle-delay 0.2)
(setq company-tooltip-limit 10)
(setq company-minimum-prefix-length 3)
(setq company-echo-delay 0)
;(require 'pos-tip)
;(require 'popup)
;(require 'auto-complete)
;(require 'auto-complete-config)
;; (ac-config-default)
;; (global-auto-complete-mode t)
;; (setq ac-menu-height 5)
;; (setq ac-auto-start nil)
;; (setq ac-use-quick-help nil)
;; ;(define-key ac-mode-map (kbd "M-TAB") 'auto-complete)
;; (ac-set-trigger-key "TAB")
;; ;(setq ac-quick-help-delay 0.5)
;; (set-default 'ac-sources
;; '(ac-source-dictionary
;; ac-source-words-in-buffer
;; ac-source-words-in-same-mode-buffers
;; ac-source-semantic
;; ac-source-filename
;; ac-source-yasnippet))
;; (add-to-list 'load-path (concat dotfiles-dir "ac-cider"))
;; (require 'ac-cider)
;; (add-hook 'cider-mode-hook 'ac-flyspell-workaround)
;; (add-hook 'cider-mode-hook 'ac-cider-setup)
;; (add-hook 'cider-repl-mode-hook 'ac-cider-setup)
;; (eval-after-load "auto-complete"
;; '(add-to-list 'ac-modes 'cider-mode))
;; (eval-after-load "auto-complete"
;; '(add-to-list 'ac-modes 'cider-repl-mode))
;; (defun set-auto-complete-as-completion-at-point-function ()
;; (setq cider-complete-at-point '(auto-complete))
;; ;(setq cider-repl-indent-and-complete-symbol '(auto-complete))
;; )
;;(add-hook 'cider-repl-mode-hook 'set-auto-complete-as-completion-at-point-function)
;;(add-hook 'auto-complete-mode-hook 'set-auto-complete-as-completion-at-point-function)
;;(add-hook 'cider-mode-hook 'set-auto-complete-as-completion-at-point-function)
;;yasnippet
(require 'yasnippet)
(add-hook 'LaTeX-mode-hook 'yas-minor-mode-on)
(add-hook 'org-mode-hook 'yas-minor-mode-on)
(yas-reload-all)
;;yasnippet org-mode conflict
(add-hook 'org-mode-hook
(lambda ()
(org-set-local 'yas/trigger-key [tab])
(define-key yas/keymap [tab] 'yas/next-field-or-maybe-expand)))
;;typing of emacs
(autoload 'typing-of-emacs "typing" "The Typing Of Emacs, a game." t)
;;helm
(add-to-list 'load-path (concat dotfiles-dir "helm"))
(require 'helm)
(require 'helm-config)
(defun helm-toggle-header-line ()
(if (= (length helm-sources) 1)
(set-face-attribute 'helm-source-header nil :height 0.1)
(set-face-attribute 'helm-source-header nil :height 1.0)))
(add-hook 'helm-before-initialize-hook 'helm-toggle-header-line)
(helm-autoresize-mode 1)
(setq helm-autoresize-max-height 30)
(setq helm-autoresize-min-height 30)
(setq helm-split-window-in-side-p t)
;;high
;;save desktop
(require 'minimal-session-saver)
(minimal-session-saver-install-aliases)
;;; init.el ends here
(cond
((string-equal system-type "windows-nt") ; Microsoft Windows
(progn
(message "Microsoft Windows") )
)
((string-equal system-type "darwin") ; Mac OS X
(define-key cider-repl-mode-map (kbd "C-S-<up>") 'cider-repl-backward-input)
(define-key cider-repl-mode-map (kbd "C-S-<down>") 'cider-repl-forward-input)
)
((string-equal system-type "gnu/linux") ; linux
(progn
(message "Linux") )
)
)
@ship561
Copy link
Author

ship561 commented Sep 10, 2012

disabling paredit doesn't work yet. Need to find the command to make paredit go away.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment