Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
176 lines (141 sloc) 5.89 KB
;;; starter-kit-defuns.el --- Saner defaults and goodies: function defs.
;; Copyright (c) 2008-2010 Phil Hagelberg and contributors
;; Author: Phil Hagelberg <>
;; URL:
;; Version: 2.0.2
;; Keywords: convenience
;; This file is not part of GNU Emacs.
;;; Commentary:
;; "Emacs outshines all other editing software in approximately the
;; same way that the noonday sun does the stars. It is not just bigger
;; and brighter; it simply makes everything else vanish."
;; -Neal Stephenson, "In the Beginning was the Command Line"
;; This file contains all the function definitions for the starter kit.
;;; License:
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License
;; as published by the Free Software Foundation; either version 3
;; of the License, or (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.
;;; Code:
;;; These belong in prog-mode-hook:
;; We have a number of turn-on-* functions since it's advised that lambda
;; functions not go in hooks. Repeatedly evaling an add-to-list with a
;; hook value will repeatedly add it since there's no way to ensure
;; that a byte-compiled lambda doesn't already exist in the list.
(defun esk-local-column-number-mode ()
(make-local-variable 'column-number-mode)
(column-number-mode t))
(defun esk-local-comment-auto-fill ()
(set (make-local-variable 'comment-auto-fill-only-comments) t)
(auto-fill-mode t))
(defun esk-turn-on-hl-line-mode ()
(when (> (display-color-cells) 8)
(hl-line-mode t)))
(defun esk-turn-on-save-place-mode ()
(require 'saveplace)
(setq save-place t))
(defun esk-turn-on-whitespace ()
(whitespace-mode t))
(defun esk-turn-on-paredit ()
(paredit-mode t))
(defun esk-turn-on-idle-highlight-mode ()
(idle-highlight-mode t))
(defun esk-pretty-lambdas ()
nil `(("(?\\(lambda\\>\\)"
(0 (progn (compose-region (match-beginning 1) (match-end 1)
,(make-char 'greek-iso8859-7 107))
(defun esk-add-watchwords ()
nil '(("\\<\\(FIX\\|TODO\\|FIXME\\|HACK\\|REFACTOR\\|NOCOMMIT\\)"
1 font-lock-warning-face t))))
(add-hook 'prog-mode-hook 'esk-local-column-number-mode)
(add-hook 'prog-mode-hook 'esk-local-comment-auto-fill)
(add-hook 'prog-mode-hook 'esk-turn-on-hl-line-mode)
(add-hook 'prog-mode-hook 'esk-turn-on-save-place-mode)
(add-hook 'prog-mode-hook 'esk-pretty-lambdas)
(add-hook 'prog-mode-hook 'esk-add-watchwords)
(add-hook 'prog-mode-hook 'esk-turn-on-idle-highlight-mode)
(defun esk-prog-mode-hook ()
(run-hooks 'prog-mode-hook))
(defun esk-turn-off-tool-bar ()
(if (functionp 'tool-bar-mode) (tool-bar-mode -1)))
(defun esk-untabify-buffer ()
(untabify (point-min) (point-max)))
(defun esk-indent-buffer ()
(indent-region (point-min) (point-max)))
(defun esk-cleanup-buffer ()
"Perform a bunch of operations on the whitespace content of a buffer."
;; Commands
(defun esk-eval-and-replace ()
"Replace the preceding sexp with its value."
(condition-case nil
(prin1 (eval (read (current-kill 0)))
(error (message "Invalid expression")
(insert (current-kill 0)))))
(defun esk-sudo-edit (&optional arg)
(interactive "p")
(if (or arg (not buffer-file-name))
(find-file (concat "/sudo:root@localhost:" (ido-read-file-name "File: ")))
(find-alternate-file (concat "/sudo:root@localhost:" buffer-file-name))))
(defun esk-lorem ()
"Insert a lorem ipsum."
(insert "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do "
"eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim"
"ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut "
"aliquip ex ea commodo consequat. Duis aute irure dolor in "
"reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla "
"pariatur. Excepteur sint occaecat cupidatat non proident, sunt in "
"culpa qui officia deserunt mollit anim id est laborum."))
(defun esk-suck-it (suckee)
"Insert a comment of appropriate length about what can suck it."
(interactive "MWhat can suck it? ")
(let ((prefix (concat ";; " suckee " can s"))
(postfix "ck it!")
(col (current-column)))
(insert prefix)
(dotimes (_ (- 80 col (length prefix) (length postfix))) (insert "u"))
(insert postfix)))
(defun esk-insert-date ()
"Insert a time-stamp according to locale's date and time format."
(insert (format-time-string "%c" (current-time))))
(defun esk-pairing-bot ()
"If you can't pair program with a human, use this instead."
(message (if (y-or-n-p "Do you have a test for that? ") "Good." "Bad!")))
(defun esk-paredit-nonlisp ()
"Turn on paredit mode for non-lisps."
(set (make-local-variable 'paredit-space-for-delimiter-predicates)
'((lambda (endp delimiter) nil)))
(paredit-mode 1))
;; A monkeypatch to cause annotate to ignore whitespace
(defun vc-git-annotate-command (file buf &optional rev)
(let ((name (file-relative-name file)))
(vc-git-command buf 0 name "blame" "-w" rev)))
(provide 'starter-kit-defuns)
;;; starter-kit-defuns.el ends here
Jump to Line
Something went wrong with that request. Please try again.