Source

js-elisp / js-micro-features.el

Full commit
  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
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885

;;----------------------------------------------------------------------------;;
;; Micro-features.  Loading this file should only affect the namespace.       ;;                                                                    ;;
;;----------------------------------------------------------------------------;;

(require 'dired)
(require 'dired-x)
(require 'haskell-mode)
(require 'haskell-indent)
(require 'iswitchb)
(require 'filladapt)
(require 'markdown-mode)
(require 'recentf)
(require 'server)
(require 'term)
(require 'whitespace)
(require 'js-lib)

;; Each definition has a commented-out line before it with (Jane.foo) on it.
;; To try out the feature without adding to your .emacs, put the cursor on
;; the right parenthesis and type C-xC-e (or whatever eval-last-sexp is bound to.

;;----------------------------------------------------------------------------;;

;; (Jane.advanced)
(defun Jane.advanced ()
  "Enable advanced commands, e.g. narrowing."
  (setq-default disabled-command-function nil)
  (put 'narrow-to-region 'disabled nil)
  (custom-set-variables
   '(enable-recursive-minibuffers t)))

;;----------------------------------------------------------------------------;;

;; (Jane.auto-modes)
(defun Jane.auto-modes ()
  (defvar auto-mode-ext
    (list
     '("\\.agda$" . agda2-mode)
     '("\\.ampl$" . ampl-mode)
     '("\\.cfg$" . twelf-mode)
     '("\\.cm$" . sml-cm-mode)
     '("\\.cs$" . csharp-mode)
     '("\\.dkal$" . dkal-mode)
     '("\\.dot$" . dot-mode)
     '("\\.elf$" . twelf-mode)
     '("\\.fun$" . sml-mode)
     '("\\.gl$" . prolog-mode)
     '("\\.grm$" . sml-yacc-mode)
     '("\\.h$" . c++-mode)
     '("\\.hl$" . hol-light-mode)
     '("\\.hs$" . haskell-mode)
     '("\\.htm$" . nxhtml-mode)
     '("\\.html$" . nxhtml-mode)
     '("\\.imo$" . text-mode)
     '("\\.jpg$" . image-mode)
     '("\\.jobs$" . scheme-mode)
     '("\\.js$" . js2-mode)
     '("\\.lex$" . sml-lex-mode)
     '("\\.lhs$" . literate-haskell-mode)
     ;;'("\\.m$" . matlab-mode)
     '("\\.m$" . octave-mode)
     '("\\.mkd$" . markdown-mode)
     '("\\.mlast$" . tuareg-mode)
     '("\\.ml[iylp4]?$" . tuareg-mode)
     '("\\.ml.part$" . tuareg-mode)
     '("\\.ML$" . sml-mode)
     '("\\.mlb$" . esml-mlb-mode)
     '("\\.mod$" . ampl-mode)
     '("\\.new$" . tuareg-mode)
     '("\\.ol$" . outline-mode)
     '("\\.old$" . tuareg-mode)
     '("\\.om$" . makefile-mode)
     '("\\.omdoc$" . xml-mode)
     '("\\.org$" . org-mode)
     '("\\.p$" . prolog-mode)
     '("\\.patdiff" . lisp-mode)
     '("\\.pl$" . prolog-mode)
     '("\\.plt$" . gnuplot-mode)
     '("\\.pp$" . tuareg-mode)
     '("\\.quy$" . twelf-mode)
     '("\\.s$" . asm-mode)
     '("\\.scm$" . scheme-mode)
     '("\\.scpt$" . ascript-mode)
     '("\\.sexp$" . lisp-mode)
     '("\\.shtml$" . nxml-mode)
     '("\\.sig$" . sml-mode)
     '("\\.sml$" . sml-mode)
     '("\\.st$" . nxhtml-mode)
     '("\\.svg$" . nxml-mode)
     '("\\.tex$" . LaTeX-mode)
     '("\\.v$" . coq-mode)
     '("\\.x$" . haskell-mode)
     '("\\.xhtml$" . nxhtml-mode)
     '("\\.xml$" . nxml-mode)
     '("\\.y$" . haskell-mode)
     ;; Config files
     '("\\.hgrc$" . shell-script-mode)
     '("_config_file.*\\.txt\\'" . lisp-mode)
     '("spec\\.txt\\'" . lisp-mode)
     '("core\\.cfg\\." . lisp-mode)
     ;; Omake
     '("OMakefile$" . makefile-mode)
     '("OMakeroot$" . makefile-mode)
     ;; Mutt
     '("/mutt-[^/]*\\'" . mail-mode)
     ))
  (setq auto-mode-alist (append auto-mode-ext auto-mode-alist)))

;;----------------------------------------------------------------------------;;

;; (Jane.auto-revert)
(defun Jane.auto-revert ()
  "update unmodified buffer when file changes on disk"
  (global-auto-revert-mode 1)
  (custom-set-variables '(revert-without-query '("")))
  ;; fixes font-lock colors after auto-revert -- bug in emacs?
  (add-hook 'after-revert-hook 'normal-mode))

;;----------------------------------------------------------------------------;;

;; (Jane.backups)
(defun Jane.backups ()
  "The following would put backups and auto-saves in /tmp/ which is
almost as fast as not doing it at all, but might be a security
issue."
  (custom-set-variables
   '(version-control t)                   ; Enable versioning
   '(delete-old-versions t)               ; don't ask when deleting old backups
   '(backup-directory-alist `((".*" . ,temporary-file-directory)))
   '(auto-save-file-name-transforms `((".*" ,temporary-file-directory t)))))

;;----------------------------------------------------------------------------;;

;; (Jane.bell)
(defun Jane.bell ()
  "blink the screen on real errors, for more normal stuff just say 'Quit' in the minibuffer"
  (setq ring-bell-function
        (lambda ()
          (unless (memq this-command
                        '(isearch-abort abort-recursive-edit exit-minibuffer keyboard-quit))
                                        ;tell me which command failed
            (if this-command (message (symbol-name this-command)))
            (ding)))))

;;----------------------------------------------------------------------------;;

;; (Jane.hg-blame-summary)
(defun Jane.hg-blame-summary ()
  "while editing an hg controlled file, find the last user to have modified
the current line, as well as printing some other statistics calculated from
'hg blame'"

  (defun my-hg-blame-summary ()
    (interactive)
    (catch 'nil-file-name
      (let (users
            (file-name (buffer-file-name))
            (buffer-line-number (line-number-at-pos))
            (summary (make-hash-table :test 'equal))
            (res-line-number 1)
            buffer-line-user)
        (if (not file-name)
            (throw 'nil-file-name
                   (message "ERROR: buffer has 'nil file name")))
        (dolist (line
                 (split-string
                  (shell-command-to-string (concat "hg blame -u -d '" file-name "'"))
                  "[\r\n]+" t))
          (let ((words (split-string line))
                user count-so-far)
            (setq user (elt words 0))
            (setq count-so-far (gethash user summary :not-found))
            (if (equal count-so-far :not-found)
                (puthash user 1 summary)
              (puthash user (+ 1 (gethash user summary)) summary))
            (if (equal res-line-number buffer-line-number)
                (setq buffer-line-user user))
            (setq res-line-number (+ res-line-number 1))))
        (maphash
         (lambda (user count)
           (setq users
                 (cons (concat user ":" (number-to-string count)) users)))
         summary)
        (message
         (concat "(" buffer-line-user "; "
                 "line " (number-to-string buffer-line-number)
                 "/" (number-to-string res-line-number) ") "
                 (mapconcat (function identity) (sort users 'string<) " "))))))
  (global-unset-key "\C-xvb")
  (global-set-key "\C-xvb" 'my-hg-blame-summary))

;;----------------------------------------------------------------------------;;

;; (Jane.buffer-menu)
(defun Jane.buffer-menu ()
  "Utilities to manage the buffer menu"
  ;; Delete read-only buffers from the menu
  (defun delete-read-only-buffers ()
    (interactive)
    (defun d-buffer ()
      (interactive)
      (if (search-forward "%" nil t)
          (progn (beginning-of-line)
                 (Buffer-menu-delete)
                 t)))
    (save-excursion
      (goto-char (point-min))
      (while (d-buffer))
      (Buffer-menu-execute)))
  (add-hook 'Buffer-menu-mode-hook
            (lambda ()
              (local-set-key "\C-c\C-d" 'delete-read-only-buffers))))

;;----------------------------------------------------------------------------;;

;; (Jane.comint)
(defun Jane.comint ()
  (ansi-color-for-comint-mode-on)
  (custom-set-variables
   '(comint-password-prompt-regexp "password\\|passphrase\\|Encryption")
   '(comint-buffer-maximum-size 10000)
   '(comint-move-point-for-output t)
   '(ansi-color-for-comint-mode t))
  (setq comint-output-filter-functions
        '(ansi-color-process-output
          comint-strip-ctrl-m
          comint-watch-for-password-prompt
          ;;comint-truncate-buffer
          comint-postoutput-scroll-to-bottom)))

;;----------------------------------------------------------------------------;;

;; (Jane.compilation)
(defun Jane.compilation ()
  (defcustom js-ask-before-killing-compilations t
    "If you have compilation buffers, ask about killing them before killing emacs."
    :group 'js)

  (add-hook 'compilation-mode-hook
            (lambda ()
              (setq buffer-file-coding-system 'utf-8)))
  ;; stop emacs from asking you if you really want to quit when you
  ;; have a compilation running in the background (e.g. omake -P)
  (add-hook 'compilation-start-hook
            (lambda (process)
              (set-process-query-on-exit-flag process nil)))
  (defun js-kill-emacs-compilations-p ()
    (let ((has-compilations
           (List.find
            (lambda (b)
              (string-match "*compilation" (buffer-name b))) (buffer-list))))
      (if (and js-ask-before-killing-compilations has-compilations)
          (y-or-n-p
           "You have compilations running.  Do you really want to kill them? ")
        t)))
  ;; (setq kill-emacs-query-functions nil)
  (add-to-list 'kill-emacs-query-functions 'js-kill-emacs-compilations-p)
  (custom-set-variables
   '(compilation-ask-about-save nil)
   '(compilation-read-command nil)
   '(compilation-scroll-output t)
   '(compilation-scroll-output t)
   '(compilation-window-height 18)
   '(next-error-highlight t)
   ;; recenter buffer with error
   '(next-error-recenter (quote (4)))
   ;; ocamlc numbers columns from 0, not from 1 (like, e.g., gcc)
   '(compilation-first-column 0)))

;;----------------------------------------------------------------------------;;

;; (Jane.completion)
(defun Jane.completion ()
  "Make completion ignore case"
  (setq completion-ignore-case t)
  (custom-set-variables
   '(case-fold-search t)
   '(read-buffer-completion-ignore-case t)
   '(read-file-name-completion-ignore-case t)))

;;----------------------------------------------------------------------------;;

;; (Jane.debug)
(defun Jane.debug ()
  "Debugging utilities"
  (custom-set-variables
   '(debug-on-error t)
   '(stack-trace-on-error t)
   '(eval-expression-debug-on-error t)))

;;----------------------------------------------------------------------------;;

;; (Jane.desktop)
(defun Jane.desktop (&optional dont-ask)
  "save a list of open files in ~/.emacs.desktop and re-open
when I restart emacs."
  (require 'desktop)
  (let ((desktop-save (if dont-ask t 'ask)))
  ;; save the desktop file automatically if it already exists
  (custom-set-variables
   '(desktop-file-name-format 'tilde)
   '(desktop-restore-eager 5)
   '(desktop-save dont-ask)
   '(desktop-globals-to-save
     '((extended-command-history . 30)
       (file-name-history        . 100)
       (grep-history             . 30)
       (compile-history          . 30)
       (minibuffer-history       . 50)
       (query-replace-history    . 60)
       (read-expression-history  . 60)
       (regexp-history           . 60)
       (regexp-search-ring       . 20)
       (search-ring              . 20)
       (shell-command-history    . 50)
       tags-file-name
       register-alist
       kill-ring)))
  (desktop-save-mode 1)
  (add-hook 'midnight-hook 'desktop-save-in-desktop-dir)))

;;----------------------------------------------------------------------------;;

;; (Jane.dictionary)
(defun Jane.dictionary ()
  (require 'dictionary)
  (global-set-key "\C-c1" 'dictionary-lookup-definition)
  (global-set-key "\C-c2" 'dictionary-search))

;;----------------------------------------------------------------------------;;

;; (Jane.dired)
(defun Jane.dired ()
  (require 'dired)
  (require 'dired-x)
  (add-hook 'dired-mode-hook
         (function (lambda ()
                     (dired-omit-mode 1)
                     )))
  (setq dired-deletion-confirmer 'y-or-n-p)
  (setq dired-guess-shell-alist-default nil)
  ;; Don't show junk in dired
  (setq dired-omit-extensions
        '(
          "#" ".DS_Store" ".a" ".annot" ".aux" ".bbl" ".bbl" ".blg"
          ".blg" ".brf" ".byte" ".class" ".cma" ".cmi" ".cmo" ".cmx"
          ".cmxa" ".deps" ".dvi" ".elc" ".glo" ".glob" ".gls" ".hc"
          ".hi" ".hp" ".hva" ".idx" ".ilg" ".ind" ".ist" ".libdeps"
          ".lo" ".loa" ".loe" ".lof" ".lot" ".ml.d" ".mli.d" ".native"
          ".nav" ".o" ".objdeps" ".omc" ".pdfsync" ".rel" ".snm" ".so"
          ".spit" ".spot" ".synctex.gz" ".toc" ".v.d" ".vo" ".vrb" "~"
          "hgignore.in" ".build_info.c" ".hg_version.c"
          ))
  (custom-set-variables
   '(dired-enable-local-variables nil)
   '(dired-recursive-copies 'always)
   '(dired-recursive-deletes 'top)
   '(dired-omit-size-limit nil)
   '(dired-guess-shell-alist-user
     (list
      (list "\\.tar.bz2\\'" "tar -xjf" "bunzip2")
      (list "\\.tar.gz\\'" "tar -xzf" "gunzip")
      (list "\\.bz2\\'" "bunzip2")
      (list "\\.bzip\\'" "bunzip2")
      (list "\\.dvi\\'" "dvi2pdf")
      (list "\\.gz\\'" "gunzip")
      (list "\\.pdf\\'" "acroread")
      (list "\\.ps\\'" "ps2pdf")
      (list "\\.tar\\'" "tar -xf")
      (list "\\.tbz\\'" "tar -xjf")
      (list "\\.tgz\\'" "tar -xzf" "gunzip")
      (list "\\.Z\\'" "unzip")
      (list "\\.zip\\'" "unzip")
      )
     )
   ;; Make autocomplete ignore these files also
   '(completion-ignored-extensions dired-omit-extensions)
   '(dired-omit-files "^\\..*$"))
  (define-key dired-mode-map "\C-c\C-c" 'js-compile))

;;----------------------------------------------------------------------------;;

;; (Jane.ediff)
(defun Jane.ediff ()
  (defun ediff-buffer-with-file ()
    (interactive)
    (message "Use ediff-current-file instead of ediff-buffer-with-file."))
  (custom-set-variables
   '(ediff-split-window-function (quote split-window-horizontally))))

;;----------------------------------------------------------------------------;;

;; (Jane.faces-basic)
(defun Jane.faces-basic ()
  "Angry fruit salad faces"
  (custom-set-faces
   '(mode-line
     ((t (:background "orange" :foreground "black"
                      :box (:line-width -1 :style released-button)))))
   '(cursor ((t (:background "red"))))
   '(highlight ((t (:background "blue4"))))
   '(region ((t (:background "blue4"))))
   '(show-paren-match ((t (:background "gray25" :weight bold))))))

;;----------------------------------------------------------------------------;;

;; (Jane.faces-dark)
(defun Jane.faces-dark ()
  "faces for a black background most people like"
  (custom-set-faces
   '(font-lock-comment-face ((((class color) (background dark)) (:foreground "green3"))))
   ;; In tuareg-mode, docs (** ... *) are more similar to comments
   ;; (* ... *) than strings "..."
   '(font-lock-doc-face ((t (:inherit font-lock-comment-face))))
   '(font-lock-function-name-face
     ((((class color) (background dark)) (:foreground "LightSkyBlue" :weight semi-bold))))
   '(help-argument-name ((t (:background "gray25"))))
   '(mouse ((t (:background "purple"))))
   '(tuareg-font-lock-governing-face
     ((t (:inherit font-lock-keywords-face :foreground "orange" :weight bold))))
   '(tuareg-font-lock-operator-face
     ((t (:inherit font-lock-keywords-face :foreground "lightblue"))))
   '(whitespace-trailing ((t (:background "pink" :weight bold))))))

;;----------------------------------------------------------------------------;;

;; (Jane.faces-default)
(defun Jane.faces-default ()
  "The faces that come standard in Emacs"
  (custom-set-faces
   '(font-lock-builitin-face ((t (:foreground "MediumOrchid4"))))
   '(font-lock-comment-face ((t (:foreground "Firebrick"))))
   '(font-lock-constant-face ((t (:foreground "Dark cyan"))))
   '(font-lock-doc-face ((t (:inherit font-lock-doc-face))))
   '(font-lock-function-name-face ((t (:foreground "Blue1"))))
   '(font-lock-keyword-face ((t (:foreground "Purple"))))
   '(font-lock-string-face ((t (:foreground "VioletRed4"))))
   '(font-lock-type-face ((t (:foreground "ForestGreen"))))
   '(font-lock-variable-name-face ((t (:foreground "sienna"))))
   '(font-lock-warning-face ((t (:foreground "Red1"))))
   '(tuareg-font-lock-governing-face ((t (:foreground "blue"))))
   '(tuareg-font-lock-operator-face ((t (:foreground "brown"))))
   '(whitespace-trailing ((t (:background "pink" :weight bold))))
   ))

;;----------------------------------------------------------------------------;;

;; (Jane.faces-light)
(defun Jane.faces-light ()
  "faces for a light background most people like"
  (custom-set-variables
   '(js-background "white")
   '(js-foreground "black"))
  (Jane.faces-default)
  )

;;----------------------------------------------------------------------------;;

;; (Jane.faces-subtle)
(defun Jane.faces-subtle ()
  (custom-set-faces
   '(cursor ((t (:background "HotPink1"))))
   '(highlight ((t (:background "blue4"))))
   '(region ((t (:background "gray20"))))
   '(show-paren-match ((t (:background "gray25" :bold t))))))

;;----------------------------------------------------------------------------;;

;; (Jane.filladapt)
(defun Jane.filladapt ()
  "fills paragraphs nicely in text mode, understands bulleted lists (try M-q)"
  (require 'filladapt))

;;----------------------------------------------------------------------------;;

;; (Jane.flyspell)
(defun Jane.flyspell ()
  "incremental spell checking"
  (defun flyspell-dwim ()
    "For programming modes, just check comments and strings.
For text modes, check everything"
    (interactive)
    (if (and (not (boundp 'flyspell-mode-predicate)) comment-start)
        (flyspell-prog-mode)
      (if (derived-mode-p 'text-mode) (turn-on-flyspell))))
  (add-hook 'font-lock-mode-hook 'flyspell-dwim)
  (custom-set-variables
   '(flyspell-mark-duplications-flag nil)
   '(flyspell-persistent-highlight nil)
   '(ispell-dictionary "american"))
  (custom-set-faces
   '(flyspell-duplicate ((t (:underline t))))
   '(flyspell-incorrect ((t (:underline t))))))

;;----------------------------------------------------------------------------;;

;; (Jane.frame)
(defun Jane.frame ()
  "Frame utils."
  ;; Give frames and icons good names
  (setq-default frame-title-format (list "Emacs: %f"))
  (setq-default icon-title-format "Emacs - %b")
  (setq frame-inherited-parameters '(font background-color foreground-color))
  ;; easier to remember than C-x 5 2
  (global-set-key "\C-x\C-n" 'make-frame)
  (custom-set-variables
   ;; prefer side-by-side buffers
   '(split-height-threshold nil)))

;;----------------------------------------------------------------------------;;

;; (Jane.global-keybindings)
(defun Jane.global-keybindings ()
  ;; Non C-c bindings
  (global-set-key "\C-xk" 'kill-this-buffer) ; don't ask me which buffer to kill
  (global-set-key "\C-xw" 'rename-buffer-file)
  (global-set-key [(control =)] 'bounce-sexp)
  (global-set-key "\M-\ " 'fixup-whitespace)

  ;; By default, buffers should auto-indent when I hit return
  (define-key global-map [remap newline] 'newline-and-indent)
  (global-set-key [(control .)] 'repeat)  ; overrides tags-apropos
  (global-set-key [(control =)] 'bounce-sexp)

  ;; C-c bindings
  (global-set-key "\C-ca" 'align-dwim)
  (global-set-key "\C-cb" 'comment-box)
  (global-set-key "\C-cc" 'comment-dwim)  ; comment (do what i mean) -- default M-j
  (global-set-key "\C-cg" 'goto-line)
  (global-set-key "\C-ck" 'comment-kill)
  (global-set-key "\C-cr" 'cr-dwim)       ; defined in cr.el
)

;;----------------------------------------------------------------------------;;

;; (Jane.grep)
(defun Jane.grep ()
  ;; For recursive grep: M-x rgrep RET foo RET ml RET dir RET
  ;; search for "foo" in ML files under dir
  (require 'grep)
  (add-to-list 'grep-files-aliases '("omake" . "*.om OMake*"))
  (add-to-list 'grep-files-aliases '("ml" . "*.ml *.mli")))

;;----------------------------------------------------------------------------;;

;; (Jane.haskell)
(defun Jane.haskell ()
  (load-library "haskell-site-file.el")
  (require 'haskell-mode)
  (require 'haskell-indent)
  (add-hook 'haskell-mode-hook
            (lambda()
              (abbrev-mode 1)
              (haskell-indent-mode 1))))

;;----------------------------------------------------------------------------;;

;; (Jane.ido)
(defun Jane.ido ()
  "Like iswitchb but for buffers and files, also more actively developed."
  (require 'ido)
  (ido-mode 1)
  (custom-set-variables
   ;; C-xb will re-open files I've opened in the past by looking at recentf
   '(ido-use-virtual-buffers t)
   '(ido-show-dot-for-dired t)
   '(ido-use-filename-at-point 'guess)
   '(ido-rotate-file-list-default t)
   '(ido-everywhere t)))

;;----------------------------------------------------------------------------;;

;; (Jane.iswitchb)
(defun Jane.iswitchb ()
  "Buffer management -- C-xb shows matching buffers interactively"
  (require 'iswitchb)
  (iswitchb-mode 1)
  (custom-set-variables
   '(read-buffer-function 'iswitchb-read-buffer)
   '(iswitchb-buffer-ignore '("^ " "*Completions"))
   ;; if buffer is in some other frame, just open another one in this window anyway
   '(iswitchb-default-method 'samewindow))
  ;; Make direction keys work in iswitchb buffer
  (add-hook 'iswitchb-define-mode-map-hook
            (lambda ()
              (mapc (lambda (K)
                      (let* ((key (car K)) (fun (cdr K)))
                        (define-key iswitchb-mode-map (read-kbd-macro key) fun)))
                    '(("<right>" . iswitchb-next-match)
                      ("<left>"  . iswitchb-prev-match)
                      ("<up>"    . ignore)
                      ("<down>"  . ignore))))))

;;----------------------------------------------------------------------------;;

;; (Jane.linum)
(defun Jane.linum ()
  "show line numbers in the left margin"
  (require 'linum))

;;----------------------------------------------------------------------------;;

;; (Jane.midnight)
(defun Jane.midnight ()
  "kills unmodified buffers that haven't been displayed in 3 days or more"
  (require 'midnight)
  (custom-set-variables
   '(midnight-mode t)))

;;----------------------------------------------------------------------------;;

;; (Jane.multiframe)
(defun Jane.multiframe ()
  (defun my-multiframe-window (&optional arg)
    (interactive "P")
    (if arg
        (previous-multiframe-window)
      (next-multiframe-window)))
  ;; switch between buffers in all frames by default
  ;; like raise-on-hover for emacs
  (custom-set-variables '(mouse-autoselect-window 0))
  (global-set-key "\C-xo" 'my-multiframe-window)
  ;; usually bound to open-line
  (global-set-key "\C-o" 'my-multiframe-window)
  (require 'dired)
  (define-key dired-mode-map "\C-o" 'my-multiframe-window)
  (require 'term)
  (define-key term-raw-map "\C-o" 'my-multiframe-window)
  (define-key term-raw-map "\M-x" 'execute-extended-command))

;;----------------------------------------------------------------------------;;

;; (Jane.no-clutter)
(defun Jane.no-clutter ()
  "Turn off menu bars, tool bars, scroll bars, auto-save files, etc"
  ;; Solid cursor
  (blink-cursor-mode   -1)
  ;; Show column numbers in the mode line
  (column-number-mode   1)
  ;; No menu bar
  (menu-bar-mode       -1)
  ;; No scroll bar
  (scroll-bar-mode     -1)
  ;; No tool bar
  (tool-bar-mode       -1)
  ;; No backups or auto saves or version control -- they make things slower
  (custom-set-variables
   '(make-backup-files nil)
   '(auto-save-default nil)
   ;; text-only questions, please
   '(use-dialog-box nil)
   '(tooltip-mode nil)
   '(history-delete-duplicates t)
   ))

;;----------------------------------------------------------------------------;;

;; (Jane.perl)
(defun Jane.perl ()
  (defalias 'perl-mode 'cperl-mode)
  (setq-default cperl-hairy t)
  (setq-default cperl-under-as-char t))

;;----------------------------------------------------------------------------;;

;; (Jane.recentf)
(defun Jane.recentf ()
  "Remember recently opened files."
  (require 'recentf)
  (defvar my-local-directory (concat "/mnt/local/LogVol01/" (user-login-name)))
  (defun my-recentf-keep (file)
    ;; symlinks for nyc-qws-r07, shouldn't delete from recent list when on nyc-qws-024
    (if (and (string-match my-local-directory (file-truename file))
             (not (file-readable-p my-local-directory)))
        t
      (recentf-keep-default-predicate file)))
  (custom-set-variables
   '(recentf-max-saved-items 10000)
   '(recentf-keep '(my-recentf-keep))
   '(recentf-auto-cleanup 'never))
  (recentf-mode 1)
  (add-hook 'midnight-hook 'recentf-save-list))

;;----------------------------------------------------------------------------;;

;; (Jane.rectangle)
(defun Jane.rectangle ()
  "Customizations of rectangular selections"
  (define-key ctl-x-map [?r ?\C-\ ] 'rm-set-mark)
  (define-key ctl-x-map "r\C-x" 'rm-exchange-point-and-mark)
  (define-key ctl-x-map "r\C-w" 'rm-kill-region)
  (define-key ctl-x-map "r\M-w" 'rm-kill-ring-save)
  (autoload 'rm-set-mark "rect-mark"
    "Set mark for rectangle." t)
  (autoload 'rm-exchange-point-and-mark "rect-mark"
    "Exchange point and mark for rectangle." t)
  (autoload 'rm-kill-region "rect-mark"
    "Kill a rectangular region and save it in the kill ring." t)
  (autoload 'rm-kill-ring-save "rect-mark"
    "Copy a rectangular region to the kill ring." t))

;;----------------------------------------------------------------------------;;

;; (Jane.saveplace)
(defun Jane.saveplace ()
  "when re-opening a file, the point goes to its last location"
  (require 'saveplace)
  (custom-set-variables '(save-place t)))

;;----------------------------------------------------------------------------;;

;; (Jane.scrolling)
(defun Jane.scrolling ()
  "Scroll smoothly (one line at a time) -- better than scroll-margin"
  (require 'smooth-scrolling)
  (custom-set-variables
   '(smooth-scroll-margin 5)
   '(isearch-allow-scroll t)))

;;----------------------------------------------------------------------------;;

;; (Jane.server)
(defun Jane.server ()
  "Server stuff"
  (require 'server)
  ;; If there's another server running, (server-start) will
  ;; fail.  Don't die if this happens.
  (unless (server-running-p) (server-start))
  (defun server-restart ()
    "Force a restart of the emacs server"
    (interactive)
    (progn
      (server-force-delete)
      (server-start)))
  ;; Close open server connections when you kill a buffer
  (add-hook 'kill-buffer-hook
            (lambda ()
              (server-buffer-done (current-buffer) t)))
  ;; This way, "crvet.exe review interactive -emacs" won't cause the
  ;; focus to shift to emacs.
  (custom-set-variables '(server-raise-frame nil)))

;;----------------------------------------------------------------------------;;

;; (Jane.sml)
(defun Jane.sml ()
  (require 'sml-mode)
  (add-hook 'sml-mode-hook
            (lambda()
              (abbrev-mode 1)
              (setq comment-start "(*")
              (setq comment-end "*)*")
              )))

;;----------------------------------------------------------------------------;;

;; (Jane.text)
(defun Jane.text ()
  (require 'filladapt)
  (add-hook 'text-mode-hook
            (lambda ()
              (turn-on-filladapt-mode)
              (turn-on-auto-fill))))

;;----------------------------------------------------------------------------;;

;; (Jane.time)
(defun Jane.time ()
  "show the time and date in the mode line"
  (display-time)
  (custom-set-variables
   '(display-time-day-and-date t)))

;;----------------------------------------------------------------------------;;

;; (Jane.uniquify)
(defun Jane.uniquify ()
  "When two files are open with the same name, emacs defaults to
FILE FILE<1> FILE<2>.  Uniquify gives more context."
  (require 'uniquify)
  (custom-set-variables
   ;; e.g. buffer name multi/OMakefile instead of OMakefile<2>
   '(uniquify-buffer-name-style 'forward)))

;;----------------------------------------------------------------------------;;

;; (Jane.vc)
(defun Jane.vc ()
  "Diffing, merging and resolving conflicts"
  (require 'smerge-mode)
  (let ((map (make-sparse-keymap))
        (keep-map (make-sparse-keymap)))
    (define-key map "o" 'smerge-diff-base-other)
    (define-key map "m" 'smerge-diff-base-mine)
    (define-key map "c" 'smerge-diff-mine-other)
    (define-key map "n" 'smerge-next)
    (define-key map "p" 'smerge-prev)
    (define-key map "r" 'smerge-resolve)
    (define-key map "R" 'smerge-resolve-all)
    (define-key map "k" keep-map)
    (define-key keep-map "o" 'smerge-keep-other)
    (define-key keep-map "m" 'smerge-keep-mine)
    (define-key global-map "\C-cd" map))
  (custom-set-variables
   '(ediff-combination-pattern
     '("<<<<<<< MINE" A
       "||||||| ANCESTOR" Ancestor
       "=======" B
       ">>>>>>> OTHER"))
   ;; don't open control buffer in a new frame
   '(ediff-window-setup-function 'ediff-setup-windows-plain)
   '(ediff-split-window-function 'split-window-horizontally)))

;;----------------------------------------------------------------------------;;

;; (Jane.whitespace)
(defun Jane.whitespace ()
  "Fixes up whitespace in everything but text modes, where whitespace
is more likely to be used on purpose."
  ;; the following line fixes a bug in whitespace.el
  (set (make-local-variable 'whitespace-indent-tabs-mode) indent-tabs-mode)
  (setq whitespace-style '(lines-tail tabs tab-mark trailing))
  (add-hook 'text-mode-hook (lambda () (setq whitespace-style nil)))
  (add-hook 'before-save-hook 'whitespace-cleanup))

;; deprecated
(defun Jane.whitespace-simple ()
  (interactive)
  (Jane.whitespace))

;; deprecated
(defun Jane.whitespace-fancy ()
  (interactive)
  (Jane.whitespace))

;;----------------------------------------------------------------------------;;

;; (Jane.selective-display)
(defun Jane.selective-display ()
  (defun js-selective-display ()
    "Activate selective display based on the column at point"
    (interactive)
    (set-selective-display
     (if selective-display
         nil
       (+ 1 (current-column)))))
  (global-set-key "\C-x$" 'js-selective-display))

;;----------------------------------------------------------------------------;;

;; a fork of cr-todo that guesses who it's "for" with hg annotate
(defun Jane.new-cr-todo ()
  (defun cr-dwim ()               ; dwim = do what I mean
    "Add a code review comment starting on current line or cycle CR/CRvYYYYMM/XCR"
    (interactive)
    (comment-dwim nil)
    (cond ((looking-at "CR ")
           (replace-match
            ;; inserts CRvYYYYMM where date will be between today and a year from now
            (concat "CRv" (format-time-string
                           "%Y%m" (time-add (current-time)
                                            (encode-time 0 0 0 0 (+ (random 12) 3)
                                                         1970)))
                    " ")
            t t))
          ((looking-at "CRv[0-9]+ ")
           (replace-match "XCR " t t))
          ((looking-at "XCR ")
           (replace-match "CR " t t))
          (t
           (insert "CR " (user-login-name) " for "
                   (substring (shell-command-to-string
                               (concat "hg --config defaults.annotate= annotate "
                                       (buffer-file-name (current-buffer))
                                       " -u | /bin/sed -n '" (number-to-string (line-number-at-pos))
                                       "{s/^ *\\([a-z]*\\):.*/\\1/;p}; d'"
                                       )) 0 -1)
                   ": ")
           (backward-word)))
    (forward-word)
    (forward-char 2))
  )

(provide 'js-micro-features)