2013-07-08 01:15:05 +02:00
|
|
|
;; A few handy functions I use in init.el (or not, but they're nice to
|
|
|
|
;; have)
|
|
|
|
|
|
|
|
(defun custom-download-theme (url filename)
|
|
|
|
"Downloads a theme through HTTP and places it in ~/.emacs.d/themes"
|
|
|
|
|
|
|
|
;; Ensure the directory exists
|
|
|
|
(unless (file-exists-p "~/.emacs.d/themes")
|
|
|
|
(make-directory "~/.emacs.d/themes"))
|
|
|
|
|
|
|
|
;; Adds the themes folder to the theme load path (if not already
|
|
|
|
;; there)
|
|
|
|
(unless (member "~/.emacs.d/themes" custom-theme-load-path)
|
|
|
|
(add-to-list 'custom-theme-load-path "~/.emacs.d/themes"))
|
2013-08-05 11:54:38 +02:00
|
|
|
|
2013-07-08 01:15:05 +02:00
|
|
|
;; Download file if it doesn't exist.
|
|
|
|
|
|
|
|
(let ((file
|
|
|
|
(concat "~/.emacs.d/themes/" filename)))
|
|
|
|
(unless (file-exists-p file)
|
|
|
|
(url-copy-file url file))))
|
|
|
|
|
2013-08-06 23:46:26 +02:00
|
|
|
(defun custom-download-script (url filename)
|
2013-07-08 01:39:10 +02:00
|
|
|
"Downloads an Elisp script, places it in ~/.emacs/other and then loads it"
|
2013-08-05 11:54:38 +02:00
|
|
|
|
2013-07-08 01:39:10 +02:00
|
|
|
;; Ensure the directory exists
|
|
|
|
(unless (file-exists-p "~/.emacs.d/other")
|
|
|
|
(make-directory "~/.emacs.d/other"))
|
|
|
|
|
|
|
|
;; Download file if it doesn't exist.
|
|
|
|
(let ((file
|
2013-08-06 23:46:26 +02:00
|
|
|
(concat "~/.emacs.d/other/" filename)))
|
2013-07-08 01:39:10 +02:00
|
|
|
(unless (file-exists-p file)
|
|
|
|
(url-copy-file url file))
|
|
|
|
|
|
|
|
(load file)))
|
|
|
|
|
2013-07-14 23:50:24 +02:00
|
|
|
;; This clones a git repository to 'foldername in .emacs.d
|
|
|
|
;; if there isn't already a folder with that name
|
|
|
|
(defun custom-clone-git (url foldername)
|
|
|
|
"Clones a git repository to .emacs.d/foldername"
|
2013-08-06 23:46:26 +02:00
|
|
|
(let ((fullpath (concat "~/.emacs.d/clones/" foldername)))
|
2013-07-14 23:50:24 +02:00
|
|
|
(unless (file-exists-p fullpath)
|
2013-08-06 23:46:26 +02:00
|
|
|
(async-shell-command (concat "git clone " url " " fullpath)))))
|
2013-07-14 23:50:24 +02:00
|
|
|
|
2013-08-07 00:49:20 +02:00
|
|
|
(defun load-file-if-exists (filename)
|
|
|
|
(if (file-exists-p filename)
|
|
|
|
(load filename)))
|
|
|
|
|
2013-08-05 11:54:38 +02:00
|
|
|
;; These come from magnars, he's got some awesome things.
|
|
|
|
|
|
|
|
(defun goto-line-with-feedback ()
|
|
|
|
"Show line numbers temporarily, while prompting for the line number input"
|
|
|
|
(interactive)
|
|
|
|
(unwind-protect
|
|
|
|
(progn
|
|
|
|
(linum-mode 1)
|
|
|
|
(call-interactively 'goto-line))
|
|
|
|
(linum-mode -1)))
|
|
|
|
|
|
|
|
(defun rotate-windows ()
|
|
|
|
"Rotate your windows"
|
|
|
|
(interactive)
|
|
|
|
(cond ((not (> (count-windows)1))
|
|
|
|
(message "You can't rotate a single window!"))
|
|
|
|
(t
|
|
|
|
(setq i 1)
|
|
|
|
(setq numWindows (count-windows))
|
|
|
|
(while (< i numWindows)
|
|
|
|
(let* (
|
|
|
|
(w1 (elt (window-list) i))
|
|
|
|
(w2 (elt (window-list) (+ (% i numWindows) 1)))
|
|
|
|
|
|
|
|
(b1 (window-buffer w1))
|
|
|
|
(b2 (window-buffer w2))
|
|
|
|
|
|
|
|
(s1 (window-start w1))
|
|
|
|
(s2 (window-start w2))
|
|
|
|
)
|
|
|
|
(set-window-buffer w1 b2)
|
|
|
|
(set-window-buffer w2 b1)
|
|
|
|
(set-window-start w1 s2)
|
|
|
|
(set-window-start w2 s1)
|
|
|
|
(setq i (1+ i)))))))
|
|
|
|
|
|
|
|
(defun untabify-buffer ()
|
|
|
|
(interactive)
|
|
|
|
(untabify (point-min) (point-max)))
|
|
|
|
|
|
|
|
(defun indent-buffer ()
|
|
|
|
(interactive)
|
|
|
|
(indent-region (point-min) (point-max)))
|
|
|
|
|
|
|
|
(defun cleanup-buffer ()
|
|
|
|
"Perform a bunch of operations on the whitespace content of a buffer.
|
|
|
|
Including indent-buffer, which should not be called automatically on save."
|
|
|
|
(interactive)
|
|
|
|
(untabify-buffer)
|
|
|
|
(delete-trailing-whitespace)
|
|
|
|
(indent-buffer))
|
|
|
|
|
2013-07-08 01:15:05 +02:00
|
|
|
;; These come from the emacs starter kit
|
|
|
|
(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))))))
|
|
|
|
|
2013-07-19 13:57:13 +02:00
|
|
|
(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)))))
|
|
|
|
|
2013-07-08 01:15:05 +02:00
|
|
|
(defun esk-add-watchwords ()
|
|
|
|
(font-lock-add-keywords
|
|
|
|
nil '(("\\<\\(FIX\\(ME\\)?\\|TODO\\|HACK\\|REFACTOR\\|NOCOMMIT\\)"
|
|
|
|
1 font-lock-warning-face t))))
|
|
|
|
|
|
|
|
(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))))
|
|
|
|
|
2013-07-15 13:34:18 +02:00
|
|
|
(defun speak (m &optional voice)
|
2013-07-15 13:42:08 +02:00
|
|
|
(shell-command (if 'voice (concat "say -v " voice " \"" m "\"")
|
2013-08-05 11:54:38 +02:00
|
|
|
(concat "say " m))))
|
2013-08-07 00:49:20 +02:00
|
|
|
|
|
|
|
(provide 'init-functions)
|