public
Description: my .emacs file
Homepage:
Clone URL: git://github.com/ki/my-dot-emacs.git
my-dot-emacs / dot-emacs.txt
100644 495 lines (401 sloc) 15.736 kb
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
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
(message "***** .emacs loading *****")
 
; thank you stevey. i love you :-)
 
(defvar emacs-root
  (if (eq system-type 'windows-nt)
      "C:/Users/kirath/"
      "~/"))
 
(add-to-list 'load-path (concat emacs-root "emacs"))
 
(require 'cl)
 
(global-set-key "\C-x\C-m" 'execute-extended-command)
 
(define-key global-map [f8] 'kill-region)
(global-set-key "\C-w" 'backward-kill-word)
 
(if (fboundp 'scroll-bar-mode) (scroll-bar-mode -1))
(if (fboundp 'tool-bar-mode) (tool-bar-mode -1))
(if (fboundp 'menu-bar-mode) (menu-bar-mode -1))
 
(global-set-key [f5] 'call-last-kbd-macro)
 
; git
 
; http://www.emacswiki.org/cgi-bin/wiki/Git
;; (if (eq system-type 'windows-nt)
;; (progn
;; (require 'magit)
;; (define-key global-map [f6] 'magit-status))
;; (progn
;; (message "i am loading git")
;; (add-to-list 'load-path (expand-file-name "/usr/share/doc/git-core/contrib/emacs"))
;; (require 'vc-git)
;; (when (featurep 'vc-git) (add-to-list 'vc-handled-backends 'git))
;; (require 'git)
;; (autoload 'git-blame-mode "git-blame"
;; "Minor mode for incremental blame for Git." t)))
 
(require 'magit)
(define-key global-map [f6] 'magit-status)
 
; tab
; http://student.northpark.edu/pemente/emacs_tabs.htm
(setq-default tab-width 4)
(setq-default indent-tabs-mode nil)
 
; http://www.emacs.uniyar.ac.ru/doc/em24h/emacs100.htm
(setq show-paren-mode t)
(setq show-paren-style 'parenthesis)
 
; --- to learn from ---
; http://www.emacswiki.org/cgi-bin/wiki/emacs-init.el
; this url seems to be a good resource
(setq inhibit-startup-message t)
 
 
; http://homepages.inf.ed.ac.uk/s0243221/emacs/
; http://tldp.org/HOWTO/Emacs-Beginner-HOWTO-4.html
(defun alt-colors-1 ()
  (progn
     (set-cursor-color "Orchid")
     (set-mouse-color "Orchid")
     (set-background-color "DarkSlateGray")
     (set-foreground-color "Wheat")
     (global-hl-line-mode 1)
))
 
; lines
(setq scroll-step 1)
(line-number-mode 1)
(column-number-mode 1)
 
; backup
(setq make-backup-files t)
(setq version-control t)
(setq backup-directory-alist (quote ((".*" . "~/.emacs_backups/"))))
; ----------------------------------------
 
; paren hilite
; http://www.emacsblog.org/2007/08/07/quick-tip-show-paren-mode/
(show-paren-mode t)
; (setq show-paren-style 'expression)
 
 
; http://infolab.stanford.edu/~manku/dotemacs.html
(transient-mark-mode t) ; highlight marked region
 
; http://www.math.umn.edu/~garrett/shortest/emacs_customization.html
(custom-set-variables
  ;; custom-set-variables was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful.
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work right.
 '(blink-cursor-mode nil))
 
(defun alt-colors-2 ()
  (progn
(set-background-color "DimGray")
(set-foreground-color "LightGray")
(set-cursor-color "DarkSlateBlue")
(set-border-color "DimGray")
(set-mouse-color "DarkSlateBlue")
 
(set-face-background 'default "DimGray")
(set-face-background 'region "DarkSlateGray")
(set-face-background 'highlight "DarkSlateBlue")
(set-face-background 'modeline "DarkSlateBlue") ;;; CornflowerBlue")
 
(set-face-foreground 'default "LightGray")
(set-face-foreground 'region "Ivory")
(set-face-foreground 'highlight "LightGray") ;;; DimGray")
(set-face-foreground 'modeline "LightGray")
))
 
(setq-default delete-old-versions 't)
(alt-colors-1)
(dired emacs-root)
(rename-buffer "dired1")
(eshell)
(find-file (concat emacs-root ".emacs"))
 
 
; ----------------------------------------
; http://www.zafar.se/bkz/Articles/EmacsTips
 
(add-hook 'isearch-mode-end-hook 'custom-goto-match-beginning)
 
(defun custom-goto-match-beginning ()
  "Use with isearch hook to end search at first char of match."
  (when isearch-forward (goto-char isearch-other-end)))
; ----------------------------------------
 
(setq resize-minibuffer-mode t)
 
; ----------------------------------------
; http://www.emacswiki.org/cgi-bin/wiki/EmacsNiftyTricks#toc3
(defadvice save-buffers-kill-emacs (around no-query-kill-emacs activate)
  "Prevent annoying \"Active processes exist\" query when you quit Emacs."
  (flet ((process-list ())) ad-do-it))
 
(fset 'yes-or-no-p 'y-or-n-p)
 
;repl for elisp
(ielm)
 
; ----------------------------------------
 
; http://common-lisp.net/project/slime/doc/html/Installation.html#Installation
; slime
 
; installation:
; apt-get install sbcl sbcl-doc sbcl-source slime
 
; bookmark: [transcript of marco baringer's slime movie]
; http://www.pchristensen.com/blog/articles/reference-for-the-slimelispemacs-screencast/#comment-144
 
(if (eq system-type 'windows-nt)
    (progn
; (message "i am starting slime")
; (setq inferior-lisp-program "C:/sbcl-1.0.19/sbcl.exe --core C:/sbcl-1.0.19/sbcl.core")
; (add-to-list 'load-path "C:/slime")
; (require 'slime)
; (slime-setup)
; (slime-setup '(slime-fancy slime-asdf))
; (slime)
; (setq slime-startup-animation nil)
      )
  (progn
      (message "i am starting slime")
      (setq inferior-lisp-program "/usr/bin/sbcl")
      (add-to-list 'load-path "/usr/share/emacs/site-lisp/slime")
      (require 'slime)
      (slime-setup)
      (slime-setup '(slime-fancy slime-asdf))
      (slime)
      ; http://www.jasondunsmore.com/emacs/dotemacs.txt
      (setq slime-startup-animation nil)))
 
; color theme
; http://www.emacswiki.org/cgi-bin/wiki?ColorTheme
; http://www.cs.cmu.edu/~maverick/GNUEmacsColorThemeTest/
 
;(require 'color-theme)
;(color-theme-initialize)
;(color-theme-robin-hood)
;(color-theme-subtle-hacker)
 
; w3m
; http://www.emacswiki.org/cgi-bin/emacs-en/emacs-w3m
; http://emacs-w3m.namazu.org/
(if (eq system-type 'windows-nt)
    (message "i am skipping w3m")
  (progn
    (message "i am starting w3m")
    (add-to-list 'load-path (concat emacs-root "emacs/emacs-w3m-1.4.4"))
    (setq browse-url-browser-function 'w3m-browse-url)
    (autoload 'w3m-browse-url "w3m" "Ask a WWW browser to show a URL." t)
    (global-set-key "\C-xm" 'browse-url-at-point)))
 
(define-key global-map [f11] " - ")
(define-key global-map [f12] " -- ")
(global-set-key [kp-subtract] "\C-a\C-k\C-d") ; numpad minus = nuke line
 
; auto encryption - begin
; http://www.emacswiki.org/cgi-bin/wiki/AutoEncryption
(defvar pgg-gpg-user-id "kirubakaran")
(autoload 'pgg-make-temp-file "pgg" "PGG")
(autoload 'pgg-gpg-decrypt-region "pgg-gpg" "PGG GnuPG")
(define-generic-mode 'gpg-file-mode
  (list ?#)
  nil nil
  '(".gpg\\'" ".gpg-encrypted\\'")
  (list (lambda ()
(add-hook 'before-save-hook
                      (lambda ()
                        (let ((pgg-output-buffer (current-buffer)))
                          (pgg-gpg-encrypt-region (point-min) (point-max)
                                                  (list pgg-gpg-user-id))))
                      nil t)
(add-hook 'after-save-hook
(lambda ()
                        (let ((pgg-output-buffer (current-buffer)))
                          (pgg-gpg-decrypt-region (point-min) (point-max)))
(set-buffer-modified-p nil)
(auto-save-mode nil))
nil t)
            (let ((pgg-output-buffer (current-buffer)))
              (pgg-gpg-decrypt-region (point-min) (point-max)))
(auto-save-mode nil)
(set-buffer-modified-p nil)))
  "Mode for gpg encrypted files")
; auto encryption - end
 
; ----------------------------------------
; set window title to contain the current buffer name
; this is so that rescue-time can see what buffer I am in
; I don't want everything I do in emacs to be classified as 'dev work'
 
;(defadvice switch-to-buffer (after name-the-frame (arg))
; (set-frame-name (concat (buffer-name) " - emacs")))
;
;(ad-activate 'switch-to-buffer)
 
; a method that wasn't sufficient:
;(global-set-key [f10]
; '(lambda ()
; (interactive)
; (set-frame-name (concat "emacs : " (buffer-name)))))
 
; a method that didn't work:
;(global-set-key "\C-xb"
; '(lambda (buffer &optional norecord)
; (interactive)
; (set-frame-name (concat "emacs : " (buffer-name)))
; (switch-to-buffer buffer norecord)))
 
; references:
; http://www.gnu.org/software/emacs/elisp/html_node/Advising-Functions.html#Advising-Functions
; http://groups.google.com/group/gnu.emacs.help/browse_thread/thread/9e50dd3a196c86c8
 
; ----------------------------------------
 
(split-window-horizontally)
 
; cygwin
; http://www.khngai.com/emacs/cygwin.php
(if (eq system-type 'windows-nt)
   (progn
     (setenv "PATH" (concat (getenv "PATH") ";C:\\users\\kirath\\cygwin\\bin"))
     (setq exec-path (cons "c:/users/kirath/cygwin/bin/" exec-path))
     (require 'cygwin-mount)
     (cygwin-mount-activate)
     
     ; Replace DOS shell with Cygwin Bash Shell
     (add-hook 'comint-output-filter-functions
               'shell-strip-ctrl-m nil t)
     (add-hook 'comint-output-filter-functions
               'comint-watch-for-password-prompt nil t)
     (setq explicit-shell-file-name "bash.exe")
     ;; For subprocesses invoked via the shell
     ;; (e.g., "shell -c command")
     (setq shell-file-name explicit-shell-file-name)))
 
; ------------------------------------------------------------
; python mode
; http://www.emacswiki.org/cgi-bin/wiki/PythonMode
;; (add-hook 'python-mode-hook
;; (lambda ()
;; (define-key python-mode-map "\"" 'electric-pair)
;; (define-key python-mode-map "\'" 'electric-pair)
;; (define-key python-mode-map "(" 'electric-pair)
;; (define-key python-mode-map "[" 'electric-pair)
;; (define-key python-mode-map "{" 'electric-pair)))
 
;; (defun electric-pair ()
;; "Insert character pair without sournding spaces"
;; (interactive)
;; (let (parens-require-spaces)
;; (insert-pair)))
; ------------------------------------------------------------
 
; ------------------------------------------------------------
; open my files
 
;; (message "i am loading files from thumb drive")
 
;; (defun thumbdrive ()
;; (if (eq system-type 'windows-nt)
;; '"f:/"
;; '"/media/HANZO\ SWORD/"))
 
;; (defun open-file-if-exists (file1)
;; (when (file-readable-p file1)
;; (find-file file1)))
 
;; (defun oife (file1)
;; (open-file-if-exists (concat (thumbdrive) "Performance/" file1)))
 
;; (mapc 'oife
;; (list
;; "done.txt"
;; "goals.txt"
;; "ideas.txt"
;; "startup-log.txt"
;; "try-new-habits.org"
;; "todo.txt"))
 
; ------------------------------------------------------------
 
(defun my-date ()
  (interactive)
  (insert
   (concat "[" (format-time-string "%b %d, %Y %H:%M") "]")))
 
(define-key global-map [f3] 'my-date)
 
; ------------------------------------------------------------
 
; ---
; copy line without selection
; http://www.emacswiki.org/cgi-bin/wiki/CopyWithoutSelection
(defun copy-line (&optional arg)
  "Save current line into Kill-Ring without mark the line "
  (interactive "P")
  (let ((beg (line-beginning-position))
      (end (line-end-position arg)))
    (copy-region-as-kill beg end)))
 
(global-set-key (kbd "C-c l") 'copy-line)
; ---
 
(defun totd ()
  (interactive)
  (random t) ;; seed with time-of-day
  (with-output-to-temp-buffer "*Tip of the day*"
    (let* ((commands (loop for s being the symbols
                           when (commandp s) collect s))
           (command (nth (random (length commands)) commands)))
      (princ
       (concat "Your tip for the day is:\n"
               "========================\n\n"
               (describe-function command)
               "\n\nInvoke with:\n\n"
               (with-temp-buffer
                 (where-is command t)
                 (buffer-string)))))))
 
(totd)
 
; ------------------------------------------------------------
; http://mail.python.org/pipermail/python-list/2007-October/464038.html
(defun my-file-processing-fn (fpath)
  "\nelisp file processing function. \nKill word that occurs after kite and hoo. \n~Kirubakaran\n"
  (interactive)
  (let (mybuffer)
    (setq mybuffer (find-file fpath))
    (search-forward "kite")
    (search-forward "hoo")
    (kill-word (point))
    (save-buffer)
    (kill-buffer mybuffer)))
; ------------------------------------------------------------
 
; ------------------------------------------------------------
; http://www3.ntu.edu.sg/home5/pg04878518/EmacsTools.html
 
(require 'ido)
(ido-mode t)
(setq ido-enable-flex-matching t)
(setq ido-create-new-buffer 'always)
 
;(require 'browse-kill-ring)
;(global-set-key [(control c)(k)] 'browse-kill-ring)
;(browse-kill-ring-default-keybindings)
 
(defun match-paren (arg)
  "Go to the matching paren if on a paren; otherwise insert %."
  (interactive "p")
  (cond ((looking-at "\\s\(") (forward-list 1) (backward-char 1))
        ((looking-at "\\s\)") (forward-char 1) (backward-list 1))
        (t (self-insert-command (or arg 1)))))
 
(global-set-key "%" 'match-paren)
 
(require 'generic)
(require 'generic-x)
 
(if (not (eq system-type 'windows-nt))
    (setq x-select-enable-clipboard 't))
 
(autoload 'gtypist-mode "gtypist-mode")
(setq auto-mode-alist
      (cons '("\\.typ\\'" . gtypist-mode) auto-mode-alist))
 
; ------------------------------------------------------------
 
(autoload 'js2-mode "js2" nil t)
(add-to-list 'auto-mode-alist '("\\.js$" . js2-mode))
  
(if (eq system-type 'windows-nt)
    (custom-set-faces
     ;; custom-set-faces was added by Custom.
     ;; If you edit it by hand, you could mess it up, so be careful.
     ;; Your init file should contain only one such instance.
     ;; If there is more than one, they won't work right.
     '(default ((t
                 (:stipple nil
                  :background "DarkSlateGray"
                  :foreground "Wheat"
                  :inverse-video nil
                  :box nil
                  :strike-through nil
                  :overline nil
                  :underline nil
                  :slant normal
                  :weight normal
                  :height 140
                  :width normal
                  :family "outline-consolas"))))))
 
(setq py-python-command-args '("-colors" "Linux"))
(setq ipython-command "/usr/bin/ipython")
(require 'ipython)
 
;experimental
;(add-to-list 'load-path (concat emacs-root "emacs/g-client"))
;(load-library "g")
 
 
; makes line into
; +------+
; | line |
; +------+
 
(global-set-key [f7] 'k_box)
 
(defun k_box ()
  (interactive)
  (setq cur_line (thing-at-point 'line))
  ;delete trailing newline
  (if (string=
       (substring cur_line -1)
       "\n")
      (progn
        (setq cur_line
              (substring cur_line 0 (- (length cur_line) 1)))))
  (setq ins_line (concat "| " cur_line " |\n"))
  (setq border_line
        (concat "+"
                (make-string (- (length ins_line) 3) ?-)
                "+"))
  (beginning-of-line)
  (kill-line)
  (insert
   border_line
   "\n"
   ins_line
   border_line
   "\n"))
 
 
;escreen
 
(load "escreen")
(escreen-install)
(global-set-key (kbd "<s-prior>") 'escreen-goto-prev-screen)
(global-set-key (kbd "<s-next>") 'escreen-goto-next-screen)
 
(delete-selection-mode t)
 
 
(message "***** .emacs loaded *****")