Added EmacsConfigurationAndHelp directory
[temp.git] / .emacs.d / wl-elisp-funcs.el
blobefa802ef707dfc7e626b162d54a4bebee84257fd
1 ;wl_elisp.el
2 (defun wombat () "Load the wombat color theme."
3 (interactive)
4 (if (file-exists-p "~/.emacs.d/color-theme/themes/color-theme-wombat.el")
5 (load-file "~/.emacs.d/color-theme/themes/color-theme-wombat.el")))
7 (defun reload () "Reloads .emacs interactively"
8 (interactive)
9 (if (file-exists-p "~/.emacs")
10 (load-file "~/.emacs")))
12 (defun count-words-buffer ()
13 "Count the number of words in the current buffer;
14 print a message in the minibuffer with the result."
15 (interactive)
16 (save-excursion
17 (let ((count 0))
18 (goto-char (point-min))
19 (while (< (point) (point-max))
20 (forward-word 1)
21 (setq count (1+ count)))
22 (message "buffer contains %d words." count))))
24 ; NOTE: I attempted to emulate a solution I found here:
25 ;http://stackoverflow.com/questions/1037545/how-to-replace-forwardslashes-with-backslashes-in-a-string-in-lisp-for-emacs
26 ; but failed. Wound up using this which I got from running replace-regexp on a region and hitting C-x ESC ESC and pasted this into my func:
27 ; (replace-regexp "\\\\" "/" nil (if (and transient-mark-mode mark-active) (region-beginning)) (if (and transient-mark-mode mark-active) (region-end)))
28 ; Currently examining this tutorial so I can figure out why the stackoverflow solution failed.
29 ;http://xahlee.org/emacs/lisp_regex_replace_func.html
30 (defun replace-backslashes () "Replace the backslashes with slashes."
31 (interactive)
32 (save-excursion)
33 (replace-regexp "\\\\" "/" nil
34 (if (and transient-mark-mode mark-active) (region-beginning))
35 (if (and transient-mark-mode mark-active) (region-end))))
37 ;;The following came from here:
38 ;http://lispy.wordpress.com/category/regular-expressions/
39 ;It's a good example of how you can set up text processing routines
40 ;Using defmacro instead of just a defun lets you defines the key binding at the same time that the replacement function is defined. This also has it's drawbacks, lispy gives this as his rationale:
41 ;I went with a macro because once I get my regular expression from re-builder, I wanted to be able to write the code for everything as quickly as possible. With “defreplacer”, all I needed was four arguments and I was good to go.
42 (defmacro defreplacer (name description search-for replace-with chord)
43 `(progn
44 (defun ,name (n)
45 ,description
46 (interactive "p")
47 (query-replace-regexp ,search-for
48 ,replace-with
49 nil
50 (if (and transient-mark-mode mark-active)
51 (region-beginning))
52 (if (and transient-mark-mode mark-active)
53 (region-end))))
54 (global-set-key (kbd ,chord) ',name)))
56 (defreplacer pull-text-from-semi-colons
57 "Remove text from between two semi-colon signs."
58 "[ ]*;\\([a-z]*\\);[ ]*" ; use double back slash to 'escape' in quotes
59 "\\1"
60 "C-c ;")
63 (defun remove-blank-lines (n)
64 "Removes blank lines from a buffer"
65 (interactive "p") ; n = value passed by the C-u “universal argument”
66 (query-replace-regexp "
68 +" "
69 " nil
70 (if (and transient-mark-mode mark-active) (region-beginning))
71 (if (and transient-mark-mode mark-active) (region-end))))