lwu (owner)

Revisions

gist: 5520 Download_button fork
public
Description:
my .emacs cfg
Public Clone URL: git://gist.github.com/5520.git
Embed All Files: show embed
.emacs.lisp #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
;; lwu .emacs 2008 (CarbonEmacs)
 
;; paths and directories
(add-to-list 'load-path "~/src/elisp")
 
(custom-set-variables)
(custom-set-faces)
 
; (require 'tramp)
(setq tramp-default-method "ssh")
; (require 'whitespace-visual-mode) ; XEmacs-only
; (set-frame-font "Andale Mono:20") ; XEmacs-only
 
;; (mac-font-panel-mode) ; CarbonEmacs-only
(set-default-font "-apple-monaco-medium-r-normal--18-0-72-72-m-0-iso10646-1")
 
(set-frame-size (selected-frame) 110 30) ; TODO condp non -nw mode
 
(server-start) ; for emacsclient
 
(require 'recentf)
(recentf-mode 1)
(require 'icicles)
(setq visible-bell t)
(transient-mark-mode t) ; region mark highlighting
; (icy-mode t) ; icicle?
(global-hl-line-mode t)
(set-face-background 'hl-line "#FFF") ; Emacs 22-only
 
(custom-set-variables
 '(mwheel-follow-mouse t)
 '(paren-mode (quote sexp) nil (paren))
 '(pc-select-selection-keys-only nil)
 '(delete-key-deletes-forward t)
 '(column-number-mode t)
 '(recent-files-permanent-submenu t)
 ; '(gnuserv-program (concat exec-directory "/gnuserv"))
 '(c-default-style "k&r")
 '(line-number-mode t)
 '(c-basic-offset 4)
 '(user-mail-address "lwu2@" t)
 '(query-user-mail-address nil)
 '(font-lock-mode t nil (font-lock))
 )
 
 
(define-key global-map [(meta return)] 'mac-toggle-max-window)
(defun mac-toggle-max-window ()
  (interactive)
  (set-frame-parameter nil 'fullscreen (if (frame-parameter nil 'fullscreen)
                                           nil
                                           'fullboth)))
(require 'tabbar)
(tabbar-mode t)
(set-face-attribute
   'tabbar-default-face nil
   :background "gray60")
  (set-face-attribute
   'tabbar-unselected-face nil
   :background "gray85"
   :foreground "gray30"
   :box nil)
  (set-face-attribute
   'tabbar-selected-face nil
   :background "#f2f2f6"
   :foreground "black"
   :box nil)
  (set-face-attribute
   'tabbar-button-face nil
   :box '(:line-width 1 :color "gray72" :style released-button))
  (set-face-attribute
   'tabbar-separator-face nil
   :height 0.7)
 
(define-key global-map [(control prior)] 'tabbar-backward)
(define-key global-map [(control next)] 'tabbar-forward)
 
(cond ((fboundp 'global-font-lock-mode)
       ;; Turn on font-lock in all modes that support it
       (global-font-lock-mode t)
       ;; Maximum colors
       (setq font-lock-maximum-decoration t)))
 
; Key bindings
; ____________
 
(global-set-key [(control home)] 'beginning-of-buffer)
(global-set-key [(control end)] 'end-of-buffer)
 
(fset 'duplicate-line [?\C-a ?\C- down ?\M-w ?\C-y ?\C-p])
(global-set-key [(control c) (y)] 'duplicate-line)
 
; Meta [ and ] enlarge and shrink the current window
(global-set-key [(meta \[)] 'enlarge-window)
(global-set-key [(meta \])] 'shrink-window)
 
; C-\ kills current buffer.
(global-set-key [(control \\)] 'kill-this-buffer)
 
; [(control c) r] query and replaces
(global-set-key [(control c) (r)] 'query-replace)
 
; [(control c) b] opens up bookmark list
(global-set-key [(control c) (b)] 'bookmark-bmenu-list)
 
(defun switch-to-other-buffer (&optional norecord)
      "Select most recently selected buffer other than the current buffer.
Optional second arg NORECORD non-nil means
do not put this buffer at the front of the list of recently selected ones."
      (interactive)
      (switch-to-buffer (other-buffer (current-buffer)) norecord))
 
; (control meta l) switches to other buffer
(global-set-key [(control meta l)] 'switch-to-other-buffer)
 
; [(control .)] switches to other buffer
(global-set-key [(control \.)] 'switch-to-other-buffer)
 
; (control shift 1) opens a shell
;(global-set-key [(control !)] 'shell)
(global-set-key [(control !)] 'tshell)
 
;;; swiped from $EMACS_PATH/19.30/lisp/dired.el
(defvar dired-font-lock-keywords
  '(;; Put directory headers in italics.
    ("^ \\(/.+\\)" 1 font-lock-type-face)
    ;; Put symlinks in bold italics.
    ("\\([^ ]+\\) -> [^ ]+$" . font-lock-function-name-face)
    ;; Put marks in bold.
    ("^[^ ]" . font-lock-reference-face)
    ;; Put files that are subdirectories in bold.
    ("^..d.* \\([^ ]+\\)$" 1 font-lock-keyword-face))
  "Additional expressions to highlight in Dired mode.")
 
(put 'dired-mode 'font-lock-defaults 'dired-font-lock-keywords)
 
(defun delete-backward-line ()
  (interactive)
  (kill-line -0))
 
(global-set-key [(control backspace)] 'delete-backward-line)
 
; [(control x) b] replaces normal switch-to-buffer with cooler iswitchb-buffer
; which does regexp searching on the fly for easier buffer switching
; (require 'iswitchb)
; (global-set-key [(control x) (b)] 'iswitchb-buffer)
 
(setq ido-confirm-unique-completion t) ; wait for RET even if unique
(setq ido-default-buffer-method 'samewindow)
(setq ido-use-filename-at-point t)
; (ido-mode t) ; comment out until fix C-x C-f up issue
; (ido-everywhere t)
; (setq ido-enable-flex-matching t)
; (set-face-background 'ido-first-match "white")
; (set-face-foreground 'ido-subdir "blue3")
 
(windmove-default-keybindings 'meta) ; thx emacsblog.org
 
(global-set-key [(control c) g] 'grep)
 
(global-set-key [(control c) (f)] 'font-lock-mode)
 
; (meta n) and (meta p) scroll buffer ahead/behind
(defalias 'scroll-ahead 'scroll-up)
(defalias 'scroll-behind 'scroll-down)
 
(defun scroll-n-lines-ahead (&optional n)
  "Scroll ahead N lines (1 by default)."
  (interactive "P")
  (scroll-ahead (prefix-numeric-value n)))
 
(defun scroll-n-lines-behind (&optional n)
  "Scroll behind N lines (1 by default)."
  (interactive "P")
  (scroll-behind (prefix-numeric-value n)))
 
(global-set-key [(meta n)] 'scroll-n-lines-ahead)
(global-set-key [(meta p)] 'scroll-n-lines-behind)
 
;;;; --- bounces from one sexp "(){}[]<>" to another (ala vi's %)
;;;; --- written by Joe Casadonte (joc@netaxs.com)
(defun joc-bounce-sexp ()
  "Will bounce between matching parens just like % in vi"
  (interactive)
  (let ((prev-char (char-to-string (preceding-char)))
        (next-char (char-to-string (following-char))))
        (cond ((string-match "[[{(<]" next-char) (forward-sexp 1))
                  ((string-match "[\]})>]" prev-char) (backward-sexp 1))
                  (t (error "%s" "Not on a paren, brace, or bracket")))))
 
(global-set-key [(control =)] 'joc-bounce-sexp)
 
; delete line and remaining blanks (like dd in vi)
(global-set-key [(control delete)] '(lambda ()
(interactive)
(kill-line 1)))
 
; better buffer selection
(global-set-key [(control x) (control b)] 'electric-buffer-list)
 
; Options
; _______
 
;;{{{ Uniqify Buffer Names
(require 'uniquify)
(setq uniquify-buffer-name-style 'forward) ;/dir1/dir2/non-unique-file
 
; control , and . move back and forth through the buffer list
; (require 'swbuff) ; http://perso.wanadoo.fr/david.ponce/more-elisp.html
; (global-set-key [(control ,)] 'swbuff-switch-to-previous-buffer)
; (global-set-key [(control \.)] 'swbuff-switch-to-next-buffer)
 
(require 'bs) ; http://home.netsurf.de/olaf.sylvester/emacs/
; nicer than list-buffers and electric-buffer-list
(global-set-key [(control x) (control b)] 'bs-show)
 
; enable parens matching
(show-paren-mode 1)
 
; make y/n suffice for yes/no q
(fset 'yes-or-no-p 'y-or-n-p)
 
; Misc
; ____
 
; Make sure emacs isn't accidentally killed
(defun paranoid-exit-from-emacs()
  (interactive)
  (if (yes-or-no-p "Do you want to exit? ")
      (save-buffers-kill-emacs)))
(global-set-key "\C-x\C-c" 'paranoid-exit-from-emacs)
 
; code copied from XEmacs's Options\Edit Init File menu code
(defun edit-dot-emacs ()
  "Edits the user's .emacs file"
  (interactive)
  (progn
    (find-file (or user-init-file "~/.xemacs/custom.el"))
    (or (eq major-mode (quote emacs-lisp-mode)) (emacs-lisp-mode))))
 
(global-set-key [(control c) (d)] 'edit-dot-emacs)
 
; calendar
(global-set-key [(control c) (c)] 'calendar)
 
(global-set-key [(control c) (g)] 'goto-line)
 
(require 'bookmark)
(define-key bookmark-bmenu-mode-map [return] 'bookmark-bmenu-select)
 
; enable pending delete (keystrokes delete then overwrite
; selected text)
(cond
 ((fboundp 'turn-on-pending-delete)
  (turn-on-pending-delete))
 ((fboundp 'pending-delete-on)
  (pending-delete-on t)))
 
; enable pending delete (keystrokes delete then overwrite
; selected text)
; (pending-delete-mode)
 
; don't display anything in modeline when pending delete is on
(setq pending-delete-modeline-string "")
 
; Enable mouse wheel
(defun scroll-down-whee (lines-to-scroll)
  (interactive)
  (scroll-down lines-to-scroll))
 
(defun scroll-up-whee (lines-to-scroll)
  (interactive)
  (scroll-up lines-to-scroll))
 
(defun scroll-down-less ()
  (interactive)
  (scroll-down-whee 3))
 
(defun scroll-up-less ()
  (interactive)
  (scroll-up-whee 3))
 
(defun scroll-down-more ()
  (interactive)
  (scroll-down-whee 8))
 
(defun scroll-up-more ()
  (interactive)
  (scroll-up-whee 8))
 
; normal mouse scroll
(global-set-key [button4] 'scroll-down-less)
(global-set-key [button5] 'scroll-up-less)
 
; control scrolls faster
(global-set-key [(control button4)] 'scroll-down-more)
(global-set-key [(control button5)] 'scroll-up-more)
 
 
; c indenting style
(setq c-set-style 'k&r)
 
; enable interactive completion mode in minibuffer
(icomplete-mode t)
 
;convert a buffer from dos ^M end of lines to unix end of lines
(defun dos2unix ()
  (interactive)
  (goto-char (point-min))
  (while (search-forward "\r" nil t)
    (replace-match "")))
 
;versa vice
(defun unix2dos ()
  (interactive)
  (goto-char (point-min))
  (while (search-forward "\n" nil t)
    (replace-match "\r\n")))
 
 
;; (taken from sample .emacs in XEmacs Help)
;;
;; Change the pointer used during garbage collection.
;;
;; Note that this pointer image is rather large as pointers go,
;; and so it won't work on some X servers (such as the MIT
;; R5 Sun server) because servers may have lamentably small
;; upper limits on pointer size.
;;(if (featurep 'xpm)
;; (set-glyph-image gc-pointer-glyph
;; (expand-file-name "trash.xpm" data-directory)))
;;
;; Here's another way to do that: it first tries to load the
;; pointer once and traps the error, just to see if it's
;; possible to load that pointer on this system; if it is,
;; then it sets gc-pointer-glyph, because we know that
;; will work. Otherwise, it doesn't change that variable
;; because we know it will just cause some error messages.
 
;; (cond (running-xemacs
;; (if (featurep 'xpm)
;; (let ((file (expand-file-name "recycle.xpm" data-directory)))
;; (if (condition-case error
;; ;; check to make sure we can use the pointer.
;; (make-image-instance file nil
;; '(pointer))
;; (error nil)) ; returns nil if an error occurred.
;; (set-glyph-image gc-pointer-glyph file))))))
 
(put 'narrow-to-region 'disabled nil)