Skip to content


Subversion checkout URL

You can clone with
Download ZIP
tree: d130ab2399
Fetching contributors…

Cannot retrieve contributors at this time

3626 lines (3005 sloc) 114.661 kB
;;;_. Initialization
(setq message-log-max 16384)
(defconst emacs-start-time (current-time))
(unless noninteractive
(message "Loading %s..." load-file-name))
(load (expand-file-name "load-path" (file-name-directory load-file-name)))
(require 'use-package)
(setq use-package-verbose (null byte-compile-current-file)))
;;;_ , Utility macros and functions
(defmacro hook-into-modes (func modes)
`(dolist (mode-hook ,modes)
(add-hook mode-hook ,func)))
(defun system-idle-time ()
(call-process "ioreg" nil (current-buffer) nil
"-c" "IOHIDSystem" "-d" "4" "-S")
(goto-char (point-min))
(and (re-search-forward "\"HIDIdleTime\" = \\([0-9]+\\)" nil t)
(/ (float (string-to-number (match-string 1)))
(defun quickping (host)
(= 0 (call-process "/sbin/ping" nil nil nil "-c1" "-W50" "-q" host)))
(defun cleanup-term-log ()
"Do not show ^M in files containing mixed UNIX and DOS line endings."
(require 'ansi-color)
(ansi-color-apply-on-region (point-min) (point-max))
(goto-char (point-min))
(while (re-search-forward "\\(.\\|
$\\|P.+\\\\\n\\)" nil t)
(overlay-put (make-overlay (match-beginning 0) (match-end 0))
'invisible t))
(set-buffer-modified-p nil))
(add-hook 'find-file-hooks
(lambda ()
(if (string-match "/\\.iTerm/.*\\.log\\'"
;;;_ , Read system environment
(let ((plist (expand-file-name "~/.MacOSX/environment.plist")))
(when (file-readable-p plist)
(let ((dict (cdr (assq 'dict (cdar (xml-parse-file plist))))))
(while dict
(if (and (listp (car dict))
(eq 'key (caar dict)))
(setenv (car (cddr (car dict)))
(car (cddr (car (cddr dict))))))
(setq dict (cdr dict))))
;; Configure exec-path based on the new PATH
(setq exec-path nil)
(mapc (apply-partially #'add-to-list 'exec-path)
(nreverse (split-string (getenv "PATH") ":")))))
;;;_ , Load customization settings
(defvar running-alternate-emacs nil)
(if (string-match (concat "/Applications/\\(Misc/\\)?"
(let ((settings (with-temp-buffer
(expand-file-name "settings.el" user-emacs-directory))
(goto-char (point-min))
(read (current-buffer))))
(suffix (downcase (match-string 2 invocation-directory))))
(setq running-alternate-emacs t
(replace-regexp-in-string "/data/" (format "/data-%s/" suffix)
(let* ((regexp "/\\.emacs\\.d/data/")
(replace (format "/.emacs.d/data-%s/" suffix)))
(dolist (setting settings)
(let ((value (and (listp setting)
(nth 1 (nth 1 setting)))))
(if (and (stringp value)
(string-match regexp value))
(setcar (nthcdr 1 (nth 1 setting))
(replace-regexp-in-string regexp replace value)))))
(eval settings)))
(load (expand-file-name "settings" user-emacs-directory)))
;;;_ , Enable disabled commands
(put 'downcase-region 'disabled nil) ; Let downcasing work
(put 'erase-buffer 'disabled nil)
(put 'eval-expression 'disabled nil) ; Let ESC-ESC work
(put 'narrow-to-page 'disabled nil) ; Let narrowing work
(put 'narrow-to-region 'disabled nil) ; Let narrowing work
(put 'set-goal-column 'disabled nil)
(put 'upcase-region 'disabled nil) ; Let upcasing work
;;;_. Keybindings
;; Main keymaps for personal bindings are:
;; C-x <letter> primary map (has many defaults too)
;; C-c <letter> secondary map (not just for mode-specific)
;; C-. <letter> tertiary map
;; M-g <letter> goto map
;; M-s <letter> search map
;; M-o <letter> markup map (even if only temporarily)
;; C-<capital letter>
;; M-<capital letter>
;; A-<anything>
;; M-A-<anything>
;; Single-letter bindings still available:
;; C- ,'";:?<>|!#$%^&*`~ <tab>
;; M- ?#
;;;_ , global-map
;;;_ . C-?
(defvar ctl-period-map)
(define-prefix-command 'ctl-period-map)
(bind-key "C-." 'ctl-period-map)
(bind-key* "<C-return>" 'other-window)
(defun collapse-or-expand ()
(if (> (length (window-list)) 1)
(bind-key "C-z" 'collapse-or-expand)
;;;_ . M-?
(defadvice async-shell-command (before uniqify-running-shell-command activate)
(let ((buf (get-buffer "*Async Shell Command*")))
(if buf
(let ((proc (get-buffer-process buf)))
(if (and proc (eq 'run (process-status proc)))
(with-current-buffer buf
(bind-key "M-!" 'async-shell-command)
(bind-key "M-/" 'dabbrev-expand)
(bind-key "M-'" 'insert-pair)
(bind-key "M-\"" 'insert-pair)
(defun align-code (beg end &optional arg)
(interactive "rP")
(if (null arg)
(align beg end)
(let ((end-mark (copy-marker end)))
(indent-region beg end-mark nil)
(align beg end-mark))))
(bind-key "M-[" 'align-code)
(bind-key "M-`" 'other-frame)
(bind-key "M-j" 'delete-indentation-forward)
(bind-key "M-J" 'delete-indentation)
(bind-key "M-W" 'mark-word)
(defun mark-line (&optional arg)
(interactive "p")
(let ((here (point)))
(dotimes (i arg)
(set-mark (point))
(goto-char here)))
(bind-key "M-L" 'mark-line)
(defun mark-sentence (&optional arg)
(interactive "P")
(mark-end-of-sentence arg))
(bind-key "M-S" 'mark-sentence)
(bind-key "M-X" 'mark-sexp)
(bind-key "M-H" 'mark-paragraph)
(bind-key "M-D" 'mark-defun)
(bind-key "M-g c" 'goto-char)
(bind-key "M-g l" 'goto-line)
(defun delete-indentation-forward ()
(delete-indentation t))
(bind-key "M-s n" 'find-name-dired)
(bind-key "M-s o" 'occur)
(bind-key "A-M-w" 'copy-code-as-rtf)
;;;_ . M-C-?
(bind-key "<C-M-backspace>" 'backward-kill-sexp)
(defun isearch-backward-other-window ()
(call-interactively 'isearch-backward))
(bind-key "C-M-r" 'isearch-backward-other-window)
(defun isearch-forward-other-window ()
(call-interactively 'isearch-forward))
(bind-key "C-M-s" 'isearch-forward-other-window)
;; Some further isearch bindings
(bind-key "C-c" 'isearch-toggle-case-fold isearch-mode-map)
(bind-key "C-t" 'isearch-toggle-regexp isearch-mode-map)
(bind-key "C-^" 'isearch-edit-string isearch-mode-map)
(bind-key "C-i" 'isearch-complete isearch-mode-map)
;;;_ . A-?
(define-key key-translation-map (kbd "A-TAB") (kbd "C-TAB"))
;;;_ , ctl-x-map
;;;_ . C-x ?
(bind-key "C-x B" 'ido-switch-buffer-other-window)
(bind-key "C-x d" 'delete-whitespace-rectangle)
(bind-key "C-x F" 'set-fill-column)
(bind-key "C-x t" 'toggle-truncate-lines)
;;;_ . C-x C-?
(defun duplicate-line ()
"Duplicate the line containing point."
(let (line-text)
(goto-char (line-beginning-position))
(let ((beg (point)))
(goto-char (line-end-position))
(setq line-text (buffer-substring beg (point))))
(if (eobp)
(insert ?\n)
(open-line 1)
(insert line-text))))
(bind-key "C-x C-d" 'duplicate-line)
(bind-key "C-x C-e" 'pp-eval-last-sexp)
(bind-key "C-x C-n" 'next-line)
(defun find-alternate-file-with-sudo (filename)
(list (read-file-name "Find alternate file: " nil
nil nil (concat "/sudo::" (buffer-file-name)))))
(find-alternate-file filename))
(bind-key "C-x C-v" 'find-alternate-file-with-sudo)
;;;_ . C-x M-?
(bind-key "C-x M-n" 'set-goal-column)
(defun refill-paragraph (arg)
(interactive "*P")
(let ((fun (if (memq major-mode '(c-mode c++-mode))
(or fill-paragraph-function
(width (if (numberp arg) arg))
prefix beg end)
(forward-paragraph 1)
(setq end (copy-marker (- (point) 2)))
(forward-line -1)
(let ((b (point)))
(skip-chars-forward "^A-Za-z0-9`'\"(")
(setq prefix (buffer-substring-no-properties b (point))))
(backward-paragraph 1)
(if (eolp)
(setq beg (point-marker))
(while (< (point) end)
(delete-indentation 1)
(let ((fill-column (or width fill-column))
(fill-prefix prefix))
(if prefix
(setq fill-column
(- fill-column (* 2 (length prefix)))))
(funcall fun nil)
(goto-char beg)
(insert prefix)
(funcall fun nil))
(goto-char (+ end 2))))
(bind-key "C-x M-q" 'refill-paragraph)
;;;_ , mode-specific-map
;;;_ . C-c ?
(bind-key "C-c <tab>" 'ff-find-other-file)
(bind-key "C-c SPC" 'just-one-space)
;; inspired by Erik Naggum's `recursive-edit-with-single-window'
(defmacro recursive-edit-preserving-window-config (body)
"*Return a command that enters a recursive edit after executing BODY.
Upon exiting the recursive edit (with\\[exit-recursive-edit] (exit)
or \\[abort-recursive-edit] (abort)), restore window configuration
in current frame."
`(lambda ()
"See the documentation for `recursive-edit-preserving-window-config'."
(bind-key "C-c 0"
(recursive-edit-preserving-window-config (delete-window)))
(bind-key "C-c 1"
(if (one-window-p 'ignore-minibuffer)
(error "Current window is the only window in its frame")
(defun delete-current-line (&optional arg)
(interactive "p")
(let ((here (point)))
(kill-line arg)
(goto-char here)))
(bind-key "C-c d" 'delete-current-line)
(bind-key "C-c e E" 'elint-current-buffer)
(defun do-eval-buffer ()
(call-interactively 'eval-buffer)
(message "Buffer has been evaluated"))
(bind-key "C-c e b" 'do-eval-buffer)
(bind-key "C-c e c" 'cancel-debug-on-entry)
(bind-key "C-c e d" 'debug-on-entry)
(bind-key "C-c e e" 'toggle-debug-on-error)
(bind-key "C-c e f" 'emacs-lisp-byte-compile-and-load)
(bind-key "C-c e j" 'emacs-lisp-mode)
(bind-key "C-c e l" 'find-library)
(bind-key "C-c e r" 'eval-region)
(bind-key "C-c e s" 'scratch)
(bind-key "C-c e v" 'edit-variable)
(defun find-which (name)
(interactive "sCommand name: ")
(substring (shell-command-to-string (format "which %s" name)) 0 -1)))
(bind-key "C-c e w" 'find-which)
(bind-key "C-c e z" 'byte-recompile-directory)
(bind-key "C-c f" 'flush-lines)
(bind-key "C-c g" 'goto-line)
(bind-key "C-c k" 'keep-lines)
(defvar emacs-min-top)
(defvar emacs-min-left)
(defvar emacs-min-height)
(defvar emacs-min-width))
(unless noninteractive
(if running-alternate-emacs
(defvar emacs-min-top (if (= 1050 (x-display-pixel-height)) 574 722))
(defvar emacs-min-left 5)
(defvar emacs-min-height 25)
(defvar emacs-min-width 80))
(defvar emacs-min-top 22)
(defvar emacs-min-left (- (x-display-pixel-width) 918))
(defvar emacs-min-height (if (= 1050 (x-display-pixel-height)) 55 64))
(defvar emacs-min-width 100)))
(defun emacs-min ()
(set-frame-parameter (selected-frame) 'fullscreen nil)
(set-frame-parameter (selected-frame) 'vertical-scroll-bars nil)
(set-frame-parameter (selected-frame) 'horizontal-scroll-bars nil)
(set-frame-parameter (selected-frame) 'top emacs-min-top)
(set-frame-parameter (selected-frame) 'left emacs-min-left)
(set-frame-parameter (selected-frame) 'height emacs-min-height)
(set-frame-parameter (selected-frame) 'width emacs-min-width)
(when running-alternate-emacs
(set-background-color "grey85")
(set-face-background 'fringe "gray80")))
(if window-system
(add-hook 'after-init-hook 'emacs-min))
(defun emacs-max ()
(if t
(set-frame-parameter (selected-frame) 'fullscreen 'fullboth)
(set-frame-parameter (selected-frame) 'vertical-scroll-bars nil)
(set-frame-parameter (selected-frame) 'horizontal-scroll-bars nil))
(set-frame-parameter (selected-frame) 'top 26)
(set-frame-parameter (selected-frame) 'left 2)
(set-frame-parameter (selected-frame) 'width
(floor (/ (float (x-display-pixel-width)) 9.15)))
(if (= 1050 (x-display-pixel-height))
(set-frame-parameter (selected-frame) 'height
(if (>= emacs-major-version 24)
(set-frame-parameter (selected-frame) 'height
(if (>= emacs-major-version 24)
(defun emacs-toggle-size ()
(if (> (cdr (assq 'width (frame-parameters))) 100)
(bind-key "C-c m" 'emacs-toggle-size)
(defcustom user-initials nil
"*Initials of this user."
#'(lambda (symbol value)
(if (fboundp 'font-lock-add-keywords)
#'(lambda (mode)
mode (list (list (concat "\\<\\(" value " [^:\n]+\\):")
1 font-lock-warning-face t))))
'(c-mode c++-mode emacs-lisp-mode lisp-mode
python-mode perl-mode java-mode groovy-mode)))
(set symbol value))
:type 'string
:group 'mail)
(defun insert-user-timestamp ()
"Insert a quick timestamp using the value of `user-initials'."
(insert (format "%s (%s): " user-initials
(format-time-string "%Y-%m-%d" (current-time)))))
(bind-key "C-c n" 'insert-user-timestamp)
(bind-key "C-c o" 'customize-option)
(bind-key "C-c O" 'customize-group)
(bind-key "C-c q" 'fill-region)
(bind-key "C-c r" 'replace-regexp)
(bind-key "C-c s" 'replace-string)
(bind-key "C-c u" 'rename-uniquely)
(autoload 'auth-source-search "auth-source")
(defun tinify-url (url)
(interactive "sURL to shorten: ")
(let* ((api-login "jwiegley")
(car (auth-source-search :host "" :user api-login
:type 'netrc :port 80))
(flet ((message (&rest ignore)))
(let ((query
(format "format=txt&longUrl=%s&login=%s&apiKey=%s"
(url-hexify-string url) api-login api-key)))
(concat "" query)))
(goto-char (point-min))
(re-search-forward "^$")
(kill-new (buffer-substring (1+ (point)) (1- (point-max))))
(kill-buffer (current-buffer)))))))
(bind-key "C-c U" 'tinify-url)
(bind-key "C-c v" 'ffap)
(defun view-clipboard ()
(switch-to-buffer "*Clipboard*")
(let ((inhibit-read-only t))
(goto-char (point-min))
(bind-key "C-c V" 'view-clipboard)
(bind-key "C-c z" 'clean-buffer-list)
(bind-key "C-c [" 'align-regexp)
(bind-key "C-c =" 'count-matches)
(bind-key "C-c ;" 'comment-or-uncomment-region)
;;;_ . C-c C-?
(defun delete-to-end-of-buffer ()
(kill-region (point) (point-max)))
(bind-key "C-c C-z" 'delete-to-end-of-buffer)
;;;_ . C-c M-?
(defun unfill-paragraph (arg)
(interactive "*p")
(let (beg end)
(forward-paragraph arg)
(setq end (copy-marker (- (point) 2)))
(backward-paragraph arg)
(if (eolp)
(setq beg (point-marker))
(when (> (count-lines beg end) 1)
(while (< (point) end)
(goto-char (line-end-position))
(let ((sent-end (memq (char-before) '(?. ?\; ?! ??))))
(delete-indentation 1)
(if sent-end
(insert ? )))
(goto-char beg)
(while (re-search-forward "[^.;!?:]\\([ \t][ \t]+\\)" end t)
(replace-match " " nil nil nil 1))))))
(bind-key "C-c M-q" 'unfill-paragraph)
(defun unfill-region (beg end)
(interactive "r")
(setq end (copy-marker end))
(goto-char beg)
(while (< (point) end)
(unfill-paragraph 1)
;;;_ , ctl-period-map
;;;_ . C-. ?
(bind-key "C-. m" 'kmacro-keymap)
;;;_ . C-. C-i
(bind-key "C-. C-i" 'indent-rigidly)
;;;_ , help-map
(defvar lisp-find-map)
(define-prefix-command 'lisp-find-map)
(bind-key "C-h e" 'lisp-find-map)
;;;_ . C-h e ?
(bind-key "C-h e c" 'finder-commentary)
(bind-key "C-h e e" 'view-echo-area-messages)
(bind-key "C-h e f" 'find-function)
(bind-key "C-h e F" 'find-face-definition)
(defun my-describe-symbol (symbol &optional mode)
(info-lookup-interactive-arguments 'symbol current-prefix-arg))
(let (info-buf find-buf desc-buf cust-buf)
(info-lookup-symbol symbol mode)
(setq info-buf (get-buffer "*info*")))
(let ((sym (intern-soft symbol)))
(when sym
(if (functionp sym)
(find-function sym)
(setq find-buf (current-buffer))
(describe-function sym)
(setq desc-buf (get-buffer "*Help*")))
(find-variable sym)
(setq find-buf (current-buffer))
(describe-variable sym)
(setq desc-buf (get-buffer "*Help*"))
;;(customize-variable sym)
;;(setq cust-buf (current-buffer))
(flet ((switch-in-other-buffer
(when buf
(switch-to-buffer-other-window buf))))
(switch-to-buffer find-buf)
(switch-in-other-buffer desc-buf)
(switch-in-other-buffer info-buf)
;;(switch-in-other-buffer cust-buf)
(bind-key "C-h e d" 'my-describe-symbol)
(bind-key "C-h e i" 'info-apropos)
(bind-key "C-h e k" 'find-function-on-key)
(bind-key "C-h e l" 'find-library)
(defvar lisp-modes '(emacs-lisp-mode
(defvar lisp-mode-hooks
(mapcar (function
(lambda (mode)
(concat (symbol-name mode) "-hook"))))
(defun scratch ()
(let ((current-mode major-mode))
(switch-to-buffer-other-window (get-buffer-create "*scratch*"))
(goto-char (point-min))
(when (looking-at ";")
(forward-line 4)
(delete-region (point-min) (point)))
(goto-char (point-max))
(if (memq current-mode lisp-modes)
(funcall current-mode))))
(bind-key "C-h e s" 'scratch)
(bind-key "C-h e v" 'find-variable)
(bind-key "C-h e V" 'apropos-value)
;;;_. Packages
;;;_ , el-get
(use-package el-get
:disabled t
:commands (el-get
(defvar el-get-sources nil)
(defun el-get-read-status-file ()
(mapcar #'(lambda (entry)
(cons (plist-get entry :symbol)
`(status "installed" recipe ,entry)))
(defalias 'el-get-init 'ignore
"Don't use el-get for making packages available for use."))
;;;_ , cc-mode
(use-package cc-mode
:mode (("\\.h\\(h?\\|xx\\|pp\\)\\'" . c++-mode)
("\\.m\\'" . c-mode)
("\\.mm\\'" . c++-mode))
(defun llvm-info ()
(w3m-find-file "/usr/local/stow/clang-3.1/docs/llvm/html/doxygen/classllvm_1_1IRBuilder.html"))
(defun my-paste-as-check ()
(insert "/*\n")
(let ((beg (point)) end)
(setq end (point-marker))
(goto-char beg)
(while (< (point) end)
(forward-char 2)
(insert "CHECK: ")
(forward-line 1)))
(insert "*/\n")))
(defun my-c-indent-or-complete ()
(let ((class (syntax-class (syntax-after (1- (point))))))
(if (or (bolp) (and (/= 2 class)
(/= 3 class)))
(call-interactively 'indent-according-to-mode)
(if t
(call-interactively 'auto-complete)
(call-interactively 'company-complete-common)))))
(defvar printf-index 0)
(defun insert-counting-printf (arg)
(interactive "P")
(if arg
(setq printf-index 0))
(if t
(insert (format "std::cerr << \"step %d..\" << std::endl;\n"
(setq printf-index (1+ printf-index))))
(insert (format "printf(\"step %d..\\n\");\n"
(setq printf-index (1+ printf-index)))))
(forward-line -1)
(defun my-c-mode-common-hook ()
(abbrev-mode 1)
(gtags-mode 1)
(hs-minor-mode 1)
(hide-ifdef-mode 1)
(whitespace-mode 1)
(which-function-mode 1)
(auto-complete-mode 1)
(yas/minor-mode 1)
(diminish 'gtags-mode)
(diminish 'hs-minor-mode)
(diminish 'hide-ifdef-mode)
(bind-key "C-c p" 'insert-counting-printf c-mode-base-map)
(if t
(auto-complete-mode 1)
(setq ac-sources (list (if (featurep 'semantic)
(bind-key "<A-tab>" 'ac-complete c-mode-base-map))
(company-mode 1)
(bind-key "<A-tab>" 'company-complete-common c-mode-base-map))
;;(doxymacs-mode 1)
(bind-key "<return>" 'newline-and-indent c-mode-base-map)
(set (make-local-variable 'yas/fallback-behavior)
'(apply my-c-indent-or-complete . nil))
(bind-key "<tab>" 'yas/expand-from-trigger-key c-mode-base-map)
(unbind-key "M-j" c-mode-base-map)
(bind-key "C-c C-i" 'c-includes-current-file c-mode-base-map)
(bind-key "C-c C-y" 'my-paste-as-check c-mode-base-map)
(set (make-local-variable 'parens-require-spaces) nil)
(setq indicate-empty-lines t)
(setq fill-column 72)
(bind-key "M-q" 'c-fill-paragraph c-mode-base-map)
(let ((bufname (buffer-file-name)))
(when bufname
((string-match "/ledger/" bufname)
(c-set-style "ledger"))
((string-match "/ansi/" bufname)
(c-set-style "ti")
(substitute-key-definition 'fill-paragraph 'ti-refill-comment
c-mode-base-map global-map)
(bind-key "M-q" 'ti-refill-comment c-mode-base-map))
((string-match "/edg/" bufname)
(c-set-style "edg"))
(c-set-style "clang")))))
(font-lock-add-keywords 'c++-mode '(("\\<\\(assert\\|DEBUG\\)("
1 font-lock-warning-face t))))
(add-hook 'c-mode-common-hook 'my-c-mode-common-hook))
(setq c-syntactic-indentation nil)
(bind-key "#" 'self-insert-command c-mode-base-map)
(bind-key "{" 'self-insert-command c-mode-base-map)
(bind-key "}" 'self-insert-command c-mode-base-map)
(bind-key "/" 'self-insert-command c-mode-base-map)
(bind-key "*" 'self-insert-command c-mode-base-map)
(bind-key ";" 'self-insert-command c-mode-base-map)
(bind-key "," 'self-insert-command c-mode-base-map)
(bind-key ":" 'self-insert-command c-mode-base-map)
(bind-key "(" 'self-insert-command c-mode-base-map)
(bind-key ")" 'self-insert-command c-mode-base-map)
(bind-key "<" 'self-insert-command c++-mode-map)
(bind-key ">" 'self-insert-command c++-mode-map)
(use-package cedet
:disabled t
;; Add further minor-modes to be enabled by semantic-mode. See
;; doc-string of `semantic-default-submodes' for other things you can
;; use here.
(dolist (submode '(global-semantic-idle-summary-mode
(add-to-list 'semantic-default-submodes submode t))
;; Enable Semantic
(semantic-mode 1)
(when nil ; jww (2012-06-20): this kills buffers
;; if you want to enable support for gnu global
(use-package semanticdb-global)
(semanticdb-enable-gnu-global-databases 'c-mode)
(semanticdb-enable-gnu-global-databases 'c++-mode))))
(add-to-list 'c-style-alist
(indent-tabs-mode . nil)
(c-basic-offset . 3)
(c-comment-only-line-offset . (0 . 0))
. ((substatement-open before after)
. ((statement-block-intro . +)
(knr-argdecl-intro . 5)
(substatement-open . 0)
(substatement-label . 0)
(label . 0)
(case-label . +)
(statement-case-open . 0)
(statement-cont . +)
(arglist-intro . c-lineup-arglist-intro-after-paren)
(arglist-close . c-lineup-arglist)
(inline-open . 0)
(brace-list-open . 0)
. (first c-lineup-topmost-intro-cont
(c-special-indent-hook . c-gnu-impose-minimum)
(c-block-comment-prefix . "")))
(add-to-list 'c-style-alist
(indent-tabs-mode . nil)
(c-basic-offset . 2)
(c-comment-only-line-offset . (0 . 0))
. ((substatement-open before after)
. ((statement-block-intro . +)
(knr-argdecl-intro . 5)
(substatement-open . 0)
(substatement-label . 0)
(label . 0)
(case-label . +)
(statement-case-open . 0)
(statement-cont . +)
(arglist-intro . +)
(arglist-close . +)
(inline-open . 0)
(brace-list-open . 0)
. (first c-lineup-topmost-intro-cont
(c-special-indent-hook . c-gnu-impose-minimum)
(c-block-comment-prefix . "")))
(add-to-list 'c-style-alist
(indent-tabs-mode . nil)
(c-basic-offset . 2)
(c-comment-only-line-offset . (0 . 0))
. ((substatement-open before after)
. ((statement-block-intro . +)
(knr-argdecl-intro . 5)
(substatement-open . 0)
(substatement-label . 0)
(label . 0)
(case-label . 0)
(statement-case-open . 0)
(statement-cont . +)
(arglist-intro . +)
(arglist-close . +)
(inline-open . 0)
(brace-list-open . 0)
. (first c-lineup-topmost-intro-cont
(c-special-indent-hook . c-gnu-impose-minimum)
(c-block-comment-prefix . "")))
(add-to-list 'c-style-alist
(indent-tabs-mode . nil)
(c-basic-offset . 2)
(c-comment-only-line-offset . (0 . 0))
. ((substatement-open before after)
. ((statement-block-intro . +)
(knr-argdecl-intro . 5)
(substatement-open . 0)
(substatement-label . 0)
(label . 0)
(case-label . 0)
(statement-case-open . 0)
(statement-cont . +)
(arglist-intro . +)
(arglist-close . +)
(inline-open . 0)
(brace-list-open . 0)
. (first c-lineup-topmost-intro-cont
(c-special-indent-hook . c-gnu-impose-minimum)
(c-block-comment-prefix . "")))
(defun opencl ()
(find-file "~/src/ansi/opencl.c")
(find-file-noselect "~/Contracts/TI/bugslayer/cl_0603/cl_0603.c")
(find-file-noselect "~/Contracts/TI/bugslayer")
(magit-status "~/src/ansi")
(gud-gdb "gdb --fullname ~/Contracts/TI/bin/c60/acpia6x"))
(defun ti-refill-comment ()
(let ((here (point)))
(goto-char (line-beginning-position))
(let ((begin (point)) end
(marker ?-) (marker-re "\\(-----\\|\\*\\*\\*\\*\\*\\)")
(leader-width 0))
(unless (looking-at "[ \t]*/\\*[-* ]")
(search-backward "/*")
(goto-char (line-beginning-position)))
(unless (looking-at "[ \t]*/\\*[-* ]")
(error "Not in a comment"))
(while (and (looking-at "\\([ \t]*\\)/\\* ")
(setq leader-width (length (match-string 1)))
(not (looking-at (concat "[ \t]*/\\*" marker-re))))
(forward-line -1)
(setq begin (point)))
(when (looking-at (concat "[^\n]+?" marker-re "\\*/[ \t]*$"))
(setq marker (if (string= (match-string 1) "-----") ?- ?*))
(while (and (looking-at "[^\n]+?\\*/[ \t]*$")
(not (looking-at (concat "[^\n]+?" marker-re
"\\*/[ \t]*$"))))
(when (looking-at (concat "[^\n]+?" marker-re "\\*/[ \t]*$"))
(setq end (point))
(let ((comment (buffer-substring-no-properties begin end)))
(insert comment)
(goto-char (point-min))
(flush-lines (concat "^[ \t]*/\\*" marker-re "[-*]+\\*/[ \t]*$"))
(goto-char (point-min))
(while (re-search-forward "^[ \t]*/\\* ?" nil t)
(goto-char (match-beginning 0))
(delete-region (match-beginning 0) (match-end 0)))
(goto-char (point-min))
(while (re-search-forward "[ \t]*\\*/[ \t]*$" nil t)
(goto-char (match-beginning 0))
(delete-region (match-beginning 0) (match-end 0)))
(goto-char (point-min)) (delete-trailing-whitespace)
(goto-char (point-min)) (flush-lines "^$")
(set-fill-column (- 80 ; width of the text
6 ; width of "/* */"
(goto-char (point-min)) (fill-paragraph nil)
(goto-char (point-min))
(while (not (eobp))
(insert (make-string leader-width ? ) "/* ")
(goto-char (line-end-position))
(insert (make-string (- 80 3 (current-column)) ? ) " */")
(goto-char (point-min))
(insert (make-string leader-width ? )
"/*" (make-string (- 80 4 leader-width) marker) "*/\n")
(goto-char (point-max))
(insert (make-string leader-width ? )
"/*" (make-string (- 80 4 leader-width) marker) "*/\n")
(setq comment (buffer-string)))
(goto-char begin)
(delete-region begin end)
(insert comment)))
(goto-char here)))))
;;;_ , abbrev
(use-package abbrev
:commands abbrev-mode
:diminish abbrev-mode
(hook-into-modes #'abbrev-mode '(text-mode-hook))
(if (file-exists-p abbrev-file-name)
(add-hook 'expand-load-hook
(lambda ()
(add-hook 'expand-expand-hook 'indent-according-to-mode)
(add-hook 'expand-jump-hook 'indent-according-to-mode)))))
;;;_ , ace-jump-mode
(use-package ace-jump-mode
:bind ("C-. C-s" . ace-jump-mode))
;;;_ , allout
(use-package allout
:diminish allout-mode
:commands allout-mode
(defvar allout-unprefixed-keybindings nil)
(defun my-allout-mode-hook ()
(dolist (mapping '((?b . allout-hide-bodies)
(?c . allout-hide-current-entry)
(?l . allout-hide-current-leaves)
(?i . allout-show-current-branches)
(?e . allout-show-entry)
(?o . allout-show-to-offshoot)))
(bind-key (concat (format-kbd-macro allout-command-prefix)
" " (char-to-string (car mapping)))
(cdr mapping)
(if (memq major-mode lisp-modes)
(unbind-key "C-k" allout-mode-map)))
(add-hook 'allout-mode-hook 'my-allout-mode-hook)))
;;;_ , ascii
(use-package ascii
:commands (ascii-on ascii-toggle)
(defun ascii-toggle ()
(if ascii-display
(bind-key "C-c e A" 'ascii-toggle)))
;;;_ , archive-region
(use-package archive-region
:commands kill-region-or-archive-region
:bind ("C-w" . kill-region-or-archive-region))
;;;_ , auctex
(use-package tex-site
:load-path "site-lisp/auctex/preview/"
:defines (latex-help-cmd-alist
;; jww (2012-06-15): Do I want to use AucTeX for texinfo-mode?
:mode ("\\.tex\\'" . latex-mode)
(defun latex-help-get-cmd-alist () ;corrected version:
"Scoop up the commands in the index of the latex info manual.
The values are saved in `latex-help-cmd-alist' for speed."
;; mm, does it contain any cached entries
(if (not (assoc "\\begin" latex-help-cmd-alist))
(setq latex-help-cmd-alist nil)
(Info-goto-node (concat latex-help-file "Command Index"))
(goto-char (point-max))
(while (re-search-backward "^\\* \\(.+\\): *\\(.+\\)\\." nil t)
(let ((key (buffer-substring (match-beginning 1) (match-end 1)))
(value (buffer-substring (match-beginning 2)
(match-end 2))))
(add-to-list 'latex-help-cmd-alist (cons key value))))))
(use-package latex-mode
:defer t
(info-lookup-add-help :mode 'latex-mode
:regexp ".*"
:parse-rule "\\\\?[a-zA-Z]+\\|\\\\[^a-zA-Z]"
:doc-spec '(("(latex2e)Concept Index" )
("(latex2e)Command Index"))))))
;;;_ , auto-complete
(use-package auto-complete-config
:commands auto-complete-mode
:diminish auto-complete-mode
(ac-set-trigger-key "TAB")
(setq ac-use-menu-map t)
(unbind-key "C-s" ac-completing-map)))
;;;_ , autopair
(use-package autopair
:disabled t
:commands autopair-mode
:diminish autopair-mode
(hook-into-modes #'autopair-mode '(c-mode-common-hook
;;;_ , autorevert
(use-package autorevert
:commands auto-revert-mode
:diminish auto-revert-mode
(add-hook 'find-file-hook
#'(lambda ()
(auto-revert-mode 1))))
;;;_ , backup-each-save
(use-package backup-each-save
:defer t
(autoload 'backup-each-save "backup-each-save")
(add-hook 'after-save-hook 'backup-each-save)
(defun my-make-backup-file-name (file)
(make-backup-file-name-1 (file-truename file)))
(defun show-backups ()
(require 'find-dired)
(let* ((file (make-backup-file-name (buffer-file-name)))
(dir (file-name-directory file))
(args (concat "-iname '" (file-name-nondirectory file)
(dired-buffers dired-buffers)
(find-ls-option '("-print0 | xargs -0 ls -lta" . "-lta")))
;; Check that it's really a directory.
(or (file-directory-p dir)
(error "Backup directory does not exist: %s" dir))
(with-current-buffer (get-buffer-create "*Backups*")
(let ((find (get-buffer-process (current-buffer))))
(when find
(if (or (not (eq (process-status find) 'run))
(yes-or-no-p "A `find' process is running; kill it? "))
(condition-case nil
(interrupt-process find)
(sit-for 1)
(delete-process find))
(error nil))
(error "Cannot have two processes in `%s' at once"
(setq buffer-read-only nil)
(setq default-directory dir
args (concat find-program " . "
(if (string= args "")
(shell-quote-argument "(")
" " args " "
(shell-quote-argument ")")
" "))
(if (string-match "\\`\\(.*\\) {} \\(\\\\;\\|+\\)\\'"
(car find-ls-option))
(format "%s %s %s"
(match-string 1 (car find-ls-option))
(shell-quote-argument "{}")
(car find-ls-option))))
;; Start the find process.
(message "Looking for backup files...")
(shell-command (concat args "&") (current-buffer))
;; The next statement will bomb in classic dired (no optional arg
;; allowed)
(dired-mode dir (cdr find-ls-option))
(let ((map (make-sparse-keymap)))
(set-keymap-parent map (current-local-map))
(define-key map "\C-c\C-k" 'kill-find)
(use-local-map map))
(make-local-variable 'dired-sort-inhibit)
(setq dired-sort-inhibit t)
(set (make-local-variable 'revert-buffer-function)
`(lambda (ignore-auto noconfirm)
(find-dired ,dir ,find-args)))
;; Set subdir-alist so that Tree Dired will work:
(if (fboundp 'dired-simple-subdir-alist)
;; will work even with nested dired format (dired-nstd.el,v 1.15
;; and later)
;; else we have an ancient tree dired (or classic dired, where
;; this does no harm)
(set (make-local-variable 'dired-subdir-alist)
(list (cons default-directory (point-min-marker)))))
(set (make-local-variable 'dired-subdir-switches) find-ls-subdir-switches)
(setq buffer-read-only nil)
;; Subdir headlerline must come first because the first marker in
;; subdir-alist points there.
(insert " " dir ":\n")
;; Make second line a ``find'' line in analogy to the ``total'' or
;; ``wildcard'' line.
(insert " " args "\n")
(setq buffer-read-only t)
(let ((proc (get-buffer-process (current-buffer))))
(set-process-filter proc (function find-dired-filter))
(set-process-sentinel proc (function find-dired-sentinel))
;; Initialize the process marker; it is used by the filter.
(move-marker (process-mark proc) 1 (current-buffer)))
(setq mode-line-process '(":%s")))))
(bind-key "C-x ~" 'show-backups))
(defun backup-each-save-filter (filename)
(not (string-match
(concat "\\(^/tmp\\|\\.emacs\\.d/data\\(-alt\\)?/"
(setq backup-each-save-filter-function 'backup-each-save-filter)
(defun my-dont-backup-files-p (filename)
(unless (string-match filename "/\\(archive/sent/\\|recentf$\\)")
(normal-backup-enable-predicate filename)))
(setq backup-enable-predicate 'my-dont-backup-files-p)))
;;;_ , bbdb
(use-package bbdb-com
:commands bbdb-create
:bind ("M-B" . bbdb))
;;;_ , bm
(use-package bm
(defvar ctl-period-breadcrumb-map)
(define-prefix-command 'ctl-period-breadcrumb-map)
(bind-key "C-. c" 'ctl-period-breadcrumb-map))
:bind (("C-. c b" . bm-last-in-previous-buffer)
("C-. c f" . bm-first-in-next-buffer)
("C-. c g" . bm-previous)
("C-. c l" . bm-show-all)
("C-. c c" . bm-toggle)
("C-. c m" . bm-toggle)
("C-. c n" . bm-next)
("C-. c p" . bm-previous)))
;;;_ , bookmark
(use-package bookmark
:disabled t
:defer t
(use-package bookmark+)
(defun my-bookmark-set ()
(flet ((bmkp-completing-read-lax
(prompt &optional default alist pred hist)
(completing-read prompt alist pred nil nil hist default)))
(call-interactively #'bookmark-set)))
(bind-key "C-x r m" 'my-bookmark-set)))
;;;_ , browse-kill-ring+
(use-package browse-kill-ring+)
;;;_ , cmake-mode
(use-package cmake-mode
:mode (("CMakeLists\\.txt\\'" . cmake-mode)
("\\.cmake\\'" . cmake-mode)))
;;;_ , compile
(use-package compile
:defer t
(add-hook 'compilation-finish-functions
(lambda (buf why)
(display-buffer buf))))
;;;_ , color-moccur
(let ((ad-redefinition-action 'accept))
(use-package color-moccur
:commands (isearch-moccur isearch-all)
:bind ("M-s O" . moccur)
(bind-key "M-o" 'isearch-moccur isearch-mode-map)
(bind-key "M-O" 'isearch-moccur-all isearch-mode-map))
(use-package moccur-edit)))
;;;_ , crosshairs
(use-package crosshairs
:bind ("M-o c" . crosshairs-mode))
;;;_ , css-mode
(use-package css-mode
:mode ("\\.css\\'" . css-mode))
;;;_ , ibuffer
(use-package ibuffer
:defer t
(add-hook 'ibuffer-mode-hook
#'(lambda ()
(ibuffer-switch-to-saved-filter-groups "default"))))
;;;_ , iflipb
(use-package iflipb
:disabled t
:commands (iflipb-next-buffer iflipb-previous-buffer)
:bind (("S-<tab>" . my-iflipb-next-buffer)
("A-S-<tab>" . my-iflipb-previous-buffer))
(defvar my-iflipb-auto-off-timeout-sec 2)
(defvar my-iflipb-auto-off-timer-canceler-internal nil)
(defvar my-iflipb-ing-internal nil)
(defun my-iflipb-auto-off ()
(message nil)
(setq my-iflipb-auto-off-timer-canceler-internal nil
my-iflipb-ing-internal nil))
(defun my-iflipb-next-buffer (arg)
(interactive "P")
(iflipb-next-buffer arg)
(if my-iflipb-auto-off-timer-canceler-internal
(cancel-timer my-iflipb-auto-off-timer-canceler-internal))
(run-with-idle-timer my-iflipb-auto-off-timeout-sec 0 'my-iflipb-auto-off)
(setq my-iflipb-ing-internal t))
(defun my-iflipb-previous-buffer ()
(if my-iflipb-auto-off-timer-canceler-internal
(cancel-timer my-iflipb-auto-off-timer-canceler-internal))
(run-with-idle-timer my-iflipb-auto-off-timeout-sec 0 'my-iflipb-auto-off)
(setq my-iflipb-ing-internal t)))
(setq iflipb-always-ignore-buffers
"\\`\\( \\|diary\\|ipa\\|\\.newsrc-dribble\\'\\)"
iflipb-wrap-around t)
(defun iflipb-first-iflipb-buffer-switch-command ()
"Determines whether this is the first invocation of
iflipb-next-buffer or iflipb-previous-buffer this round."
(not (and (or (eq last-command 'my-iflipb-next-buffer)
(eq last-command 'my-iflipb-previous-buffer))
;;;_ , debbugs
(use-package debbugs-gnu
:commands (debbugs-gnu debbugs-gnu-search))
;;;_ , dedicated
(use-package dedicated
:bind ("C-. d" . dedicated-mode))
;;;_ , diff-mode
(use-package diff-mode
:commands diff-mode
(use-package diff-mode-))
;;;_ , dired
(use-package dired
:defer t
(defun dired-package-initialize ()
(unless (featurep 'runner)
(use-package dired-x)
;; (use-package dired-async)
(use-package dired-sort-map)
(use-package runner)
(setq dired-use-ls-dired t)
(bind-key "l" 'dired-up-directory dired-mode-map)
(defun my-dired-switch-window ()
(if (eq major-mode 'sr-mode)
(call-interactively #'sr-change-window)
(call-interactively #'other-window)))
(bind-key "<tab>" 'my-dired-switch-window dired-mode-map)
(bind-key "M-!" 'async-shell-command dired-mode-map)
(unbind-key "M-G" dired-mode-map)
(unbind-key "M-s f" dired-mode-map)
(defadvice dired-omit-startup (after diminish-dired-omit activate)
"Make sure to remove \"Omit\" from the modeline."
(diminish 'dired-omit-mode) dired-mode-map)
(defadvice dired-next-line (around dired-next-line+ activate)
"Replace current buffer if file is a directory."
(while (and (not (eobp)) (not ad-return-value))
(setq ad-return-value(dired-move-to-filename)))
(when (eobp)
(forward-line -1)
(setq ad-return-value(dired-move-to-filename))))
(defadvice dired-previous-line (around dired-previous-line+ activate)
"Replace current buffer if file is a directory."
(while (and (not (bobp)) (not ad-return-value))
(forward-line -1)
(setq ad-return-value(dired-move-to-filename)))
(when (bobp)
(call-interactively 'dired-next-line)))
(defvar dired-omit-regexp-orig (symbol-function 'dired-omit-regexp))
;; Omit files that Git would ignore
(defun dired-omit-regexp ()
(let ((file (expand-file-name ".git"))
(while (and (not (file-exists-p file))
(setq parent-dir
(file-name-directory file))))
;; Give up if we are already at the root dir.
(not (string= (file-name-directory file)
;; Move up to the parent dir and try again.
(setq file (expand-file-name ".git" parent-dir)))
;; If we found a change log in a parent, use that.
(if (file-exists-p file)
(let ((regexp (funcall dired-omit-regexp-orig))
(shell-command-to-string "git clean -d -x -n")))
(if (= 0 (length omitted-files))
(if (> (length regexp) 0)
"\\|" "")
#'(lambda (str)
(substring str 13
(if (= ?/ (aref str (1- (length str))))
(1- (length str))
(split-string omitted-files "\n" t)
(funcall dired-omit-regexp-orig))))))
(eval-after-load "dired-aux"
'(defun dired-do-async-shell-command (command &optional arg file-list)
"Run a shell command COMMAND on the marked files asynchronously.
Like `dired-do-shell-command' but if COMMAND doesn't end in ampersand,
adds `* &' surrounded by whitespace and executes the command asynchronously.
The output appears in the buffer `*Async Shell Command*'."
(let ((files (dired-get-marked-files t current-prefix-arg)))
;; Want to give feedback whether this file or marked files are
;; used:
(dired-read-shell-command "& on %s: " current-prefix-arg files)
(unless (string-match "[ \t][*?][ \t]" command)
(setq command (concat command " *")))
(unless (string-match "&[ \t]*\\'" command)
(setq command (concat command " &")))
(dired-do-shell-command command arg file-list)))
(add-hook 'dired-mode-hook 'dired-package-initialize)
(defun dired-double-jump (first-dir second-dir)
(list (ido-read-directory-name "First directory: "
(expand-file-name "~")
nil nil "dl/")
(ido-read-directory-name "Second directory: "
(expand-file-name "~")
nil nil "Archives/")))
(dired first-dir)
(dired-other-window second-dir))
(bind-key "C-c J" 'dired-double-jump)))
;;;_ , doxymacs
(use-package doxymacs
:disabled t
:load-path "site-lisp/doxymacs/lisp/")
;;;_ , dvc
(use-package dvc-autoloads
:load-path "site-lisp/dvc/lisp/")
;;;_ , ediff
(use-package ediff
(defvar ctl-period-equals-map)
(define-prefix-command 'ctl-period-equals-map)
(bind-key "C-. =" 'ctl-period-equals-map)
(bind-key "C-. = c" 'compare-windows)) ; not an ediff command, but it fits
:bind (("C-. = b" . ediff-buffers)
("C-. = B" . ediff-buffers3)
("C-. = =" . ediff-files)
("C-. = f" . ediff-files)
("C-. = F" . ediff-files3)
("C-. = r" . ediff-revision)
("C-. = p" . ediff-patch-file)
("C-. = P" . ediff-patch-buffer)
("C-. = l" . ediff-regions-linewise)
("C-. = w" . ediff-regions-wordwise))
(use-package ediff-keep))
;;;_ , edit-server
(use-package edit-server
:if (and window-system (not running-alternate-emacs)
(not noninteractive))
(add-hook 'after-init-hook 'server-start t)
(add-hook 'after-init-hook 'edit-server-start t)))
;;;_ , emms
(use-package emms-setup
:load-path "site-lisp/emms/lisp"
:defines emms-info-functions
:commands (emms-all emms-devel)
(defvar emms-initialized nil)
(defun my-emms ()
(unless emms-initialized
(require 'emms-info-libtag)
(setq emms-info-functions '(emms-info-libtag))
(setq emms-initialized t))
(call-interactively #'emms-smart-browse))
(bind-key "C-. M" 'my-emms))
(bind-key "S-<f7>" 'emms-previous)
(bind-key "S-<f8>" 'emms-pause)
(bind-key "S-<f9>" 'emms-next)
(bind-key "S-<f10>" 'emms-stop)
(defun emms-player-mplayer-volume-up ()
"Depends on mplayer’s -slave mode."
emms-player-simple-process-name "volume 1\n"))
(defun emms-player-mplayer-volume-down ()
"Depends on mplayer’s -slave mode."
emms-player-simple-process-name "volume -1\n"))
(bind-key "C-. C--" 'emms-player-mplayer-volume-down)
(bind-key "C-. C-=" 'emms-player-mplayer-volume-up)))
;;;_ , erc
(use-package erc
;; :commands erc
:if running-alternate-emacs
(defun irc ()
(erc-tls :server ""
:port 6697
:nick "johnw"
:password (funcall
(car (auth-source-search :host ""
:user "johnw"
:type 'netrc
:port 6667))
(erc-tls :server ""
:port 6697
:nick "johnw"))
(defun im ()
(erc :server "localhost"
:port 6667
:nick "johnw"
:password (funcall
(car (auth-source-search :host "bitlbee"
:user "johnw"
:type 'netrc
:port 6667))
(erc-track-minor-mode 1)
(erc-track-mode 1)
(use-package erc-alert)
(use-package erc-highlight-nicknames)
(use-package erc-patch)
(use-package erc-yank
(bind-key "C-y" 'erc-yank erc-mode-map))
(use-package wtf
:commands wtf-is
(defun erc-cmd-WTF (term &rest ignore)
"Look up definition for TERM."
(let ((def (wtf-is term)))
(if def
(let ((msg (concat "{Term} " (upcase term) " is " def)))
(insert msg)
(kill-ring-save (point-min) (point-max)))
(message msg))
(message (concat "No definition found for " (upcase term)))))))
(defun switch-to-bitlbee ()
(switch-to-buffer-other-window "&bitlbee")
(call-interactively 'erc-channel-names)
(goto-char (point-max)))
(bind-key "C-c b" 'switch-to-bitlbee)
(defun erc-cmd-SHOW (&rest form)
"Eval FORM and send the result and the original form as:
FORM => (eval FORM)."
(let* ((form-string (mapconcat 'identity form " "))
(condition-case err
(eval (read-from-whole-string form-string))
(format "Error: %s" err)))))
(erc-send-message (format "%s => %S" form-string result))))
(defun erc-cmd-INFO (&rest ignore)
"Send current info node."
(unless (get-buffer "*info*")
(error "No *info* buffer"))
(let (output)
(with-current-buffer "*info*"
(let* ((file (file-name-nondirectory Info-current-file))
(node Info-current-node))
(setq output (format "(info \"(%s)%s\") <-- hit C-x C-e to evaluate"
file node))))
(erc-send-message output)))
(defvar erc-fools))
(defun erc-cmd-FOOL (term &rest ignore)
(add-to-list 'erc-fools term))
(defun erc-cmd-UNFOOL (term &rest ignore)
(setq erc-fools (delete term erc-fools)))
(defun erc-cmd-OPME ()
"Request chanserv to op me."
(erc-message "PRIVMSG"
(format "chanserv op %s %s"
(erc-current-nick)) nil))
(defun erc-cmd-DEOPME ()
"Deop myself from current channel."
(erc-cmd-DEOP (format "%s" (erc-current-nick))))))
;;;_ , eshell
(use-package eshell
:defer t
(defun eshell-initialize ()
(defun eshell-spawn-external-command (beg end)
"Parse and expand any history references in current input."
(goto-char end)
(when (looking-back "&!" beg)
(delete-region (match-beginning 0) (match-end 0))
(goto-char beg)
(insert "spawn "))))
(add-hook 'eshell-expand-input-functions 'eshell-spawn-external-command)
(defun ss (server)
(interactive "sServer: ")
(call-process "spawn" nil nil nil "ss" server))
(eval-after-load "em-unix"
(unintern 'eshell/su)
(unintern 'eshell/sudo))))
(add-hook 'eshell-first-time-mode-hook 'eshell-initialize)))
(use-package esh-toggle
:requires eshell
:bind ("C-x C-z" . eshell-toggle))
;;;_ , ess
(use-package ess-site
:disabled t
:load-path "site-lisp/ess/lisp/"
:commands R)
;;;_ , eval-expr
(use-package eval-expr
:bind ("M-:" . eval-expr)
(setq eval-expr-print-function 'pp
eval-expr-print-level 20
eval-expr-print-length 100)
(defun eval-expr-minibuffer-setup ()
(set-syntax-table emacs-lisp-mode-syntax-table)
;;;_ , fetchmail-mode
(use-package fetchmail-mode
:commands fetchmail-mode)
;;;_ , flyspell
(use-package ispell
:bind (("C-c i c" . ispell-comments-and-strings)
("C-c i d" . ispell-change-dictionary)
("C-c i k" . ispell-kill-ispell)
("C-c i m" . ispell-message)
("C-c i r" . ispell-region)))
(use-package flyspell
:bind (("C-c i b" . flyspell-buffer)
("C-c i f" . flyspell-mode))
(define-key flyspell-mode-map [(control ?.)] nil))
;;;_ , fold-dwim
(use-package fold-dwim
:bind (("<f13>" . fold-dwim-toggle)
("<f14>" . fold-dwim-hide-all)
("<f15>" . fold-dwim-show-all)))
;;;_ , gist
(use-package gist
:bind ("C-c G" . gist-region-or-buffer))
;;;_ , gnus
(use-package dot-gnus
:bind (("M-G" . switch-to-gnus)
("C-x m" . compose-mail))
(setq gnus-init-file (expand-file-name "dot-gnus" user-emacs-directory)
gnus-home-directory "~/Messages/Gnus/")))
;;;_ , grep
(use-package grep
:bind (("M-s d" . find-grep-dired)
("M-s f" . find-grep)
("M-s g" . grep))
(defun find-grep-in-project (command-args)
(let ((default (thing-at-point 'symbol)))
(list (read-shell-command "Run find (like this): "
(cons (concat "git --no-pager grep -n "
(+ 24 (length default)))
(if command-args
(let ((null-device nil)) ; see grep
(grep command-args))))
(bind-key "M-s p" 'find-grep-in-project))
(use-package grep-ed)
(grep-apply-setting 'grep-command "egrep -nH -e ")
'("find . -type f -print0 | xargs -P4 -0 egrep -nH -e " . 52))))
;;;_ , gtags
(use-package gtags
:commands gtags-mode
:diminish gtags-mode
(defun my-gtags-or-semantic-find-tag ()
(if (and (fboundp 'semantic-active-p)
(funcall #'semantic-active-p))
(call-interactively #'semantic-complete-jump)
(call-interactively #'gtags-find-tag)))
(bind-key "M-." 'my-gtags-or-semantic-find-tag gtags-mode-map)
(bind-key "C-c t ." 'gtags-find-rtag)
(bind-key "C-c t f" 'gtags-find-file)
(bind-key "C-c t p" 'gtags-parse-file)
(bind-key "C-c t g" 'gtags-find-with-grep)
(bind-key "C-c t i" 'gtags-find-with-idutils)
(bind-key "C-c t s" 'gtags-find-symbol)
(bind-key "C-c t r" 'gtags-find-rtag)
(bind-key "C-c t v" 'gtags-visit-rootdir)
(bind-key "<mouse-2>" 'gtags-find-tag-from-here gtags-mode-map)
(use-package helm-gtags
:bind ("M-T" . helm-gtags-select)
(bind-key "M-," 'helm-gtags-resume gtags-mode-map))))
;;;_ , gud
(use-package gud
:commands gud-gdb
(defun show-debugger ()
(let ((gud-buf
(catch 'found
(dolist (buf (buffer-list))
(if (string-match "\\*gud-" (buffer-name buf))
(throw 'found buf))))))
(if gud-buf
(switch-to-buffer-other-window gud-buf)
(call-interactively 'gud-gdb))))
(bind-key "C-. g" 'show-debugger))
(bind-key "<f9>" 'gud-cont)
(bind-key "<f10>" 'gud-next)
(bind-key "<f11>" 'gud-step)
(bind-key "S-<f11>" 'gud-finish)))
;;;_ , haskell-mode
(require 'haskell-config)
;;;_ , helm
(use-package helm-config
:if (not running-alternate-emacs)
(bind-key "C-c M-x" 'helm-M-x)
(bind-key "C-h a" 'helm-c-apropos)
(bind-key "M-s a" 'helm-do-grep)
(bind-key "M-s b" 'helm-occur)
(bind-key "M-s F" 'helm-for-files)
(use-package helm-commands)
(bind-key "C-h e a" 'my-helm-apropos)
(bind-key "C-x M-!" 'helm-command-from-zsh)
(bind-key "C-x f" 'helm-find-git-file)
(use-package helm-descbinds
:commands helm-descbinds
(fset 'describe-bindings 'helm-descbinds))
(bind-key "C-h b" 'helm-descbinds))
(helm-match-plugin-mode t))
;;;_ , hi-lock
(use-package hi-lock
:bind (("M-o l" . highlight-lines-matching-regexp)
("M-o r" . highlight-regexp)
("M-o w" . highlight-phrase)))
;;;_ , hilit-chg
(use-package hilit-chg
:bind ("M-o C" . highlight-changes-mode))
;;;_ , hl-line
(use-package hl-line
:bind ("M-o h" . hl-line-mode)
(use-package hl-line+))
;;;_ , ibuffer
(use-package ibuffer
:bind ("C-x C-b" . ibuffer))
;;;_ , ido
(use-package ido
:defines (ido-cur-item
(ido-mode 'buffer)
(use-package ido-hacks
(ido-hacks-mode 1))
(use-package ido-springboard)
(defun ido-smart-select-text ()
"Select the current completed item. Do NOT descend into directories."
(when (and (or (not ido-require-match)
(if (memq ido-require-match
'(confirm confirm-after-completion))
(if (or (eq ido-cur-item 'dir)
(eq last-command this-command))
(setq ido-show-confirm-message t)
(not ido-incomplete-regexp))
(when ido-current-directory
(setq ido-exit 'takeprompt)
(unless (and ido-text (= 0 (length ido-text)))
(let ((match (ido-name (car ido-matches))))
(throw 'ido
(setq ido-selected
(if match
(replace-regexp-in-string "/\\'" "" match)
ido-text ido-selected
ido-final-text ido-text)))))
(add-hook 'ido-minibuffer-setup-hook
#'(lambda ()
(bind-key "<return>" 'ido-smart-select-text
(defun ido-switch-buffer-tiny-frame (buffer)
(interactive (list (ido-read-buffer "Buffer: " nil t)))
(make-frame '((width . 80)
(height . 22)
(left-fringe . 0)
(right-fringe . 0)
(vertical-scroll-bars . nil)
(unsplittable . t)
(has-modeline-p . nil)
;;(background-color . "grey80")
(minibuffer . nil)))
(switch-to-buffer buffer)
(set (make-local-variable 'mode-line-format) nil)))
(bind-key "C-x 5 t" 'ido-switch-buffer-tiny-frame)))
;;;_ , ielm
(use-package ielm
:bind ("C-c :" . ielm)
(defun my-ielm-return ()
(let ((end-of-sexp (save-excursion
(goto-char (point-max))
(skip-chars-backward " \t\n\r")
(if (>= (point) end-of-sexp)
(goto-char (point-max))
(skip-chars-backward " \t\n\r")
(delete-region (point) (point-max))
(call-interactively #'ielm-return))
(call-interactively #'paredit-newline))))
(add-hook 'ielm-mode-hook
(lambda ()
(bind-key "<return>" 'my-ielm-return ielm-map)))
;;;_ , image-file
(use-package image-file
:disabled t
(auto-image-file-mode 1))
;;;_ , info
(use-package info
:bind ("C-h C-i" . info-lookup-symbol)
(remove-hook 'menu-bar-update-hook 'mac-setup-help-topics)
(defadvice info-setup (after load-info+ activate)
(use-package info+))
(defadvice Info-exit (after remove-info-window activate)
"When info mode is quit, remove the window."
(if (> (length (window-list)) 1)
(use-package info-look
:commadns info-lookup-add-help)
;;;_ , indirect
(use-package indirect
:bind ("C-c C" . indirect-region))
;;;_ , initsplit
(eval-after-load "cus-edit"
'(use-package initsplit))
;;;_ , ipa
(use-package ipa
:commands ipa-insert
(autoload 'ipa-load-annotations-into-buffer "ipa")
(add-hook 'find-file-hook 'ipa-load-annotations-into-buffer)))
;;;_ , js2-mode
(use-package js2-mode
:mode ("\\.js\\'" . js2-mode))
;;;_ , ledger
(use-package "ldg-new"
:commands ledger-mode
(defun my-ledger-start-entry (&optional arg)
(interactive "p")
(find-file-other-window "~/Documents/Accounts/ledger.dat")
(goto-char (point-max))
(skip-syntax-backward " ")
(if (looking-at "\n\n")
(goto-char (point-max))
(delete-region (point) (point-max))
(insert ?\n)
(insert ?\n))
(insert (format-time-string "%Y/%m/%d ")))
(bind-key "C-c L" 'my-ledger-start-entry)
(defun ledger-matchup ()
(while (re-search-forward "\\(\\S-+Unknown\\)\\s-+\\$\\([-,0-9.]+\\)"
nil t)
(let ((account-beg (match-beginning 1))
(account-end (match-end 1))
(amount (match-string 2))
account answer)
(goto-char account-beg)
(set-window-point (get-buffer-window) (point))
(with-current-buffer (get-buffer "nrl-mastercard-old.dat")
(goto-char (point-min))
(when (re-search-forward (concat "\\(\\S-+\\)\\s-+\\$" amount)
nil t)
(setq account (match-string 1))
(goto-char (match-beginning 1))
(set-window-point (get-buffer-window) (point))
(setq answer
(read-char (format "Is this a match for %s (y/n)? "
(when (eq answer ?y)
(goto-char account-beg)
(delete-region account-beg account-end)
(insert account))
;;;_ , lisp-mode
;; Utilities every Emacs Lisp coders should master:
;; paredit Let's you manipulate sexps with ease
;; redshank Think: Lisp refactoring
;; edebug Knowing the traditional debugger is good too
;; eldoc
;; cldoc
;; elint
;; elp
;; ert
(use-package lisp-mode
;; :load-path "site-lisp/slime/contrib/"
(defface esk-paren-face
'((((class color) (background dark))
(:foreground "grey50"))
(((class color) (background light))
(:foreground "grey55")))
"Face used to dim parentheses."
:group 'starter-kit-faces)
;; Change lambda to an actual lambda symbol
(mapc (lambda (major-mode)
(0 (ignore
(compose-region (match-beginning 1)
(match-end 1) ?λ))))
("(\\|)" . 'esk-paren-face)
("(\\(ert-deftest\\)\\>[ '(]*\\(setf[ ]+\\sw+\\|\\sw+\\)?"
(1 font-lock-keyword-face)
(2 font-lock-function-name-face
nil t)))))
(defvar slime-mode nil)
(defvar lisp-mode-initialized nil)
(defun initialize-lisp-mode ()
(unless lisp-mode-initialized
(setq lisp-mode-initialized t)
(use-package redshank
:diminish redshank-mode)
(use-package elisp-slime-nav
:diminish elisp-slime-nav-mode)
(use-package edebug)
(use-package eldoc
:diminish eldoc-mode
:defer t
(use-package eldoc-extension
:disabled t
:defer t
(add-hook 'emacs-lisp-mode-hook
#'(lambda () (require 'eldoc-extension)) t))
(eldoc-add-command 'paredit-backward-delete
(use-package cldoc
:diminish cldoc-mode)
(use-package ert
:commands ert-run-tests-interactively
:bind ("C-c e t" . ert-run-tests-interactively))
(use-package elint
:commands 'elint-initialize
(defun elint-current-buffer ()
(add-to-list 'elint-standard-variables 'current-prefix-arg)
(add-to-list 'elint-standard-variables 'command-line-args-left)
(add-to-list 'elint-standard-variables 'buffer-file-coding-system)
(add-to-list 'elint-standard-variables 'emacs-major-version)
(add-to-list 'elint-standard-variables 'window-system)))
(use-package highlight-cl
(mapc (function
(lambda (mode-hook)
(add-hook mode-hook
(defun my-elisp-indent-or-complete (&optional arg)
(interactive "p")
(call-interactively 'lisp-indent-line)
(unless (or (looking-back "^\\s-*")
(not (looking-back "[-A-Za-z0-9_*+/=<>!?]+")))
(call-interactively 'lisp-complete-symbol)))
(defun my-lisp-indent-or-complete (&optional arg)
(interactive "p")
(if (or (looking-back "^\\s-*") (bolp))
(call-interactively 'lisp-indent-line)
(call-interactively 'slime-indent-and-complete-symbol)))
(defun my-byte-recompile-file ()
(byte-recompile-file buffer-file-name)))
;; Register Info manuals related to Lisp
(use-package info-lookmore
(mapc (lambda (mode)
:mode mode
:regexp "[^][()'\" \t\n]+"
:ignore-case t
:doc-spec '(("(ansicl)Symbol Index" nil nil nil))))
(defun my-lisp-mode-hook ()
(auto-fill-mode 1)
(paredit-mode 1)
(redshank-mode 1)
(elisp-slime-nav-mode 1)
(local-set-key (kbd "<return>") 'paredit-newline)
(if (memq major-mode
'(emacs-lisp-mode inferior-emacs-lisp-mode ielm-mode))
(bind-key "<M-return>" 'outline-insert-heading emacs-lisp-mode-map)
(bind-key "<tab>" 'my-elisp-indent-or-complete emacs-lisp-mode-map))
(bind-key "<tab>" 'my-lisp-indent-or-complete lisp-mode-map)
(bind-key "M-q" 'slime-reindent-defun lisp-mode-map)
(bind-key "M-l" 'slime-selector lisp-mode-map))
(yas/minor-mode 1))
(hook-into-modes #'my-lisp-mode-hook lisp-mode-hooks)))
;;;_ , llvm-mode
(use-package llvm-mode
:mode ("\\.ll\\'" . llvm-mode))
;;;_ , log4j-mode
(use-package log4j-mode
:disabled t
:mode ("\\.log\\'" . log4j-mode))
;;;_ , lua-mode
(use-package lua-mode
:mode ("\\.lua\\'" . lua-mode)
:interpreter ("lua" . lua-mode))
;;;_ , lusty-explorer
(use-package lusty-explorer
:bind ("C-x C-f" . lusty-file-explorer)
(add-hook 'lusty-setup-hook
(lambda ()
(bind-key "SPC" 'lusty-select-match lusty-mode-map)
(bind-key "C-d" 'exit-minibuffer lusty-mode-map)))
(defun lusty-open-this ()
"Open the given file/directory/buffer, creating it if not already present."
(when lusty--active-mode
(ecase lusty--active-mode
(let* ((path (minibuffer-contents-no-properties))
(last-char (aref path (1- (length path)))))
(:buffer-explorer (lusty-select-match)))))
(defvar lusty-only-directories nil)
(defun lusty-file-explorer-matches (path)
(let* ((dir (lusty-normalize-dir (file-name-directory path)))
(file-portion (file-name-nondirectory path))
(and dir
;; NOTE: directory-files is quicker but
;; doesn't append slash for directories.
;;(directory-files dir nil nil t)
(file-name-all-completions "" dir)))
(filtered (lusty-filter-files
(if lusty-only-directories
(loop for f in files
when (= ?/ (aref f (1- (length f))))
collect f)
(if (or (string= file-portion "")
(string= file-portion "."))
(sort filtered 'string<)
(lusty-sort-by-fuzzy-score filtered file-portion))))
(defun lusty-read-directory ()
"Launch the file/directory mode of LustyExplorer."
(let ((lusty--active-mode :file-explorer))
(let* ((lusty--ignored-extensions-regex
(concat "\\(?:" (regexp-opt completion-ignored-extensions) "\\)$"))
(minibuffer-local-filename-completion-map lusty-mode-map)
(lusty-only-directories t))
(lusty--run 'read-directory-name default-directory ""))))
(defun lusty-read-file-name ()
"Launch the file/directory mode of LustyExplorer."
(let ((lusty--active-mode :file-explorer))
(let* ((lusty--ignored-extensions-regex
(concat "\\(?:" (regexp-opt completion-ignored-extensions) "\\)$"))
(minibuffer-local-filename-completion-map lusty-mode-map)
(lusty-only-directories nil))
(lusty--run 'read-file-name default-directory ""))))
(if (featurep 'icicles)
(defadvice lusty-file-explorer (around lusty-file-explorer-without-icy
(flet ((message (&rest ignore)))
(let ((icy-was-on icicle-mode))
(if icy-was-on (icy-mode 0))
(if icy-was-on (icy-mode 1)))))))))
;;;_ , macrostep
(use-package macrostep
:bind ("C-c e m" . macrostep-expand))
;;;_ , magit
(use-package magit
:bind ("C-x g" . magit-status)
(setenv "GIT_PAGER" "")
(add-hook 'magit-log-edit-mode-hook
#'(lambda ()
(set-fill-column 72)
(require 'magit-topgit)
(require 'rebase-mode)
(defun start-git-monitor ()
(start-process "git-monitor" (current-buffer) "~/bin/git-monitor"))
;;(add-hook 'magit-status-mode-hook 'start-git-monitor)
;;;_ , markdown-mode
(use-package markdown-mode
:mode ("\\.md\\'" . markdown-mode)
(defun markdown-preview-file ()
"run Marked on the current file and revert the buffer"
(format "open -a /Applications/ %s"
(shell-quote-argument (buffer-file-name)))))
(bind-key "C-x M" 'markdown-preview-file)))
;;;_ , merlin
(defun merlin-record-times ()
(require 'rx)
(let* ((text (buffer-substring-no-properties (line-beginning-position)
(rx (and string-start (0+ space)
(group (and (= 2 num) ?/ (= 2 num) ?/ (= 2 num)
space (= 2 num) ?: (= 2 num) space
(in "AP") ?M)) (1+ space)
(group (and (= 2 num) ?/ (= 2 num) ?/ (= 2 num)
space (= 2 num) ?: (= 2 num) space
(in "AP") ?M)) (1+ space)
(? (and (group ?*) (1+ space)))
(group (1+ (or digit (in ".hms"))))
(1+ space) (group (1+ nonl)) string-end))))
(if (string-match regex text)
(let ((start (match-string 1 text))
(end (match-string 2 text))
(cleared (match-string 3 text))
(duration (match-string 4 text)) commodity
(account (match-string 5 text)))
(when (string-match "\\([0-9.]+\\)\\([mhs]\\)" duration)
(setq commodity (match-string 2 duration)
duration (match-string 1 duration))
(cond ((string= commodity "h")
(setq commodity "hours"))
((string= commodity "m")
(setq commodity "minutes"))
((string= commodity "s")
(setq commodity "seconds"))))
(if (string-match "\\([0-9.][0-9.a-z]+\\)" account)
(setq account (match-string 1 account)))
tell application \"Merlin\"
set act to 0
set listActivity to every activity of first document
repeat with oneActivity in listActivity
if subtitle of oneActivity is \"%s\" then
set act to oneActivity
exit repeat
end if
end repeat
if act is 0 then
set myselection to selected object of main window of first document as list
if (count of myselection) is 0 then
display dialog \"Please select activity to set time for\" buttons {\"OK\"}
set act to beginning of myselection
end if
end if
if act is 0 or (class of act is project) or (is milestone of act is true) then
display dialog \"Cannot locate activity for %s\" buttons {\"OK\"}
tell act
if ((class is not project) and (is milestone is not true)) then
set actual start date to (date \"%s\")
set given actual work to {amount:%s, unit:%s, floating:false, ¬
relative error:0}
if %s then
set actual end date to (date \"%s\")
delete last actuals reporting date
set given remaining work to {amount:0, unit:hours, floating:false, ¬
relative error:0}
delete actual end date
set last actuals reporting date to (date \"%s\")
-- set theReturnedItems to (display dialog \"Enter remaining hours for \" ¬
-- with title \"Given Remaining Work\" with icon stop ¬
-- default answer \"\" buttons {\"OK\", \"Cancel\"} default button 1)
-- set theAnswer to the text returned of theReturnedItems
-- set theButtonName to the button returned of theReturnedItems
-- set given remaining work to {amount:(theAnswer as number), unit:hours, ¬
-- floating:false, relative error:0}
end if
end if
end tell
end if
end tell" account account start duration commodity (if cleared "true" "false")
end end))))))
;;;_ , mudel
(use-package mudel
:commands mudel
:bind ("C-c M" . mud)
(defun mud ()
(mudel "4dimensions" "" 6000)))
;;;_ , mule
(use-package mule
(prefer-coding-system 'utf-8)
(set-terminal-coding-system 'utf-8)
(setq x-select-request-type '(UTF8_STRING COMPOUND_TEXT TEXT STRING))))
;;;_ , multi-term
(use-package multi-term
:bind (("C-. t" . multi-term-next)
("C-. T" . multi-term))
(defun screen ()
(let (term-buffer)
;; Set buffer.
(setq term-buffer
(let ((multi-term-program (executable-find "screen"))
(multi-term-program-switches "-DR"))
(set-buffer term-buffer)
;; Internal handle for `multi-term' buffer.
;; Switch buffer
(switch-to-buffer term-buffer)))
(if t
(defalias 'my-term-send-raw-at-prompt 'term-send-raw)
(defun my-term-send-raw-at-prompt ()
(if (save-excursion
(search-backward " $ " (line-beginning-position) t))
(if (memq 'meta (event-modifiers last-command-event))
(format "\e%c"
(logand last-command-event (lognot #x8000000)))))
(call-interactively #'term-send-raw)))
(call-interactively (lookup-key (current-global-map)
(vector last-command-event))))))
(defun my-term-end-of-buffer ()
(call-interactively #'end-of-buffer)
(if (and (eobp) (bolp))
(delete-char -1)))
(require 'term)
(defadvice term-process-pager (after term-process-rebind-keys activate)
(define-key term-pager-break-map "\177" 'term-pager-back-page))))
;;;_ , nf-procmail-mode
(use-package nf-procmail-mode
:commands nf-procmail-mode)
;;;_ , nroff-mode
(use-package nroff-mode
:commands nroff-mode
(defun update-nroff-timestamp ()
(goto-char (point-min))
(when (re-search-forward "^\\.Dd ")
(let ((stamp (format-time-string "%B %e, %Y")))
(unless (looking-at stamp)
(delete-region (point) (line-end-position))
(insert stamp)
(let (after-save-hook)
(add-hook 'nroff-mode-hook
#'(lambda ()
(add-hook 'after-save-hook 'update-nroff-timestamp nil t)))))
;;;_ , nxml-mode
(use-package nxml-mode
:commands nxml-mode
(defalias 'xml-mode 'nxml-mode)
(defun my-nxml-mode-hook ()
(bind-key "<return>" 'newline-and-indent nxml-mode-map))
(add-hook 'nxml-mode-hook 'my-nxml-mode-hook)
(defun tidy-xml-buffer ()
(call-process-region (point-min) (point-max) "tidy" t t nil
"-xml" "-i" "-wrap" "0" "-omit" "-q")))
(bind-key "C-H" 'tidy-xml-buffer nxml-mode-map)))
;;;_ , org-mode
(use-package dot-org
:commands org-agenda-list
:bind (("M-C" . jump-to-org-agenda)
("M-m" . org-smart-capture)
("M-M" . org-inline-note)
("C-c a" . org-agenda)
("C-c S" . org-store-link)
("C-c l" . org-insert-link))
(unless running-alternate-emacs
(run-with-idle-timer 300 t 'jump-to-org-agenda))
(if (string-match "\\.elc\\'" load-file-name)
(add-hook 'after-init-hook
#'(lambda ()
(org-resolve-clocks))) t)))
;;;_ , paredit
(use-package paredit
:commands paredit-mode
:diminish paredit-mode
(use-package paredit-ext)
(bind-key "C-M-l" 'paredit-recentre-on-sexp paredit-mode-map)
(bind-key ")" 'paredit-close-round-and-newline paredit-mode-map)
(bind-key "M-)" 'paredit-close-round paredit-mode-map)
(bind-key "M-k" 'paredit-raise-sexp paredit-mode-map)
(bind-key "M-h" 'mark-containing-sexp paredit-mode-map)
(bind-key "M-I" 'paredit-splice-sexp paredit-mode-map)
(unbind-key "M-r" paredit-mode-map)
(unbind-key "M-s" paredit-mode-map)
(bind-key "C-. d" 'paredit-forward-down paredit-mode-map)
(bind-key "C-. B" 'paredit-splice-sexp-killing-backward paredit-mode-map)
(bind-key "C-. C" 'paredit-convolute-sexp paredit-mode-map)
(bind-key "C-. F" 'paredit-splice-sexp-killing-forward paredit-mode-map)
(bind-key "C-. a" 'paredit-add-to-next-list paredit-mode-map)
(bind-key "C-. A" 'paredit-add-to-previous-list paredit-mode-map)
(bind-key "C-. j" 'paredit-join-with-next-list paredit-mode-map)
(bind-key "C-. J" 'paredit-join-with-previous-list paredit-mode-map)
(add-hook 'allout-mode-hook
#'(lambda ()
(bind-key "M-k" 'paredit-raise-sexp allout-mode-map)
(bind-key "M-h" 'mark-containing-sexp allout-mode-map)))))
;;;_ , paren
(use-package mic-paren
(use-package paren
(show-paren-mode 1)))
;;;_ , per-window-point
(use-package per-window-point
(pwp-mode 1))
;;;_ , persistent-scratch
(use-package persistent-scratch
:if (and window-system (not running-alternate-emacs)
(not noninteractive)))
;;;_ , popup-ruler
(use-package popup-ruler
:bind (("C-. r" . popup-ruler)
("C-. R" . popup-ruler-vertical)))
;;;_ , pp-c-l
(use-package pp-c-l
(hook-into-modes 'pretty-control-l-mode '(prog-mode-hook)))
;;;_ , ps-print
(use-package ps-print
:defer t
(defun ps-spool-to-pdf (beg end &rest ignore)
(interactive "r")
(let ((temp-file (concat (make-temp-name "ps2pdf") ".pdf")))
(call-process-region beg end (executable-find "ps2pdf")
nil nil nil "-" temp-file)
(call-process (executable-find "open") nil nil nil temp-file)))
(setq ps-print-region-function 'ps-spool-to-pdf)))
;;;_ , puppet-mode
(use-package puppet-mode
:mode ("\\.pp\\'" . puppet-mode)
(use-package puppet-ext))
;;;_ , python-mode
(use-package python-mode
:mode ("\\.py\\'" . python-mode)
:interpreter ("python" . python-mode)
(defvar python-mode-initialized nil)
(defun my-python-mode-hook ()
(unless python-mode-initialized
(setq python-mode-initialized t)
:mode 'python-mode
:regexp "[a-zA-Z_0-9.]+"
'(("(python)Python Module Index" )
"\\([A-Za-z0-9_]+\\)() (in module \\([A-Za-z0-9_.]+\\))" item)
(format "%s.%s" (match-string 2 item)
(match-string 1 item)))))))))
(setq indicate-empty-lines t)
(set (make-local-variable 'parens-require-spaces) nil)
(setq indent-tabs-mode nil)
(bind-key "C-c C-z" 'python-shell python-mode-map)
(unbind-key "C-c c" python-mode-map))
(add-hook 'python-mode-hook 'my-python-mode-hook)))
;;;_ , quickrun
(use-package quickrun
:bind ("C-c C-r" . quickrun))
;;;_ , recentf
(use-package recentf
:if (not noninteractive)
(recentf-mode 1)
(defun recentf-add-dired-directory ()
(if (and dired-directory
(file-directory-p dired-directory)
(not (string= "/" dired-directory)))
(let ((last-idx (1- (length dired-directory))))
(if (= ?/ (aref dired-directory last-idx))
(substring dired-directory 0 last-idx)
(add-hook 'dired-mode-hook 'recentf-add-dired-directory)))
;;;_ , repeat-insert
(use-package repeat-insert
:disabled t
:commands (insert-patterned
;;;_ , ruby-mode
(use-package ruby-mode
:mode ("\\.rb\\'" . ruby-mode)
:interpreter ("ruby" . ruby-mode)
(use-package yari
(defvar yari-helm-source-ri-pages
'((name . "RI documentation")
(candidates . (lambda () (yari-ruby-obarray)))
(action ("Show with Yari" . yari))
(candidate-number-limit . 300)
(requires-pattern . 2)
"Source for completing RI documentation."))
(defun helm-yari (&optional rehash)
(interactive (list current-prefix-arg))
(when current-prefix-arg (yari-ruby-obarray rehash))
(helm 'yari-helm-source-ri-pages (yari-symbol-at-point)))))
(defun my-ruby-smart-return ()
(when (memq (char-after) '(?\| ?\" ?\'))
(call-interactively 'newline-and-indent))
(defun my-ruby-mode-hook ()
(require 'inf-ruby)
(bind-key "<return>" 'my-ruby-smart-return ruby-mode-map)
(bind-key "C-h C-i" 'helm-yari ruby-mode-map)
(set (make-local-variable 'yas/fallback-behavior)
'(apply ruby-indent-command . nil))
(bind-key "<tab>" 'yas/expand-from-trigger-key ruby-mode-map))
(add-hook 'ruby-mode-hook 'my-ruby-mode-hook)))
;;;_ , selectkey
(use-package selectkey
(bind-key "C-. b" 'selectkey-select-prefix-map)
(selectkey-define-select-key compile "c" "\\*compilation")
(selectkey-define-select-key shell-command "o" "Shell Command")
(selectkey-define-select-key shell "s" "\\*shell" (shell))
(selectkey-define-select-key multi-term "t" "\\*terminal" (multi-term-next))
(selectkey-define-select-key eshell "z" "\\*eshell" (eshell))))
;;;_ , session
(use-package session
:if (not noninteractive)
:load-path "site-lisp/session/lisp/"
(defun remove-session-use-package-from-settings ()
(when (string= (buffer-file-name)
(expand-file-name "settings.el"
(goto-char (point-min))
(when (re-search-forward "^ '(session-use-package " nil t)
(delete-region (line-beginning-position)
(1+ (line-end-position)))))))
(add-hook 'before-save-hook 'remove-session-use-package-from-settings)
;; expanded folded secitons as required
(defun le::maybe-reveal ()
(when (and (or (memq major-mode '(org-mode outline-mode))
(and (boundp 'outline-minor-mode)
(if (eq major-mode 'org-mode)
(add-hook 'session-after-jump-to-last-change-hook
(defun save-information ()
(with-temp-message "Saving Emacs information..."
(loop for func in kill-emacs-hook
unless (memq func '(exit-gnus-on-exit server-force-stop))
do (funcall func))
(unless (or noninteractive
(eq 'listen (process-status server-process)))
(run-with-idle-timer 300 t 'save-information)
(if window-system
(add-hook 'after-init-hook 'session-initialize t))))
;;;_ , sh-script
(use-package sh-script
:defer t
(defvar sh-script-initialized nil)
(defun initialize-sh-script ()
(unless sh-script-initialized
(setq sh-script-initialized t)
(info-lookup-add-help :mode 'shell-script-mode
:regexp ".*"
(add-hook 'shell-mode-hook 'initialize-sh-script)))
;;;_ , sh-toggle
(use-package sh-toggle
:bind ("C-. C-z" . shell-toggle))
;;;_ , slime
(use-package slime
:commands (sbcl slime)
#'(lambda ()
;; slime-enclosing-context
;; slime-typeout-frame
(define-key slime-repl-mode-map [(control return)] 'other-window)
(define-key slime-mode-map [return] 'paredit-newline)
(define-key slime-mode-map [(control ?h) ?F] 'info-lookup-symbol)))
(defvar slime-repl-mode-map))
(setq slime-net-coding-system 'utf-8-unix)
(setq slime-lisp-implementations
("sbcl" "--core"
(lambda (port-file _)
(format "(swank:start-server %S)\n" port-file)))
(ecl ("ecl" "-load" "/Users/johnw/Library/Lisp/init.lisp"))
(clisp ("clisp" "-i" "/Users/johnw/Library/Lisp/lwinit.lisp"))))
(setq slime-default-lisp 'sbcl)
(setq slime-complete-symbol*-fancy t)
(setq slime-complete-symbol-function 'slime-fuzzy-complete-symbol)
(defun sbcl (&optional arg)
(interactive "P")
(let ((slime-default-lisp (if arg 'sbcl64 'sbcl))
(current-prefix-arg nil))
(defun clisp () (interactive) (let ((slime-default-lisp 'clisp)) (slime)))
(defun ecl () (interactive) (let ((slime-default-lisp 'ecl)) (slime)))
(defun start-slime ()
(unless (slime-connected-p)
(save-excursion (slime))))
(add-hook 'slime-mode-hook 'start-slime)
(add-hook 'slime-load-hook #'(lambda () (require 'slime-fancy)))
(add-hook 'inferior-lisp-mode-hook #'(lambda () (inferior-slime-mode t)))
(use-package hyperspec
(setq common-lisp-hyperspec-root
;;;_ , smart-compile
(use-package smart-compile
:commands smart-compile
:bind (("C-c c" . smart-compile)
("A-n" . next-error)
("A-p" . previous-error))
(defun show-compilation ()
(let ((compile-buf
(catch 'found
(dolist (buf (buffer-list))
(if (string-match "\\*compilation\\*" (buffer-name buf))
(throw 'found buf))))))
(if compile-buf
(switch-to-buffer-other-window compile-buf)
(call-interactively 'compile))))
(bind-key "M-O" 'show-compilation)))
;;;_ , smerge-mode
(use-package smerge-mode
:commands (smerge-mode smerge-command-prefix)
(setq smerge-command-prefix (kbd "C-. C-.")))
;;;_ , stopwatch
(use-package stopwatch
:bind ("<f8>" . stopwatch))
;;;_ , sunrise-commander
(use-package sunrise-commander
:disabled t
:commands (sunrise sunrise-cd)
(defun my-activate-sunrise ()
(let ((sunrise-exists
(loop for buf in (buffer-list)
when (string-match " (Sunrise)$" (buffer-name buf))
return buf)))
(if sunrise-exists
(call-interactively 'sunrise)
(sunrise "~/dl/" "~/Archives/"))))
(bind-key "C-c j" 'my-activate-sunrise)
(bind-key "C-c C-j" 'sunrise-cd))
(require 'sunrise-x-modeline)
(require 'sunrise-x-tree)
(require 'sunrise-x-tabs)
(bind-key "/" 'sr-sticky-isearch-forward sr-mode-map)
(bind-key "<backspace>" 'sr-scroll-quick-view-down sr-mode-map)
(bind-key "C-x t" 'sr-toggle-truncate-lines sr-mode-map)
(bind-key "q" 'sr-history-prev sr-mode-map)
(bind-key "z" 'sr-quit sr-mode-map)
(unbind-key "C-e" sr-mode-map)
(unbind-key "C-p" sr-tabs-mode-map)
(unbind-key "C-n" sr-tabs-mode-map)
(unbind-key "M-<backspace>" sr-term-line-minor-mode-map)
(bind-key "M-[" 'sr-tabs-prev sr-tabs-mode-map)
(bind-key "M-]" 'sr-tabs-next sr-tabs-mode-map)
(defun sr-browse-file (&optional file)
"Display the selected file with the default appication."
(setq file (or file (dired-get-filename)))
(let ((buff (current-buffer))
(fname (if (file-directory-p file)
(file-name-nondirectory file)))
(app (cond
((eq system-type 'darwin) "open %s")
((eq system-type 'windows-nt) "open %s")
(t "xdg-open %s"))))
(start-process-shell-command "open" nil (format app file))
(unless (eq buff (current-buffer))
(sr-scrollable-viewer (current-buffer)))
(message "Opening \"%s\" ..." fname))))
(defun sr-goto-dir (dir)
"Change the current directory in the active pane to the given one."
(interactive (list (progn
(require 'lusty-explorer)
(if sr-goto-dir-function
(funcall sr-goto-dir-function dir)
(unless (and (eq major-mode 'sr-mode)
(sr-equal-dirs dir default-directory))
(if (and sr-avfs-root
(null (posix-string-match "#" dir)))
(setq dir (replace-regexp-in-string
(expand-file-name sr-avfs-root) "" dir)))
(sr-within dir (sr-alternate-buffer (dired dir))))
(sr-history-push default-directory)
;;;_ , tablegen-mode
(use-package tablegen-mode
:description "\
This mode is used for editing .td files in the LLVM/Clang source code."
:mode ("\\.td\\'" . tablegen-mode))
;;;_ , texinfo
(use-package texinfo
:defines texinfo-section-list
:mode ("\\.texi\\'" . texinfo-mode)
(defun my-texinfo-mode-hook ()
(dolist (mapping '((?b . "emph")
(?c . "code")
(?s . "samp")
(?d . "dfn")
(?o . "option")
(?x . "pxref")))
(local-set-key (vector (list 'alt (car mapping)))
`(lambda () (interactive)
(TeX-insert-macro ,(cdr mapping))))))
(add-hook 'texinfo-mode-hook 'my-texinfo-mode-hook)
(defun texinfo-outline-level ()
;; Calculate level of current texinfo outline heading.
(require 'texinfo)
(if (bobp)
(forward-char 1)
(let* ((word (buffer-substring-no-properties
(point) (progn (forward-word 1) (point))))
(entry (assoc word texinfo-section-list)))
(if entry
(nth 1 entry)
;;;_ , vkill
(use-package vkill
:commands vkill
(defun vkill-and-helm-occur ()
(call-interactively #'helm-occur))
(bind-key "C-x L" 'vkill-and-helm-occur))
(setq vkill-show-all-processes t))
;;;_ , w3m
(use-package w3m
:commands w3m-search
:bind (("C-. u" . w3m-browse-url)
("C-. U" . w3m-browse-url-new-session)
("C-. A-u" . w3m-browse-chrome-url-new-session))
(setq w3m-command "/opt/local/bin/w3m")
(setq w3m-coding-system 'utf-8
w3m-file-coding-system 'utf-8
w3m-file-name-coding-system 'utf-8
w3m-input-coding-system 'utf-8
w3m-output-coding-system 'utf-8
w3m-terminal-coding-system 'utf-8)
(add-hook 'w3m-mode-hook 'w3m-link-numbering-mode)
(autoload 'w3m-session-crash-recovery-remove "w3m-session")
(defun wikipedia-query (term)
(interactive (list (read-string "Wikipedia search: " (word-at-point))))
(require 'w3m-search)
(w3m-search "en.wikipedia" term))
(autoload 'w3m-search-escape-query-string "w3m-search"))
(defun wolfram-alpha-query (term)
(interactive (list (read-string "Ask Wolfram Alpha: " (word-at-point))))
(require 'w3m-search)
(w3m-browse-url (format ""
(w3m-search-escape-query-string term))))
(defun goto-emacswiki ()
(w3m-browse-url ""))
(defun w3m-browse-url-new-session (url)
(interactive (progn
(require 'browse-url)
(browse-url-interactive-arg "Emacs-w3m URL: ")))
(w3m-browse-url url t))
(defun w3m-browse-chrome-url-new-session ()
(let ((url (do-applescript
(string-to-multibyte "tell application \"Google Chrome\"
URL of active tab of front window
end tell"))))
(w3m-browse-url (substring url 1 (1- (length url))) t)))
(bind-key "A-M-e" 'goto-emacswiki)
(bind-key "A-M-g" 'w3m-search)
(bind-key "A-M-h" 'wolfram-alpha-query)
(bind-key "A-M-w" 'wikipedia-query))
(let (proxy-host proxy-port)
(shell-command "scutil --proxy" (current-buffer))
(when (re-search-forward "HTTPPort : \\([0-9]+\\)" nil t)
(setq proxy-port (match-string 1)))
(when (re-search-forward "HTTPProxy : \\(\\S-+\\)" nil t)
(setq proxy-host (match-string 1))))
(if (and proxy-host proxy-port)
(setq w3m-command-arguments
(nconc w3m-command-arguments
(list "-o" (format "http_proxy=http://%s:%s/"
proxy-host proxy-port)))))
(use-package w3m-type-ahead
:requires w3m
(add-hook 'w3m-mode-hook 'w3m-type-ahead-mode))
(add-hook 'w3m-display-hook
(lambda (url)
(let ((buffer-read-only nil))
(defun my-w3m-linknum-follow ()
(bind-key "k" 'w3m-delete-buffer w3m-mode-map)
(bind-key "i" 'w3m-view-previous-page w3m-mode-map)
(bind-key "p" 'w3m-previous-anchor w3m-mode-map)
(bind-key "n" 'w3m-next-anchor w3m-mode-map)
(defun dka-w3m-textarea-hook()
(while (re-search-forward "\r\n" nil t)
(replace-match "\n" nil nil))
(add-hook 'w3m-form-input-textarea-mode-hook 'dka-w3m-textarea-hook)
(bind-key "<return>" 'w3m-view-url-with-external-browser
(bind-key "S-<return>" 'w3m-safe-view-this-url w3m-minor-mode-map)))
;;;_ , wcount-mode
(use-package wcount-mode
:commands wcount)
;;;_ , whitespace
(use-package whitespace
:diminish (global-whitespace-mode
:commands (whitespace-buffer
(hook-into-modes 'whitespace-mode
(defun normalize-file ()
(goto-char (point-min))
(goto-char (point-max))
(set-buffer-file-coding-system 'unix)
(goto-char (point-min))
(while (re-search-forward "\r$" nil t)
(replace-match ""))
(set-buffer-file-coding-system 'utf-8)
(let ((require-final-newline t))
(defun maybe-turn-on-whitespace ()
"Depending on the file, maybe clean up whitespace."
(let ((file (expand-file-name ".clean"))
(while (and (not (file-exists-p file))
(setq parent-dir
(file-name-directory file))))
;; Give up if we are already at the root dir.
(not (string= (file-name-directory file)
;; Move up to the parent dir and try again.
(setq file (expand-file-name ".clean" parent-dir)))
;; If we found a change log in a parent, use that.
(when (and (file-exists-p file)
(not (file-exists-p ".noclean"))
(not (and buffer-file-name
(string-match "\\.texi\\'" buffer-file-name))))
(add-hook 'write-contents-hooks
#'(lambda ()
(ignore (whitespace-cleanup))) nil t)
(add-hook 'find-file-hooks 'maybe-turn-on-whitespace t))
(remove-hook 'find-file-hooks 'whitespace-buffer)
(remove-hook 'kill-buffer-hook 'whitespace-buffer)))
;;;_ , winner
(use-package winner
:diminish winner-mode
:if (not noninteractive)
(winner-mode 1)
(bind-key "M-N" 'winner-redo)
(bind-key "M-P" 'winner-undo)))
;;;_ , workgroups
(use-package workgroups
:diminish workgroups-mode
:if (not noninteractive)
(workgroups-mode 1)
(let ((workgroups-file (expand-file-name "workgroups" user-data-directory)))
(if (file-readable-p workgroups-file)
(wg-load workgroups-file)))
(bind-key "C-\\" 'wg-switch-to-previous-workgroup wg-map)
(bind-key "\\" 'toggle-input-method wg-map)))
;;;_ , wrap-region
(use-package wrap-region
:commands wrap-region-mode
:diminish wrap-region-mode
'(("$" "$")
("/" "/" nil ruby-mode)
("/* " " */" "#" (java-mode javascript-mode css-mode
c-mode c++-mode))
("`" "`" nil (markdown-mode ruby-mode shell-script-mode)))))
;;;_ , write-room
(defun write-room ()
"Make a frame without any bling."
;; to restore:
;; (setq mode-line-format (default-value 'mode-line-format))
(let ((frame (make-frame
'((minibuffer . nil)
(vertical-scroll-bars . nil)
(left-fringe . 0); no fringe
(right-fringe . 0)
(background-mode . dark)
(background-color . "cornsilk")
(foreground-color . "black")
(cursor-color . "green")
(border-width . 0)
(border-color . "black"); should be unnecessary
(internal-border-width . 64); whitespace!
(cursor-type . box)
(menu-bar-lines . 0)
(tool-bar-lines . 0)
(fullscreen . fullboth) ; this should work
(unsplittable . t)))))
(select-frame frame)
(find-file "~/Documents/Notes.txt")
(setq mode-line-format nil
fill-column 65)
(set-window-margins (selected-window) 50 50)))
;;;_ , yasnippet
(use-package yasnippet
:if (not noninteractive)
:diminish yas/minor-mode
:commands (yas/minor-mode yas/expand)
:mode ("/\\.emacs\\.d/snippets/" . snippet-mode)
(hook-into-modes #'(lambda () (yas/minor-mode 1))
(yas/load-directory (expand-file-name "snippets/" user-emacs-directory))
(bind-key "<tab>" 'yas/next-field-or-maybe-expand yas/keymap)
(defun yas/new-snippet (&optional choose-instead-of-guess)
(interactive "P")
(let ((guessed-directories (yas/guess-snippet-directories)))
(switch-to-buffer "*new snippet*")
(set (make-local-variable 'yas/guessed-modes)
(mapcar #'(lambda (d)
(intern (yas/table-name (car d))))
(unless (and choose-instead-of-guess
(not (y-or-n-p "Insert a snippet with useful headers? ")))
(yas/expand-snippet "\
# -*- mode: snippet -*-
# name: $1
# --
(bind-key "C-c y TAB" 'yas/expand)
(bind-key "C-c y n" 'yas/new-snippet)
(bind-key "C-c y f" 'yas/find-snippets)
(bind-key "C-c y r" 'yas/reload-all)
(bind-key "C-c y v" 'yas/visit-snippet-file)))
;;;_ , yaoddmuse
(use-package yaoddmuse
:bind (("C-c w f" . yaoddmuse-browse-page-default)
("C-c w e" . yaoddmuse-edit-default)
("C-c w p" . yaoddmuse-post-library-default)))
;;;_ , zencoding-mode
(use-package zencoding-mode
:commands zencoding-mode
(add-hook 'nxml-mode-hook 'zencoding-mode)
(add-hook 'html-mode-hook 'zencoding-mode)
(add-hook 'html-mode-hook
#'(lambda ()
(bind-key "<return>" 'newline-and-indent html-mode-map))))
(defvar zencoding-mode-keymap (make-sparse-keymap))
(bind-key "C-c C-c" 'zencoding-expand-line zencoding-mode-keymap)))
;;;_. Post initialization
(when window-system
(let ((elapsed (float-time (time-subtract (current-time)
(message "Loading %s...done (%.3fs)" load-file-name elapsed))
(add-hook 'after-init-hook
`(lambda ()
(let ((elapsed (float-time (time-subtract (current-time)
(message "Loading %s...done (%.3fs) [after-init]"
,load-file-name elapsed)))
;; Local Variables:
;; mode: emacs-lisp
;; mode: allout
;; outline-regexp: "^;;;_\\([,. ]+\\)"
;; End:
;;; init.el ends here
Jump to Line
Something went wrong with that request. Please try again.