changelog shortlog tags changeset files revisions annotate raw

de_emacs_env.el

changeset 66: 5b737eefe5ea
parent:524e6294a380
author: kim.vanwyk
date: Wed Nov 10 15:19:03 2010 +0200 (18 months ago)
permissions: -rw-r--r--
description: Adding CSharp Mode and Google Weather
1;; customisations to the general emacs environment itself
2
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
6(winner-mode 1)
7
8;; Make all "yes or no" prompts show "y or n" instead
9(fset 'yes-or-no-p 'y-or-n-p)
10
11;; Remove toolbar
12(if (fboundp 'tool-bar-mode) (tool-bar-mode -1))
13
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)
19
20;; Syntax highlighting on:
21(global-font-lock-mode 1)
22(defconst font-lock-maximum-decoration t)
23
24;; - Icicles
25;; (add-to-list 'load-path "~/emacs/lisp/addons/icicles")
26;; Icicles Stuff:
27;;(require-if-exists 'icicles)
28;; Add the current line number to the mode bar
29(line-number-mode t)
30
31;; Add the current column number to the mode bar
32(column-number-mode t)
33
34;; Enable highlighting when marking a region
35(setq transient-mark-mode t)
36
37(global-set-key "\C-cl" 'goto-line)
38(global-set-key "\C-Z" 'undo)
39
40;; Reload .emacs file by typing: Mx reload.
41(defun reload () "Reloads .emacs interactively."
42 (interactive)
43 (load "~/.emacs"))
44
45(display-time-mode t)
46(setq display-time-24hr-format t)
47
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
52
53;; find file at point
54(ffap-bindings)
55
56;; enable ido-mode
57(ido-mode 1)
58
59
60;; Window navigation
61(when (fboundp 'windmove-default-keybindings)
62 (windmove-default-keybindings))
63;; Emacs server support
64(server-start)
65
66
67;; Bind f3 to repeat our last keyboard macro
68(global-set-key [f3] 'call-last-kbd-macro)
69
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)
74
75;; Disable insert key on keyboard
76(global-set-key (quote [insert]) nil)
77
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)
83
84(defun ridm ()
85 "Remove intrusive CTRL-Ms from the buffer"
86 (interactive)
87 (save-excursion
88 (goto-char (point-min))
89 (replace-string "\C-m\C-j" "\C-j")))
90
91
92;; Resize to 3/4 - 1/4 instead of 1/2-1/2
93(defun three-quarters-window ()
94 "Resizes current window big"
95 (interactive)
96 (let ((size (- (truncate (* .75 (frame-height))) (window-height))))
97 (if (> size 0)
98 (enlarge-window size))))
99(global-set-key "\C-x7" 'three-quarters-window)
100
101;; Toggle window dedication
102(defun toggle-window-dedicated ()
103"Toggle whether the current active window is dedicated or not"
104(interactive)
105(message
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")
111(current-buffer)))
112
113(global-set-key [pause] 'toggle-window-dedicated)
114
115(if (require-if-exists 'browse-kill-ring)
116 (browse-kill-ring-default-keybindings))
117
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
123 2)))))
124
125(defadvice kill-region (before slick-cut activate compile)
126 "When called interactively with no active region, kill a single line instead."
127 (interactive
128 (if mark-active (list (region-beginning) (region-end))
129 (list (line-beginning-position)
130 (line-beginning-position 2)))))
131
132(defun dont-kill-emacs ()
133 "Print a message when the shortcut to kill emacs is pressed, listing the command to run instead"
134 (interactive)
135 (error (substitute-command-keys "To exit emacs: \\[kill-emacs]")))
136
137(global-set-key "\C-x\C-c" 'dont-kill-emacs)
138
139(defun set-font ()
140(interactive)
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)
147
148;; uniquify buffer names
149(if (require-if-exists 'uniquify)
150 (progn
151 (setq
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
157 ; buffers)
158 ))
159
160;; Unbind the suspend-frame key to prevent accidental emacs suspension
161(global-unset-key "\C-x\C-z")
162
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."
167 (interactive "r")
168 (replace-regexp "\\([^\n]\\)\n\\([^ *\n]\\)" "\\1 \\2" nil begin end))
169
170(require-if-exists 'hide-lines)
171
172(setq apropos-do-all t)
173(setq confirm-nonexistent-file-or-buffer nil)
174
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."
179 (interactive)
180 (backward-kill-sexp)
181 (condition-case nil
182 (prin1 (eval (read (current-kill 0)))
183 (current-buffer))
184 (error (message "Invalid expression")
185 (insert (current-kill 0)))))
186
187(global-set-key (kbd "C-c e") 'fc-eval-and-replace)
188
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)))
193strmatch)
194
195;; Add regex-IDE
196(load "regex-tool.el" t)
197
198;; Bring in extra-edit stuff
199(require-if-exists 'extraedit)
200(require-if-exists 'htmlize)
201
202;; yasnippet
203(require-if-exists 'yasnippet "yasnippet/")
204(yas/initialize)
205(setq yas/root-directory '("~/emacs/lisp/addons/kvw_yasnippets"
206 "~/emacs/lisp/addons/yasnippet/snippets/"))
207(mapc 'yas/load-directory yas/root-directory)
208
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))
213
214 ;; Color Theme
215 (if (require-if-exists 'color-theme "color-theme/")
216 (progn
217 (color-theme-initialize)
218 (color-theme-dark-laptop)
219 ;; (load-file "color-theme/color-theme-chocolate-rain.el")
220 ;; (color-theme-chocolate-rain)
221 ))
222
223
224(set-font)
225(put 'set-goal-column 'disabled nil)
226
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.
231
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.
234
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.
238
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)
246 (goto-char start))
247
248(defadvice open-rectangle-line (around
249 sane-open-rect-line
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)))))
257
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)
267 (point)))))))
268
269(defadvice delete-whitespace-rectangle (around
270 sane-del-ws-rect
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
275the right column.
276
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
280be applied.
281
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))
289
290;; Google weather, from http://julien.danjou.info/google-weather-el.html
291(require-if-exists 'google-weather)
292
293(provide 'de_emacs_env)