Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
tree: 53627f575e
Fetching contributors…

Cannot retrieve contributors at this time

206 lines (166 sloc) 7.001 kB
;;; starter-kit-defuns.el --- Saner defaults and goodies: function defs.
;;
;; Copyright (c) 2008-2010 Phil Hagelberg and contributors
;;
;; Author: Phil Hagelberg <technomancy@gmail.com>
;; URL: http://www.emacswiki.org/cgi-bin/wiki/StarterKit
;; Version: 2.0
;; 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
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; 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:
(require 'thingatpt)
(require 'imenu)
;; Network
(defun esk-view-url ()
"Open a new buffer containing the contents of URL."
(interactive)
(let* ((default (thing-at-point-url-at-point))
(url (read-from-minibuffer "URL: " default)))
(switch-to-buffer (url-retrieve-synchronously url))
(rename-buffer url t)
(cond ((search-forward "<?xml" nil t) (xml-mode))
((search-forward "<html" nil t) (html-mode)))))
;; Buffer-related
(defun esk-flatten-assoc-tree (tree pred)
"Returns an alist of only (key . leaf) pairs in TREE. PRED
determines whether a value is a sub-alist or a leaf."
(flet ((inner (lst)
(mapcan (lambda (elt)
(cond ((atom elt) nil)
((funcall pred elt) (inner elt))
(t (list elt))))
lst)))
(inner tree)))
(defun esk-ido-imenu ()
"Queries with `ido-completing-read' a symbol in the buffer's
imenu index, then jumps to that symbol's location."
(interactive)
(goto-char
(let ((lst (nreverse (esk-flatten-assoc-tree
(imenu--make-index-alist) 'imenu--subalist-p))))
(cdr (assoc (ido-completing-read "Symbol: " (mapcar 'car lst)) lst)))))
;;; These belong in coding-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 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 window-system (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-pretty-lambdas ()
(font-lock-add-keywords
nil `(("(?\\(lambda\\>\\)"
(0 (progn (compose-region (match-beginning 1) (match-end 1)
,(make-char 'greek-iso8859-7 107))
nil))))))
(defun esk-add-watchwords ()
(font-lock-add-keywords
nil '(("\\<\\(FIX\\|TODO\\|FIXME\\|HACK\\|REFACTOR\\):"
1 font-lock-warning-face t))))
(add-hook 'esk-coding-hook 'esk-local-column-number-mode)
(add-hook 'esk-coding-hook 'esk-local-comment-auto-fill)
(add-hook 'esk-coding-hook 'esk-turn-on-hl-line-mode)
(add-hook 'esk-coding-hook 'esk-turn-on-save-place-mode)
(add-hook 'esk-coding-hook 'esk-pretty-lambdas)
(add-hook 'esk-coding-hook 'esk-add-watchwords)
(add-hook 'esk-coding-hook 'idle-highlight)
(defun esk-run-coding-hook ()
"Enable things that are convenient across all coding buffers."
(run-hooks 'esk-coding-hook))
(defun esk-turn-off-tool-bar ()
(tool-bar-mode -1))
(defun esk-untabify-buffer ()
(interactive)
(untabify (point-min) (point-max)))
(defun esk-indent-buffer ()
(interactive)
(indent-region (point-min) (point-max)))
(defun esk-cleanup-buffer ()
"Perform a bunch of operations on the whitespace content of a buffer."
(interactive)
(esk-indent-buffer)
(esk-untabify-buffer)
(delete-trailing-whitespace))
(defun esk-recentf-ido-find-file ()
"Find a recent file using ido."
(interactive)
(let ((file (ido-completing-read "Choose recent file: " recentf-list nil t)))
(when file
(find-file file))))
;; Other
(defun esk-eval-and-replace ()
"Replace the preceding sexp with its value."
(interactive)
(backward-kill-sexp)
(condition-case nil
(prin1 (eval (read (current-kill 0)))
(current-buffer))
(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."
(interactive)
(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-insert-date ()
"Insert a time-stamp according to locale's date and time format."
(interactive)
(insert (format-time-string "%c" (current-time))))
(defun esk-pairing-bot ()
"If you can't pair program with a human, use this instead."
(interactive)
(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-delimiter-chars)
(list ?\"))
(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.