Skip to content

Instantly share code, notes, and snippets.

@markrwilliams
Created July 13, 2015 17:24
Show Gist options
  • Save markrwilliams/a111ca152021110c0701 to your computer and use it in GitHub Desktop.
Save markrwilliams/a111ca152021110c0701 to your computer and use it in GitHub Desktop.
# # emacs keybindings for navigation in copy mode
# markkeys ^B=Y:^F=V:h=^B:l=^F:0=^A:$=^E
# # C-space sets mark. markkeys does it in screen 4.0 and higher, but 3.9x
# # needs the bindkey command. (note the ^@ escape sequence for C-space.)
# markkeys ' '=^@
# # bindkey -m ^@ stuff ' '
# # page up and page down
# bindkey -m -k kP stuff Y
# bindkey -m -k kN stuff V
# # failed attempt to make C-space work in i-search too
# # bindkey -m ^@ eval "stuff \033" "stuff ^@"
# # special hack for C-e, since it should go *past*
# # the last char. -m means this is for copy mode only.
# bindkey -m ^e stuff "$^f"
# # C-g and other keys just quit copy mode. Esc does nothing.
# markkeys \033=\015=^G=^D=h=j=k=l=H=M=L=G=g=y=c=v=a=x=b=e=B=E=w
# markkeys @=\033
# # control arrows move by words. (set B, e, and w to F keys so that i can
# # use them to move by words, but they themselves still quit copy mode.)
# markkeys B=[:E=]:b={:e=}:w=>
# bindkey -m ^[Od stuff { #"[[}"
# bindkey -m ^[Oc stuff ] #"}]^f"
#caption always "%n(%t) : %C"
#caption always "%{= kw}%?%-Lw%?%{+b kw}%n*%t%f %?(%u)%?%{= kw}%?%+Lw%?"
#caption always "%{=r wk}%-w%{=b wb}%50>%n%f* %{-}%+Lw%<%{- Wk}"
startup_message off
# caption always "%{=r wk}%-w%{=b wb}%50>%n%f %t%{-}%+Lw%<%{- Wk}"
shelltitle ""
caption always "%{=b .}%-w%{=r .} %n %{-}%+w"
# termcapinfo xterm|xterms|xs|rxvt ti@:te@
termcapinfo xterm|mlterm 'hs:ts=\E]2;:fs=\007:ds=\E]2;mlterm\007'
defhstatus "^Et: ^En"
hardstatus off
@markrwilliams
Copy link
Author

(setq x-select-enable-clipboard nil)
(setq x-select-enable-primary t)
(setq mouse-drag-copy-region t)
;; display time in modeline
(display-time)
(savehist-mode 1)
(auto-compression-mode 1)
;; (setq column-number-mode t)
;; conkeror!
(setq browse-url-browser-function 'browse-url-generic
browse-url-generic-program "conkeror")
;; no typing yes or no
(defalias 'yes-or-no-p 'y-or-n-p)
(load "accel" t t)
(display-time)
(global-set-key "\C-x\C-m" 'execute-extended-command)
(global-set-key "\C-c\C-m" 'execute-extended-command)
(global-set-key [?\C-h] 'backward-delete-char-untabify)
(global-set-key [?\C-x ??] 'help-command)
;; (global-set-key "\C-q" 'backward-kill-word)
;; (global-set-key "\M-/" 'hippie-expand)
;; (eval-after-load "dabbrev" '(defalias 'dabbrev-expand 'hippie-expand))
;; (global-set-key "\C-h" 'backward-delete-char-untabify)

(setq windows-i-created (make-hash-table :test 'eq))

(defun record-delete-window (&optional window)
(interactive)
(let ((condemned (if (null window)
(selected-window)
window)))
(delete-window window)
(remhash condemned windows-i-created)))

(defun record-delete-other-windows (&optional window)
(interactive)
(let ((saved (if (null window)
(selected-window)
window)))
(delete-other-windows window)
(setq windows-i-created (make-hash-table :test 'eq))
(puthash saved t windows-i-created)))

(defun record-split-window-vertically (&optional size)
(interactive)
(puthash (split-window-vertically size) t windows-i-created))

(defun record-split-window-horizontally (&optional size)
(interactive)
(puthash (split-window-horizontally size) t windows-i-created))

(global-set-key "\C-x0" 'record-delete-window)
(global-set-key "\C-x1" 'record-delete-other-windows)
(global-set-key "\C-x2" 'record-delete-other-windows)
(global-set-key "\C-x2" 'record-split-window-vertically)
(global-set-key "\C-x3" 'record-split-window-horizontally)

(defadvice quit-window (after close-if-automatically-created activate)
"delete the window if i didn't create it."
(let ((window (selected-window)))
(if (and (not (gethash window windows-i-created)) (not (one-window-p)))
(delete-window window))))

(if (fboundp 'scroll-bar-mode) (scroll-bar-mode -1))
(if (fboundp 'tool-bar-mode) (tool-bar-mode -1))
(if (fboundp 'menu-bar-mode) (menu-bar-mode -1))

;; (set-default-font "-mutt-clearlyu arabic-medium-r-normal--17-120-100-100-p-93-iso10646-1")
;; (set-default-font "-misc-fixed-medium-r-normal--14---*-c-70-iso8859-1")
(setq make-backup-files nil)
(setq-default indent-tabs-mode nil)
(setq-default tab-width 4)

;; (global-visual-line-mode)

(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.
'(ange-ftp-try-passive-mode t)
'(column-number-mode t)
'(custom-safe-themes (quote ("d677ef584c6dfc0697901a44b885cc18e206f05114c8a3b7fde674fce6180879" "e16a771a13a202ee6e276d06098bc77f008b73bbac4d526f160faa2d76c1dd0e" default)))
'(display-time-mode t)
'(inhibit-startup-screen t)
'(js2-basic-offset 4)
'(js2-highlight-level 4)
'(no-word-coding-systems (quote (("utf-8" "UTF-8.txt") ("greek-iso-8bit" "8859-7.txt") ("iso-8859-7" "8859-7.txt") ("iso-8859-1" "8859-1.txt"))))
'(no-word-default-coding "utf-8")
'(quack-programs (quote ("racket" ""racket"" "bigloo" "csi" "csi -hygienic" "gosh" "gsi" "gsi ~~/syntax-case.scm -" "guile" "kawa" "mit-scheme" "mred -z" "mzscheme" "mzscheme -M errortrace" "mzscheme -il r6rs" "mzscheme -il typed-scheme" "mzscheme3m" "mzschemecgc" "rs" "scheme" "scheme48" "scsh" "sisc" "stklos" "sxi"))))
;; (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.
;; '(default ((t (:inherit nil :stipple nil :background "white" :foreground "#000000" :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight normal :height 120 :width normal :foundry "unknown" :family "Inconsolata"))))
;; '(mumamo-background-chunk-major ((((class color) (min-colors 88) (background light)) nil)))
;; '(mumamo-background-chunk-submode1 ((((class color) (min-colors 88) (background light)) (:background "cornsilk"))))
;; '(which-func ((((class color) (min-colors 88) (background light)) nil))))

;; (add-to-list 'load-path "/usr/share/emacs/site-lisp/emacs-goodies-el/color-theme.el")
;; (require 'color-theme)

(defun reverse-video ()
"swap :foreground and :background in custom-set-faces. ugly!"
(interactive)
(let* ((custom-face-attributes (custom-face-attributes-get 'default nil))
(background (plist-get custom-face-attributes :background))
(foreground (plist-get custom-face-attributes :foreground)))
(plist-put custom-face-attributes :foreground background)
(plist-put custom-face-attributes :background foreground)
(custom-set-faces (list 'default (list (list t custom-face-attributes))))))

(server-start)

(global-visual-line-mode)

(add-to-list 'auto-mode-alist '("/mutt" . mail-mode))
;; (add-hook 'mail-mode-hook 'turn-on-auto-fill)
(add-hook
'mail-mode-hook
(lambda ()
(define-key mail-mode-map [(control c) (control c)](lambda %28%29
%28interactive%29
%28save-buffer%29
%28server-edit%29))))

;; (require 'color-theme)
;; (color-theme-aliceblue)
;; (color-theme-simple-1)

;; (defun fix-amazon-url ()
;; "Minimizes the Amazon URL under the point. You can paste an Amazon
;; URL out of your browser, put the cursor in it somewhere, and invoke
;; this method to convert it."
;; (interactive)
;; (and (search-backward "http://www.amazon.com" (point-at-bol) t)
;; (search-forward-regexp
;; ".+/([A-Z0-9]{10})/[^[:space:]\"]+" (point-at-eol) t)
;; (replace-match
;; (concat "http://www.amazon.com/o/asin/"
;; (match-string 1)
;; (match-string 3)))))

;; (defun extract-amazon-url ()
;; (interactive)
;; (and (search-backward "www.amazon.com" (point-at-bol) t)
;; (search-forward-regexp "[2F|F]*([A-Z0-9]{10,})")
;; (progn (move-beginning-of-line nil)
;; (insert (concat "http://www.amazon.com/o/asin/"
;; (match-string 1)))
;; (kill-line))))

(setq load-path (cons "~/elisp" load-path))
(require 'undo-tree)
(require 'nice-light)
(require 'cython-mode)
(nice-light)

(global-undo-tree-mode)
(require 'browse-kill-ring)
(require 'lcomp)
;; (require 'flyflakes)

(setq tramp-default-method "scp")

;; modes
;; lisp mode
(add-hook 'lisp-interaction-mode-hook (lambda ()
(local-set-key "\C-j" 'newline-and-indent)))

(add-hook 'python-mode-hook
(lambda ()
(local-set-key """ 'electric-pair)
(local-set-key "'" 'electric-pair)
(local-set-key "(" 'electric-pair)
(local-set-key "[" 'electric-pair)
(local-set-key "{" 'electric-pair)))

(add-hook 'python-mode-hook (lambda ()
(local-set-key "\C-c\C-e"
'python-end-of-block)))
(add-hook 'c-mode-hook
(lambda ()
(local-set-key """ 'electric-pair)
(local-set-key "'" 'electric-pair)
(local-set-key "(" 'electric-pair)
(local-set-key "[" 'electric-pair)
(local-set-key "{" 'electric-pair)))

(defun electric-pair ()
(interactive)
(let (parens-require-spaces) (insert-pair)))

;; ruby stuff
(autoload 'ruby-mode "ruby-mode"
"Mode for editing ruby source files" t)
(setq auto-mode-alist
(append '((".rb$" . ruby-mode)) auto-mode-alist))
(setq interpreter-mode-alist (append '(("ruby" . ruby-mode))
interpreter-mode-alist))
(autoload 'run-ruby "inf-ruby"
"Run an inferior Ruby process")
(autoload 'inf-ruby-keys "inf-ruby"
"Set local key defs for inf-ruby in ruby-mode")
(add-hook 'ruby-mode-hook
'(lambda ()
(inf-ruby-keys)
))

;; php mode
(defun setup-php ()
(c-set-style "stroustrup"))
(add-hook 'php-mode-hook 'setup-php)
(autoload 'php-mode "php-mode" nil t)
(add-to-list 'auto-mode-alist '(".php$" . php-mode))

;; org mode
(add-hook 'org-mode-hook (lambda ()
(local-set-key "\C-\M-p" 'org-metaup)
(local-set-key "\C-\M-n" 'org-metadown)
(local-set-key "\C-\M-b" 'org-metaleft)
(local-set-key "\C-\M-f" 'org-metaright)
(local-set-key "\C-cb" 'org-shiftleft)
(local-set-key "\C-cf" 'org-shiftright)))
(add-hook 'org-mode-hook 'turn-on-font-lock)
(require 'org-exp-blocks)
(require 'ob-dot)
(setq user-mail-address "markrwilliams@gmail.com")
(require 'org-latex)
(unless (boundp 'org-export-latex-classes)
(setq org-export-latex-classes nil))
(add-to-list 'org-export-latex-classes
'("article"
"\documentclass{article}"
("\section{%s}" . "\section_{%s}")
("\subsection{%s}" . "\subsection_{%s}")
("\subsubsection{%s}" . "\subsubsection_{%s}")
("\paragraph{%s}" . "\paragraph_{%s}")
("\subparagraph{%s}" . "\subparagraph*{%s}")))

(setq org-export-latex-default-packages-alist '(("AUTO" "inputenc" t)
("T1" "fontenc" t)
("" "fixltx2e" nil)
("" "graphicx" t)
("" "longtable" nil)
("" "float" nil)
("" "wrapfig" nil)
("" "soul" t)
("" "textcomp" t)
("" "marvosym" t)
("" "wasysym" t)
("" "latexsym" t)
("" "amssymb" t)
("linkcolor=blue, colorlinks=true" "hyperref" nil)
"\tolerance=1000"))
(setq org-export-latex-listings 'minted)
(add-to-list 'org-export-latex-packages-alist '("" "minted"))

(add-hook 'org-babel-after-execute-hook 'org-display-inline-images)

(setq org-babel-load-languages (quote ((emacs-lisp . t)
(dot . t)
(ditaa . t)
(R . t)
(python . t)
(ruby . t)
(gnuplot . t)
(clojure . t)
(sh . t))))
(setq org-confirm-babel-evaluate nil)

;; actionscript
(autoload 'actionscript-mode "actionscript-mode-haas-5.6.el" t)
(add-to-list 'auto-mode-alist '(".[Aa][Ss]" . actionscript-mode))

;; csv mode
(autoload 'csv-mode "csv-mode"
"Major mode for editing comma-separated value files." t)
(add-to-list 'auto-mode-alist '(".[Cc][Ss][Vv]'" . csv-mode))

;; nxhtml mode
;; (setq mumamo-background-colors nil)
(load "~/elisp/nxhtml/autostart.el")
(require 'jinja)
(add-to-list 'auto-mode-alist '(".[Hh][Tt][Mm][Ll]$'" . jinja-nxhtml-mumamo))
(add-hook 'nxhtml-mode-hook (lambda ()
(setq popcmp-completion-style 'emacs-default)
(popcmp-group-alternatives-toggle)))

(eval-after-load "mumamo"
'(setq mumamo-per-buffer-local-vars
(delq 'buffer-file-name mumamo-per-buffer-local-vars)))

;; javascript mode & moz repl
(autoload 'moz-minor-mode "moz" "mozrepl minor and inferior modes" t)

(autoload 'js2-mode "js2" nil t)
(add-to-list 'auto-mode-alist '(".js$" . js2-mode))
(setq js2-bounce-indent-flag nil)

(add-hook 'js2-mode-hook 'js2-custom-setup)
(defun js2-custom-setup ()
(moz-minor-mode 1))

;; here's espresso
;; (autoload 'espresso-mode "espresso" "Start espresso-mode" t)
;; (add-to-list 'auto-mode-alist '(".js$" . espresso-mode))
;; (add-to-list 'auto-mode-alist '(".json$" . espresso-mode))

;; django related stuff here
(require 'uniquify)
(setq uniquify-buffer-name-style 'forward)

;; (require 'ido)
;; (ido-mode t)
;; (require 'iswitchb-mode)
(iswitchb-mode t)

;; noword!
(autoload 'no-word "no-word" nil t)
(add-to-list 'auto-mode-alist '(".doc'" . no-word))

(require 'org-install)
(setq org-log-done t)

(require 'quack)

;; (require 'fit-frame)

;; (require 'autofit-frame)
;; (add-hook 'after-make-frame-functions 'fit-frame)
(require 'sr-speedbar)
(global-set-key (kbd "s-s") 'sr-speedbar-toggle)

(require 'dired-details)
(dired-details-install)

(add-to-list 'auto-mode-alist '(".org$" . org-mode))

;; keymaps
(define-key global-map "\C-xp" '(lambda () (interactive) (other-window -1))) ;makes C-x p do C-x o backwards
(define-key global-map "\C-cl" 'org-store-link)
(define-key global-map "\C-ca" 'org-agenda)

;; keyboard macros
(fset 'articles-needed
"\C-[>\C-rauth\C-m\C-[da\C-?editor\C-j\C-[1\C-iARTICLES? \C-r@book\C-m")

(fset 'php-preamble
"\C-p\C-p")

(defun dec-read (digit-string radix)
(let ((digits-key "0123456789abcdef"))
(labels ((recur-thru (string-list)
(if (and
(position (car string-list) digits-key)
string-list)
(+ (position (car string-list) digits-key) (* radix (recur-thru (cdr string-list))))
0)))
(recur-thru (reverse (string-to-list digit-string))))))

(defun set-python-path ()
"Sets the PYTHONPATH environment variable, so the inferior
Python shell's import system works usefully"
(interactive)
(setenv "PYTHONPATH"
(read-from-minibuffer "Directory: " default-directory)))

(defun create-tags (dir-name)
"Create tags file."
(interactive "DDirectory: ")
(shell-command
(format "etags -f %s/TAGS -e -R %s" dir-name (directory-file-name dir-name))))

(setq disabled-command-function nil)

(require 'less-mode)
(setq visible-bell t)

(add-to-list 'load-path "~/src/cl/slime")
(setq inferior-lisp-program "/usr/bin/sbcl")
(require 'slime)
(slime-setup '(slime-fancy))

;; (define-key inferior-python-mode-map "\C-c\t" 'python-complete-symbol)

(add-hook 'c-mode-common-hook
(lambda()
(add-hook 'local-write-file-hooks
'(lambda()
(save-excursion
(delete-trailing-whitespace))))))

(add-hook 'before-save-hook 'delete-trailing-whitespace)

;; (add-to-list 'load-path "~/src/go/src/github.com/dougm/goflymake")
;; (require 'go-flymake)
;; (require 'flash-paren)

(defun python-swap-quotes ()
(interactive)
(save-excursion
(let ((state (syntax-ppss)))
(when (eq 'string (syntax-ppss-context state))
(let* ((left (nth 8 state))
(right (1- (scan-sexps left 1)))
(newquote (if (= ?' (char-after left))
?" ?')))
(dolist (loc (list left right))
(goto-char loc)
(delete-char 1)
(insert-char newquote 1)))))))

(setq pytest-global-name "py.test")
(add-hook 'python-mode-hook (lambda ()
(require 'pytest)
(require 'pyvenv)
(local-unset-key "\C-c\C-s")
(local-set-key "\C-c\C-s"
'python-swap-quotes)
(local-set-key (kbd "M-n")
'flycheck-next-error)
(local-set-key (kbd "M-p")
'flycheck-previous-error)
(local-set-key (kbd "\C-ca") 'pytest-all)
(local-set-key (kbd "\C-cm") 'pytest-module)
(local-set-key (kbd "\C-c.") 'pytest-one)
(local-set-key (kbd "\C-cd") 'pytest-directory)
(local-set-key (kbd "\C-cpa") 'pytest-pdb-all)
(local-set-key (kbd "\C-cpm") 'pytest-pdb-module)
(local-set-key (kbd "\C-cp.") 'pytest-pdb-one)
(local-set-key (kbd "\C-c\C-w") 'pyvenv-workon)))
(fset 'markdown-lb
(lambda (&optional arg)
"Keyboard macro." (interactive "p")
(just-one-space)
(kmacro-exec-ring-item
(quote ([60 98 114 47 62 return] 0 "%d"))
arg)))

(add-hook 'markdown-mode-hook (lambda ()
(local-set-key "\C-x!"
'markdown-lb)))

(defvar hexcolour-keywords
'(("#[aAbBcCdDeEfF[:digit:]]{6}"
(0 (put-text-property (match-beginning 0)
(match-end 0)
'face (list :background
(match-string-no-properties 0)))))))

(require 'cl)
(defun hexcolour-luminance (color)
"Calculate the luminance of a color string (e.g. "#ffaa00", "blue").
This is 0.3 red + 0.59 green + 0.11 blue and always between 0 and 255."
(let* ((values (x-color-values color))
(r (car values))
(g (cadr values))
(b (caddr values)))
(floor (+ (* .3 r) (* .59 g) (* .11 b)) 256)))

(defun hexcolour-add-to-font-lock ()
(interactive)
(font-lock-add-keywords nil
((,(concat "#[0-9a-fA-F]\\{3\\}[0-9a-fA-F]\\{3\\}?\\|" (regexp-opt (x-defined-colors) 'words)) (0 (let ((colour (match-string-no-properties 0))) (put-text-property (match-beginning 0) (match-end 0) 'face((:foreground ,(if (> 128.0 (hexcolour-luminance colour))
"white" "black"))
(:background ,colour)))))))))

(add-hook 'css-mode-hook 'hexcolour-add-to-font-lock)

(require 'package)
(add-to-list 'package-archives
'("melpa" .
"http://melpa.org/packages/"))
(package-initialize)
(ffap-bindings)
(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.
'(mumamo-background-chunk-major ((((class color) (min-colors 88) (background light)) nil))))
(load-theme 'solarized-light)
(add-hook 'after-init-hook #'global-flycheck-mode)
(provide '.emacs)
(set-face-attribute 'default nil :height 100)
;;; .emacs ends here
(require 'popwin)
(popwin-mode 1)

(eval-after-load 'tramp
'(vagrant-tramp-enable))

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