1;; customisations to the general emacs environment itself
3;; stop confirmation required for opening largish files.
4(setq large-file-warning-threshold nil)
5;; Set winner mode on, to track window configs if needed
8;; Make all "yes or no" prompts show "y or n" instead
9(fset 'yes-or-no-p 'y-or-n-p)
12(if (fboundp 'tool-bar-mode) (tool-bar-mode -1))
14;; Hippie Expansion stuff. Set hippie-expansion to C-tab
15;;(require-if-exists 'hippie-exp)
16(global-set-key (kbd "C-<tab>") 'hippie-expand)
17;; Add python completion to avoid altering hippie-exp.el itself.
18;;(add-to-list 'hippie-expand-try-functions-list 'try-complete-py-complete-symbol)
20;; Syntax highlighting on:
21(global-font-lock-mode 1)
22(defconst font-lock-maximum-decoration t)
25;; (add-to-list 'load-path "~/emacs/lisp/addons/icicles")
27;;(require-if-exists 'icicles)
28;; Add the current line number to the mode bar
31;; Add the current column number to the mode bar
34;; Enable highlighting when marking a region
35(setq transient-mark-mode t)
37(global-set-key "\C-cl" 'goto-line)
38(global-set-key "\C-Z" 'undo)
40;; Reload .emacs file by typing: Mx reload.
41(defun reload () "Reloads .emacs interactively."
46(setq display-time-24hr-format t)
48;;http://www.emacsblog.org/2007/04/09/highlight-the-current-line/
49(global-hl-line-mode 0)
50;; To customize the background color
51(set-face-background 'hl-line "#040") ;; Emacs 22 Only
61(when (fboundp 'windmove-default-keybindings)
62 (windmove-default-keybindings))
63;; Emacs server support
67;; Bind f3 to repeat our last keyboard macro
68(global-set-key [f3] 'call-last-kbd-macro)
70;; Make various default-unavailable commands permanently available
71(put 'downcase-region 'disabled nil)
72(put 'upcase-region 'disabled nil)
73(put 'narrow-to-region 'disabled nil)
75;; Disable insert key on keyboard
76(global-set-key (quote [insert]) nil)
78;; Bindings for replace string and replace regex
79(global-set-key "\C-crs" 'replace-string)
80(global-set-key "\C-crr" 'replace-regexp)
81;; Binding to delete-region
82(global-set-key "\C-cd" 'delete-region)
85 "Remove intrusive CTRL-Ms from the buffer"
88 (goto-char (point-min))
89 (replace-string "\C-m\C-j" "\C-j")))
92;; Resize to 3/4 - 1/4 instead of 1/2-1/2
93(defun three-quarters-window ()
94 "Resizes current window big"
96 (let ((size (- (truncate (* .75 (frame-height))) (window-height))))
98 (enlarge-window size))))
99(global-set-key "\C-x7" 'three-quarters-window)
101;; Toggle window dedication
102(defun toggle-window-dedicated ()
103"Toggle whether the current active window is dedicated or not"
106(if (let (window (get-buffer-window (current-buffer)))
107 (set-window-dedicated-p window
108 (not (window-dedicated-p window))))
109"Window '%s' is dedicated"
110"Window '%s' is normal")
113(global-set-key [pause] 'toggle-window-dedicated)
115(if (require-if-exists 'browse-kill-ring)
116 (browse-kill-ring-default-keybindings))
118;; Advise killing function to operate on current line if nothing is selected
119(defadvice kill-ring-save (before slick-copy activate compile) "When called
120 interactively with no active region, copy a single line instead."
121 (interactive (if mark-active (list (region-beginning) (region-end)) (message
122 "Copied line") (list (line-beginning-position) (line-beginning-position
125(defadvice kill-region (before slick-cut activate compile)
126 "When called interactively with no active region, kill a single line instead."
128 (if mark-active (list (region-beginning) (region-end))
129 (list (line-beginning-position)
130 (line-beginning-position 2)))))
132(defun dont-kill-emacs ()
133 "Print a message when the shortcut to kill emacs is pressed, listing the command to run instead"
135 (error (substitute-command-keys "To exit emacs: \\[kill-emacs]")))
137(global-set-key "\C-x\C-c" 'dont-kill-emacs)
141;; Set font for X or win32 systems, leaving unchanged otherwise
142(if (equal window-system 'x)
143 (set-frame-font "-adobe-courier-medium-r-normal--12-120-75-75-m-70-iso8859-1" t))
144(if (equal window-system 'w32)
145 (set-frame-font "-outline-Lucida Console-normal-r-normal-normal-13-97-96-96-c-*-iso8859-1" t)))
146(add-hook 'term-setup-hook 'set-font)
148;; uniquify buffer names
149(if (require-if-exists 'uniquify)
152 uniquify-buffer-name-style 'post-forward
153 uniquify-strip-common-suffix nil)
154 (setq uniquify-after-kill-buffer-p t) ; rename after killing uniquified
155 (setq uniquify-ignore-buffers-re "^\\*") ; don't muck with special
156 ; buffers (or Gnus mail
160;; Unbind the suspend-frame key to prevent accidental emacs suspension
161(global-unset-key "\C-x\C-z")
163; An unfill region command
164(defun unfill-region (begin end)
165 "Remove all linebreaks in a region but leave paragraphs,
166 indented text (quotes,code) and lines starting with an asterix (lists) intact."
168 (replace-regexp "\\([^\n]\\)\n\\([^ *\n]\\)" "\\1 \\2" nil begin end))
170(require-if-exists 'hide-lines)
172(setq apropos-do-all t)
173(setq confirm-nonexistent-file-or-buffer nil)
175;;Add a function to evaluate sexp's in place and provide the result. From emacs.wordpress.com
176;;bound to C-c e - which was unused
177(defun fc-eval-and-replace ()
178 "Replace the preceding sexp with its value."
182 (prin1 (eval (read (current-kill 0)))
184 (error (message "Invalid expression")
185 (insert (current-kill 0)))))
187(global-set-key (kbd "C-c e") 'fc-eval-and-replace)
189;; A function to be used progromatically to replace all occurences of OLD in a supplied string with NEW
190(defun replace-in-string (strmatch old new)
191(while (string-match old strmatch)
192 (setq strmatch (replace-match new t t strmatch)))
196(load "regex-tool.el" t)
198;; Bring in extra-edit stuff
199(require-if-exists 'extraedit)
200(require-if-exists 'htmlize)
203(require-if-exists 'yasnippet "yasnippet/")
205(setq yas/root-directory '("~/emacs/lisp/addons/kvw_yasnippets"
206 "~/emacs/lisp/addons/yasnippet/snippets/"))
207(mapc 'yas/load-directory yas/root-directory)
209;; only show battery mode if the system name reflects the term "laptop"
210(if (string-match ".*?-laptop.*" system-name)
211 (display-battery-mode t)
212 (display-battery-mode nil))
215 (if (require-if-exists 'color-theme "color-theme/")
217 (color-theme-initialize)
218 (color-theme-dark-laptop)
219 ;; (load-file "color-theme/color-theme-chocolate-rain.el")
220 ;; (color-theme-chocolate-rain)
225(put 'set-goal-column 'disabled nil)
227;; Advice for rectangle open and close, to add optional better whitespace handling
228;; Courtesy Jon McKeown
229(defadvice open-rectangle (around saner-open-rect (start end &optional fill ragged))
230 "Blank out the region-rectangle, shifting text right.
232Default behaviour is to insert whitespace at the left edge of the rectangle,
233moving text in the region to the column after the right edge.
235Interactively, a - argument does the whitespace insertion at the first
236whitespace after existing text. A prefix argument will fill short lines
237with whitespace. Both options can be applied.
239When called from a program the rectangle's corners are START and END, and
240FILL and RAGGED have the effect of a prefix and - argument respectively."
241 (interactive "*r\nP")
242 (when (called-interactively-p)
243 (if (< (prefix-numeric-value fill) 0) (setq ragged t))
244 (if (eq fill '-) (setq fill nil)))
245 (apply-on-rectangle 'open-rectangle-line start end fill ragged)
248(defadvice open-rectangle-line (around
250 (startcol endcol fill ragged))
251 (let ((endpos (+ (point-at-bol) endcol)))
252 (when (= (move-to-column startcol (if fill t 'coerce)) startcol)
253 (unless (and (not fill)
254 (= (point) (point-at-eol)))
255 (if ragged (skip-syntax-forward "^ " endpos))
256 (indent-to endcol)))))
258(defadvice delete-whitespace-rectangle-line (around
259 sane-del-ws-rect-line
260 (startcol endcol fill ragged))
261 (let ((endpos (+ (point-at-bol) endcol)))
262 (when (= (move-to-column startcol (if fill t 'coerce)) startcol)
263 (unless (= (point) (point-at-eol))
264 (if ragged (skip-syntax-forward "^ " endpos))
265 (delete-region (point) (progn
266 (skip-syntax-forward " " endpos)
269(defadvice delete-whitespace-rectangle (around
271 (start end &optional fill ragged))
272 "Delete continuous whitespace within the rectangle.
273Default behaviour operates only on lines containing whitespace in the
274left column of the rectangle, and deletes continuous whitespace up to
277Interactively, a - argument causes the deletion to apply on every line
278and start at the first whitespace after the left column. A prefix
279argument will space-fill short lines as far as the left column. Both can
282When called from a program the rectangle's corners are START and END, and
283FILL and RAGGED have the effect of prefix and - arguments respectively."
284 (interactive "*r\nP")
285 (when (called-interactively-p)
286 (if (< (prefix-numeric-value fill) 0) (setq ragged t))
287 (if (eq fill '-) (setq fill nil)))
288 (apply-on-rectangle 'delete-whitespace-rectangle-line start end fill ragged))
290;; Google weather, from http://julien.danjou.info/google-weather-el.html
291(require-if-exists 'google-weather)
293(provide 'de_emacs_env)