-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.el
2469 lines (1946 loc) · 78.5 KB
/
init.el
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
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(require 'cl)
(setq mouse-buffer-menu-mode-mult 1000)
;; automatically enable linum-mode in all programming modes
(add-hook 'prog-mode-hook 'linum-mode)
;; ******************************************************
;; * Maximize Emacs window *
;; ******************************************************
;; Start emacs in fullscreen mode in Xorg
;; (defun fullscreen ()
;; (interactive)
;; (cond ((eq window-system 'x)
;; (x-send-client-message nil 0 nil "_NET_WM_STATE" 32
;; '(2 "_NET_WM_STATE_FULLSCREEN" 0)))
;; ((eq system-type 'windows-nt)
;; ;; Maximize Emacs window
;; (w32-send-sys-command ?\xf030))
;; ;;(w32-send-sys-command #xf030)
;; ))
;; (add-hook 'emacs-startup-hook 'fullscreen)
;; (add-hook 'window-setup-hook 'toggle-frame-maximized t)
;; This is bound to f11 in Emacs 24.4
;;(toggle-frame-fullscreen)
;;(add-hook 'window-setup-hook 'toggle-frame-fullscreen t)
(add-to-list 'default-frame-alist '(fullscreen . maximized))
(when (eq system-type 'windows-nt)
(w32-send-sys-command ?\xf030))
(defun w32-restore-frame ()
"Restore a minimized/maximized frame"
(interactive)
(w32-send-sys-command 61728))
(defun w32-maximize-frame ()
"Maximize the current frame"
(interactive)
(w32-send-sys-command 61488))
(global-set-key [(f4)] (function (lambda ()
"Maximize frame"
(interactive)
(w32-send-sys-command 61488))))
;; Close current buffer and reopen it (files only)
(defvar previous-opened-buffer nil)
(defun reopen.last.buffer ()
(interactive)
(let ((file.name (pop previous-opened-buffer)))
(if file.name
(find-file file.name)
(print "No more buffers to open"))))
(defun kill.this.buffer ()
(interactive)
(let ((buffer.name (buffer-file-name)))
(when buffer.name
(push buffer.name previous-opened-buffer)))
(kill-buffer))
(defun kill.region.or.buffer ()
(interactive)
(if (region-active-p)
(kill-region (region-beginning) (region-end))
(kill.this.buffer)))
(global-set-key [(control w)] 'kill.region.or.buffer)
(global-set-key [(control shift t)] 'reopen.last.buffer)
;; ******************************************************
;; (setq time-stamp-format "%:y-%02m-%02d %02H:%02M:%02S")
;; (setq buffer-time-stamp-format "%h %d %H:%M:%S")
(setq indicate-empty-lines t)
;;; Display date and time in mode line
(setq display-time-24hr-format t)
(setq display-time-day-and-date t)
(setq display-time-format nil)
(display-time-mode 1)
(setq european-calendar-style 't)
(setq calendar-week-start-day 1)
;; (auto-fill-mode 1)
;;;(add-hook 'lisp-mode-hook
;;; (lambda ()
;;; (turn-on-auto-fill)
;;; (set (make-local-variable 'fill-nobreak-predicate)
;;; (lambda ()
;;; (not (eq (get-text-property (point) 'face)
;;; 'font-lock-comment-face))))))
;;;(add-hook 'emacs-lisp-mode-hook 'turn-on-auto-fill)
;;;
;;;(add-hook 'fundamental-mode-hook 'turn-on-auto-fill)
;;;
;;;(add-hook 'text-mode-hook 'turn-on-auto-fill)
;;;
;;;
;;;(add-hook 'org-mode-hook 'turn-on-auto-fill)
;; display only tails of lines longer than 80 columns, tabs and
;; trailing whitespaces
(setq whitespace-line-column 80
whitespace-style '(tabs trailing lines-tail))
(require 'whitespace)
;; face for long lines' tails
(set-face-attribute 'whitespace-line nil
:background "red1"
:foreground "yellow"
:weight 'bold)
;; face for Tabs
(set-face-attribute 'whitespace-tab nil
:background "red1"
:foreground "yellow"
:weight 'bold)
(require 'info)
(require 'cl)
(require 'advice)
(require 'bytecomp)
(require 'timer)
;; FIXME
;;(require 'setnu)
;;(require 'wtf)
;;(add-hook 'prog-mode-hook #'hs-minor-mode)
;; (find-lisp-object-file-name 'goto-line 'function)
(cond ((eq system-type 'windows-nt)
(setq find-function-C-source-directory "c:/emacs-24.4.51-windows-x64/share/emacs/24.4.51/src")
(setq source-directory "c:/emacs-24.4.51-windows-x64"))
(t
(setq find-function-C-source-directory "/usr/share/emacs24/emacs24-24.3+1/src")
(setq source-directory "/usr/share/emacs24/emacs24-24.3+1")))
;; Info directory
(unless (boundp 'Info-directory-list)
(setq Info-directory-list Info-default-directory-list))
;; copy/paste between emacs and e.g. iceweasel
(setq x-select-enable-clipboard t)
;;
(setq default-truncate-lines t)
;; Since my sentences end with `. ' and not `. '
(setq sentence-end-double-space 'nil)
;; all files end with `\n'
(setq require-final-newline 'visit-save)
;; no pager-like behavior with ansi-term
(setq term-buffer-maximum-size 0)
(setq backup-by-copying t)
(setq compilation-scroll-output t)
;;(global-auto-revert-mode 1)
(setq global-auto-revert-non-file-buffers t)
;; Elevate some limits
(setq max-lisp-eval-depth '4000)
(setq max-specpdl-size '10000)
;; Disable enabled commands/keybindings
(put 'overwrite-mode 'disabled t)
;;;_ , automatically create path
;; some sort of mkdir -p for non existing paths
;; when opening a non-existing file (e.g. myfile) within some yet
;; non-existing directory, it automatically creates the file and
;; /path/to/file/myfile when the file is saved witin emacs
(add-hook 'before-save-hook
'(lambda ()
(or (file-exists-p (file-name-directory buffer-file-name))
(make-directory (file-name-directory buffer-file-name) t)))
'append)
;;;_ , automatically delete trailing whitespace
;; (add-hook 'before-save-hook 'delete-trailing-whitespace)
;;;_ , automatically untabify buffers
;;;(add-hook 'before-save-hook
;;; '(lambda ()
;;; (untabify (point-min) (point-max))))
;;;_ , autosave
;; save every 100 characters typed
(setq auto-save-interval 100)
;; save after 30 seconds of idle time
;; (setq auto-save-timeout 30)
(defun my-save-buffer-if-visiting-file (&optional args)
"Save the current buffer only if it is visiting a file"
(interactive)
(if (buffer-file-name)
(save-buffer args)))
;; This causes files that I'm editing to be saved automatically by the
;; emacs auto-save functionality. I'm hoping to break myself of the
;; c-x c-s twitch.
(add-hook 'auto-save-hook 'my-save-buffer-if-visiting-file)
;;;_ , my-frame-title-refresh
;; Show date and current time, GNU Emacs version and `buffer-file-name'
;; if available, `buffer-name' otherwise
;; (defun my-frame-title-refresh ()
;; (setq frame-title-format
;; `(,(buffer-file-name "buffer-file-name: %f" ("%b"))
;; " "
;; ,(format-time-string "Week/Day of year: %W/%j")
;; " "
;; ,(format-time-string "Weekday: %A")
;; " "
;; ,(format-time-string "Date: %Y/%m/%d")
;; " "
;; ,(format-time-string "Time: ")
;; ,(replace-regexp-in-string "\n" "" (shell-command-to-string "date -u +%H:%M"))
;; " UTC"
;; " "
;; ,(substring (emacs-version) 0 20)
;; )))
;; Update frame title every minute
;;(run-with-timer 1 60 'my-frame-title-refresh)
;; (cancel-timer (fifth timer-list))
;;;_ , Auto bytecompile
(defun byte-compile-init-file ()
(when (equal buffer-file-name user-init-file)
(let ((byte-compile-warnings '(unresolved)))
(when (file-exists-p (concat user-init-file ".elc"))
(delete-file (concat user-init-file ".elc")))
(byte-compile-file user-init-file)
(message "Just compiled %s " user-init-file))))
(add-hook 'kill-buffer-hook 'byte-compile-init-file)
;;_ , command-history
;; See `chistory.el'
;; NOTES:
;; 1) I use `command-history' which is bound to `C-x c' on a regular
;; 2) Using `repeat-complex-command' wich is bound to `C-x M-:' per
;; default is also pretty useful
(setq list-command-history-max '100)
;;;_ , higlight-changes-mode
;;(global-highlight-changes-mode t)
;;(setq highlight-changes-global-changes-existing-buffers t)
;;;_ , uniquify
;; See (Info-goto-node "(emacs) Uniquify")
(require 'uniquify)
(setq uniquify-buffer-name-style 'forward)
(setq uniquify-trailing-separator-p t)
;;_ , multi-protocol remote file access
;; See (Info-goto-node "(tramp)Top") as well as
;; http://www.emacswiki.org/cgi-bin/wiki/TrampMode
;; What I also consider very useful is
;;(Info-goto-node "(tramp)Version Control")
(require 'tramp)
;;(add-to-list 'Info-default-directory-list "~/git/tramp/info/")
;;(setq tramp-default-method "ssh")
;;;_ , dired
(setq dired-dwim-target t)
(setq dired-recursive-copies 'always)
(setq dired-recursive-deletes 'always)
(setq image-dired-external-viewer "/usr/bin/gimp")
;;;_ , dired-x
;; See (Info-goto-node "(dired-x) Top")
(require 'dired-x)
;;;_ . Advanced Mark Commands
;; (Info-goto-node "(dired-x) Advanced Mark Commands")
;;;_ . Omit
;; (dired-omit-mode 1)
;; (setq dired-omit-files (concat dired-omit-files "\\|^\\."))
;; (setq dired-omit-extensions `(,@dired-omit-extensions ".avi" ".mp3"))
;;;_ , image-dired
;; See http://www.emacswiki.org/cgi-bin/wiki/Tumme
(require 'image-dired)
(setq image-dired-show-all-from-dir-max-files 100)
(setq image-dired-thumb-margin 4)
(setq image-dired-thumb-relief 0)
(require 'recentf)
(recentf-mode 1) ;recently edited files in menu
(setq recentf-max-menu-items 25)
(global-set-key "\C-xr" 'recentf-open-files)
;;;_ Web
;;;_. standard browser to open URLs within GNU Emacs
;; See http://www.emacswiki.org/cgi-bin/wiki/BrowseUrl for more information.
;;;(setq gnus-button-url 'browse-url-generic
;;; browse-url-browser-function gnus-button-url)
;;;(setq gnus-button-url (list (cons "." 'browse-url-generic)))
(setf browse-url-generic-program (cond ((eq system-type 'windows-nt)
"C:/Program Files/Google/Chrome/Application/chrome.exe")
(t "iceweasel")))
(defvar browse-url-chm-program "D:/clhs/KeyHH.exe")
(defvar browse-url-chm-program-args '("-emacs"))
(defun browse-url-chm (url &rest args)
(with-temp-buffer
(let ((process (apply 'start-process
"CHMBrowser"
nil
browse-url-chm-program
(append browse-url-chm-program-args (list url)))))
(process-kill-without-query process))))
(unless (listp browse-url-browser-function)
(setf browse-url-browser-function (list (cons "." browse-url-browser-function))))
(pushnew '("\\.chm" . browse-url-chm) browse-url-browser-function :test 'equal)
;;; HyperSpec
;; (setq common-lisp-hyperspec-root "k:/doc/ansicl/HyperSpec/")
;; (setq common-lisp-hyperspec-root "D:\\clhs\\clhs.chm::/")
;; (setq common-lisp-hyperspec-symbol-table "D:/clhs/Map_Sym.txt")
(defun google-region-or-query ()
"Googles a query or region if any."
(interactive)
(browse-url
(concat
"http://www.google.com/search?ie=utf-8&oe=utf-8&q="
(if mark-active
(buffer-substring (region-beginning) (region-end))
(read-string "Query: ")))))
(global-set-key [M-mouse-3] 'google-region-or-query)
;;;_. w3m
;;(require 'w3m)
;;; GNUGP && EasyPG
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(add-to-list 'load-path (expand-file-name "~/git/gnupg"))
;;(require 'epa-file)
;;(epa-file-enable)
;;; Info mode
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; After Info-mode has started
(add-hook 'Info-mode-hook
(lambda ()
(setq Info-additional-directory-list Info-default-directory-list)
)
'append)
(add-to-list 'Info-default-directory-list "~/git/gnupg/doc")
(add-to-list 'Info-default-directory-list "~/git/gnus/texi")
(add-to-list 'Info-default-directory-list "~/git/org-mode/doc")
;;;(Info-goto-node "(emacs)FFAP")
;;;(Info-goto-node "(dired-x) Top")
;;;(Info-goto-node "(gnus)Category Syntax")
;;;(Info-goto-node "(bbdb) Mail Sending Interfaces")
;;;(Info-goto-node "(message)Security")
;;__________________________________________________________________________
;;;; System Customizations
;; keys for moving to prev/next code section (Form Feed; ^L)
(global-set-key (kbd "<C-M-prior>") 'backward-page) ; Ctrl+Alt+PageUp
(global-set-key (kbd "<C-M-next>") 'forward-page) ; Ctrl+Alt+PageDown
;; Prevent the cursor from blinking
(blink-cursor-mode 0)
;; Who use the bar to scroll?
;;(scroll-bar-mode left)
;;(set-scroll-bar-mode 'left)
;;(set-scroll-bar-mode 'right)
;; Deactivate tooltips in emacs
(tooltip-mode 0)
(tool-bar-mode -1)
(scroll-bar-mode -1)
;; (setq scroll-margin 0)
;; (setq scroll-conservatively 100000)
;; (setq scroll-preserve-screen-position 1)
;;(fringe-mode 'no-fringes)
;; Delete the selection area with a keypress
(delete-selection-mode t)
;; Use font-lock everywhere.
(global-font-lock-mode t)
;; We have CPU to spare; highlight all syntax categories.
(setq font-lock-maximum-decoration t)
;; Set buffer behaviour
;; Prevent emacs from adding newlines when pressing down arrow at the end of the buffer
(setq next-line-add-newlines nil)
;; Ordinarily emacs jumps by half a page when scrolling -- reduce:
(setq scroll-step 1)
(setq scroll-conservatively 5)
;; Enable emacs functionality that is disabled by default
(put 'eval-expression 'disabled nil)
(put 'set-goal-column 'disabled nil)
(put 'narrow-to-page 'disabled nil)
(put 'narrow-to-region 'disabled nil)
(put 'downcase-region 'disabled nil)
(put 'upcase-region 'disabled nil)
(setq enable-recursive-minibuffers t)
;; Misc customizations
(fset 'yes-or-no-p 'y-or-n-p) ;replace y-e-s by y
;;________________________________________________________________
;; Don't display initial logo
;;________________________________________________________________
(setq inhibit-startup-message t) ;no startup message
(setq inhibit-splash-screen t) ;no splash screen
(setq initial-scratch-message "") ; Don't use messages that you don't read
(defconst use-backup-dir t) ;use backup directory
(defconst query-replace-highlight t) ;highlight during query
(defconst search-highlight t) ;highlight incremental search
(setq ls-lisp-dirs-first t) ;display dirs first in dired
(global-font-lock-mode t) ;colorize all buffers
(setq ecb-tip-of-the-day nil) ;turn off ECB tips
;; If we read a compressed file, uncompress it on the fly:
;; (this works with .tar.gz and .tgz file as well)
(auto-compression-mode 1)
;; The following key-binding iconifies a window -- we disable it:
(global-unset-key "\C-x\C-z")
;; The following key-binding quits emacs -- we disable it too:
(global-unset-key "\C-x\C-c")
;; But we establish a longer sequence that is harder to hit by accident:
(global-set-key "\C-x\C-c\C-v" 'save-buffers-kill-emacs)
;; The longer sequence is all right: emacs should be launched just
;; once at login and never killed until ready to logout.
;; Disable binding of C-z to iconify a window.
(global-unset-key "\C-z")
;; M-` invokes tmm-menubar; disable it.
(global-unset-key "\M-`")
;; C-x C-n invokes set-goal-column; disable it.
(global-unset-key "\C-x\C-n")
;;________________________________________________________________
;; Flash the screen on error; don't beep.
;;________________________________________________________________
(setq-default visible-bell t)
;;________________________________________________________________
;; Files and directories
;;________________________________________________________________
;; dired-x is a nice substitute for Windows Explorer and OSX's Finder.
;; M-o: avoid seeing all the backup files.
;; C-x C-j: enter dired/dired-x mode.
(add-hook 'dired-load-hook
(function (lambda ()
(load "dired-x"))))
;; Ordinarily emacs jumps by half a page when scrolling -- reduce:
(setq scroll-step 1)
;;________________________________________________________________
;; scroll-left is disabled by default; enable it.
;;________________________________________________________________
(put 'scroll-left 'disabled nil)
(put 'set-goal-column 'disabled nil)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; KEY RECONFIGURATION
;; HOME - go to beginning of line
(define-key global-map [home] 'beginning-of-line)
;; C-HOME - go to beginning of buffer
(define-key global-map [C-home] 'beginning-of-buffer)
;; END - go to end of line
(define-key global-map [end] 'end-of-line)
;; C-END - go to end of buffer
(define-key global-map [C-end] 'end-of-buffer)
;; KEYPAD-/ - "/" character
(define-key global-map [kp-divide] "/")
(global-set-key [C-tab] 'hippie-expand)
(global-set-key [M-delete] 'kill-word)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; NAVIGATION
;; M-LEFT - begining of S-Expression
(define-key global-map [M-left] 'backward-sexp)
;; M-RIGHT - end of S-Expression
(define-key global-map [M-right] 'forward-sexp)
;; Isto destina-se a permitir seleccionar simbolos com '.' no meio quando se carrega
;; o botao do meio do rato
(modify-syntax-entry ?# "_ " emacs-lisp-mode-syntax-table)
(modify-syntax-entry ?. "w " emacs-lisp-mode-syntax-table)
(modify-syntax-entry ?# "_ " lisp-mode-syntax-table)
(modify-syntax-entry ?. "w " lisp-mode-syntax-table)
(global-set-key "\M-\C-\\" 'indent-region)
;;; VISUAL ENHANCEMENTS
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Highlight isearch current match
(setq search-highlight t)
;; Permanent display of line and column numbers is handy.
(setq-default line-number-mode 't)
(setq-default column-number-mode 't)
;;; Display date and time in mode line
;; (setq display-time-24hr-format t)
;; (setq display-time-day-and-date t)
;; (display-time)
(setq mouse-wheel-progressive-speed nil)
(setq-default show-trailing-whitespace t)
;;; Quick expression selection with control return
(defun select-current-sexp ()
(interactive)
(when (and (not (char-equal (char-after) ?\())
(char-equal (char-before) ?\)))
(backward-char)
(backward-up-list))
(when mark-active
(backward-up-list))
(mark-sexp 1))
(global-set-key [(ctrl return)] 'select-current-sexp)
(global-set-key [f10] 'reposition-defun-at-top)
(global-set-key [f12] 'revert-buffer)
;; ******************************************************
;; * EMACS - SLIME *
;; ******************************************************
;; How to customize Emacs split-window-X with the new window showing the next buffer?
;; Funciona para C-x 2 e C-x 3.
(defun split-window-and-next-buffer (new-window)
(let ((old-window (selected-window)))
(select-window new-window)
(next-buffer)
(select-window old-window)
new-window))
(defadvice split-window-right (after split-window-right-and-next-buffer
activate protect compile)
(split-window-and-next-buffer ad-return-value))
(defadvice split-window-below (after split-window-bellow-and-next-buffer
activate protect compile)
(split-window-and-next-buffer ad-return-value))
;; To remove the advices, call the functions until they return nil.
;;(ad-unadvise 'split-window-below)
;;(ad-unadvise 'split-window-right)
(defvar electrify-return-match
"[\]}\)\"]"
"If this regexp matches the text after the cursor, do an \"electric\"
return.")
(defun electrify-return-if-match (arg)
"If the text after the cursor matches `electrify-return-match' then
open and indent an empty line between the cursor and the text. Move the
cursor to the new line."
(interactive "P")
(let ((case-fold-search nil))
(if (looking-at electrify-return-match)
(save-excursion (newline-and-indent)))
(newline arg)
(indent-according-to-mode)))
(require 'eldoc) ; if not already loaded
;;;(eldoc-add-command
;;; 'paredit-backward-delete
;;; 'paredit-close-round)
(add-hook 'emacs-lisp-mode-hook
(lambda ()
;;; (paredit-mode t)
(turn-on-eldoc-mode)
;;; (eldoc-add-command
;;; 'paredit-backward-delete
;;; 'paredit-close-round)
(local-set-key (kbd "RET") 'electrify-return-if-match)
(eldoc-add-command 'electrify-return-if-match)))
(add-hook 'lisp-interaction-mode-hook 'turn-on-eldoc-mode)
(add-hook 'ielm-mode-hook 'turn-on-eldoc-mode)
;; source: http://steve.yegge.googlepages.com/my-dot-emacs-file
(defun rename-file-and-buffer (new-name)
"Renames both current buffer and file it's visiting to NEW-NAME."
(interactive "sNew name: ")
(let ((name (buffer-name))
(filename (buffer-file-name)))
(if (not filename)
(message "Buffer '%s' is not visiting a file!" name)
(if (get-buffer new-name)
(message "A buffer named '%s' already exists!" new-name)
(progn
(rename-file name new-name 1)
(rename-buffer new-name)
(set-visited-file-name new-name)
(set-buffer-modified-p nil))))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ENCODING ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; C-h C RET
;; M-x describe-current-coding-system
(add-to-list 'file-coding-system-alist '("\\.tex" . utf-8-unix) )
(add-to-list 'file-coding-system-alist '("\\.txt" . utf-8-unix) )
;(add-to-list 'file-coding-system-alist '("\\.el" . utf-8-unix) )
(add-to-list 'file-coding-system-alist '("\\.scratch" . utf-8-unix) )
(add-to-list 'file-coding-system-alist '("user_prefs" . utf-8-unix) )
(add-to-list 'file-coding-system-alist '("\\.xml" . utf-8-unix) )
(add-to-list 'file-coding-system-alist '("\\.java" . utf-8-unix) )
(add-to-list 'file-coding-system-alist '("\\.bash_profile" . utf-8-unix) )
(add-to-list 'file-coding-system-alist '("\\.bashrc" . utf-8-unix) )
(add-to-list 'file-coding-system-alist '("\\.profile" . utf-8-unix) )
(add-to-list 'file-coding-system-alist '("\\.sh" . utf-8-unix) )
(add-to-list 'file-coding-system-alist '("\\.org" . utf-8-unix) )
(cond ((eq system-type 'windows-nt)
(add-to-list 'file-coding-system-alist '("\\.lisp" . iso-latin-1-dos) )
(add-to-list 'file-coding-system-alist '("\\.cl" . iso-latin-1-dos) )
(add-to-list 'file-coding-system-alist '("\\.dic" . iso-latin-1-dos) )
(add-to-list 'file-coding-system-alist '("\\.data" . iso-latin-1-dos) )
)
(t
(add-to-list 'file-coding-system-alist '("\\.lisp" . utf-8-unix) )
(add-to-list 'file-coding-system-alist '("\\.cl" . utf-8-unix) )
))
(add-to-list 'process-coding-system-alist '("\\.txt" . utf-8-unix) )
(add-to-list 'network-coding-system-alist '("\\.txt" . utf-8-unix) )
(setq locale-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(prefer-coding-system 'utf-8)
(set-default-coding-systems 'utf-8-unix)
(set-terminal-coding-system 'utf-8-unix)
; (set-selection-coding-system 'utf-8)
(setq-default buffer-file-coding-system 'utf-8-unix)
(setq default-process-coding-system '(utf-8-unix . utf-8-unix))
(set-charset-priority 'unicode)
(set-language-environment 'utf-8)
(unless (eq system-type 'windows-nt)
(set-selection-coding-system 'utf-8))
;; Treat clipboard input as UTF-8 string first; compound text next, etc.
(setq x-select-request-type '(UTF8_STRING COMPOUND_TEXT TEXT STRING))
;; mnemonic for utf-8 is "U", which is defined in the mule.el
(setq eol-mnemonic-dos ":CRLF")
(setq eol-mnemonic-mac ":CR")
(setq eol-mnemonic-undecided ":?")
(setq eol-mnemonic-unix ":LF")
(defalias 'read-buffer-file-coding-system 'lawlist-read-buffer-file-coding-system)
(defun lawlist-read-buffer-file-coding-system ()
(let* ((bcss (find-coding-systems-region (point-min) (point-max)))
(css-table
(unless (equal bcss '(undecided))
(append '("dos" "unix" "mac")
(delq nil (mapcar (lambda (cs)
(if (memq (coding-system-base cs) bcss)
(symbol-name cs)))
coding-system-list)))))
(combined-table
(if css-table
(completion-table-in-turn css-table coding-system-alist)
coding-system-alist))
(auto-cs
(unless find-file-literally
(save-excursion
(save-restriction
(widen)
(goto-char (point-min))
(funcall set-auto-coding-function
(or buffer-file-name "") (buffer-size))))))
(preferred 'utf-8-unix)
(default 'utf-8-unix)
(completion-ignore-case t)
(completion-pcm--delim-wild-regex ; Let "u8" complete to "utf-8".
(concat completion-pcm--delim-wild-regex
"\\|\\([[:alpha:]]\\)[[:digit:]]"))
(cs (completing-read
(format "Coding system for saving file (default %s): " default)
combined-table
nil t nil 'coding-system-history
(if default (symbol-name default)))))
(unless (zerop (length cs)) (intern cs))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; SHOW ERRORS ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Show errors in this file:
;; (setq debug-on-error t)
;; (setq stack-trace-on-error t)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ELECTRIC MODE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(when (>= emacs-major-version 24)
(electric-pair-mode))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ORG MODE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(add-to-list 'load-path (expand-file-name "~/org-mode/lisp"))
(add-to-list 'auto-mode-alist '("\\.\\(org\\|org_archive\\)$" . org-mode))
(require 'org)
(require 'org-id)
;; (require 'org-checklist)
;;(require 'org-latex)
(require 'org-clock)
;;(require 'org-special-blocks)
(require 'org-habit)
;; Nice bullets
;;(require 'org-bullets)
;;(add-hook 'org-mode-hook (lambda () (org-bullets-mode 1)))
;;
;; Standard key bindings
(global-set-key "\C-cl" 'org-store-link)
(global-set-key "\C-cb" 'org-iswitchb)
;; Custom Key Bindings
;;(global-set-key (kbd "<f11>") 'org-clock-goto)
(add-to-list 'org-src-lang-modes
'("elisp" . emacs-lisp))
(add-to-list 'org-src-lang-modes
'("emacs_lisp" . emacs-lisp))
(setq org-src-preserve-indentation t)
(setq org-edit-src-auto-save-idle-delay 0)
(setq org-edit-src-content-indentation 0)
(setq org-export-coding-system 'utf-8-unix)
(unless (boundp 'org-export-latex-classes)
(setq org-export-latex-classes nil))
(add-to-list 'org-export-latex-classes
'("article"
"\\documentclass{article}"
("\\section{%s}" . "\\section*{%s}")))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ORG-MODE SETUP ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq org-directory "~/org")
(setq org-default-notes-file "~/org/notes.org")
(add-to-list 'load-path (expand-file-name "~/git/org-mode/contrib/lisp"))
(setq org-empty-line-terminates-plain-lists t)
(setq org-enforce-todo-dependencies t)
(setq org-cycle-separator-lines 0)
(setq org-blank-before-new-entry (quote ((heading)
(plain-list-item . auto))))
(setq org-insert-heading-respect-content nil)
(setq org-M-RET-may-split-line (quote ((headline) (default . t))))
(setq org-show-following-heading t)
(setq org-show-hierarchy-above t)
(setq org-show-siblings (quote ((default))))
(setq org-id-method (quote uuidgen))
(setq org-table-export-default-format "orgtbl-to-csv")
(setq org-time-stamp-rounding-minutes (quote (1 1)))
(defvar bh/insert-inactive-timestamp nil)
(defun bh/toggle-insert-inactive-timestamp ()
(interactive)
(setq bh/insert-inactive-timestamp (not bh/insert-inactive-timestamp))
(message "Heading timestamps are %s" (if bh/insert-inactive-timestamp "ON" "OFF")))
(defun bh/insert-inactive-timestamp ()
(interactive)
(org-insert-time-stamp nil t t nil nil nil))
;; (defun bh/insert-inactive-timestamp ()
;; (interactive)
;; (org-insert-time-stamp nil t t nil nil nil))
(defun bh/insert-heading-inactive-timestamp ()
(save-excursion
(when bh/insert-inactive-timestamp
(org-return)
(org-cycle)
(bh/insert-inactive-timestamp))))
;;(add-hook 'org-insert-heading-hook 'bh/insert-heading-inactive-timestamp 'append)
;; (global-set-key (kbd "<f9> t") 'bh/insert-inactive-timestamp)
;; (setq org-treat-insert-todo-heading-as-state-change t)
(setq org-todo-keywords '((sequence "TODO(t)" "WAITING(w)" "DEFERRED(f)" "STARTED(s)" "|" "DONE(d)" "NOTE(n)" "PHONE(p)" "MEETING(m)" "CLOSED(l)" "CANCELED(c)")))
(setq org-todo-keyword-faces (quote (("TODO" :foreground "red" :weight bold)
("WAITING" :foreground "orange" :weight bold)
("DEFERRED" :foreground "orange" :weight bold)
("STARTED" :foreground "orange" :weight bold)
("DONE" :foreground "forest green" :weight bold)
("NOTE" :foreground "dark violet" :weight bold)
("PHONE" :foreground "dark violet" :weight bold)
("MEETING" :foreground "dark violet" :weight bold)
("CLOSED" :foreground "forest green" :weight bold)
("CANCELLED" :foreground "forest green" :weight bold))))
(setq org-use-fast-todo-selection t)
(setq org-treat-S-cursor-todo-selection-as-state-change nil)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ORG REFILE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq org-refile-targets '((nil :maxlevel . 2)
; all top-level headlines in the
; current buffer are used (first) as a
; refile target
(org-agenda-files :maxlevel . 2)))
;; provide refile targets as paths, including the file name
;; (without directory) as level 1 of the path
(setq org-refile-use-outline-path 'file)
;; allow to create new nodes (must be confirmed by the user) as
;; refile targets
(setq org-refile-allow-creating-parent-nodes 'confirm)
(setq org-log-refile t)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ORG CLOCKING ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Resume clocking task when emacs is restarted
(org-clock-persistence-insinuate)
;;
;; Show lot of clocking history so it's easy to pick items off the C-F11 list
(setq org-clock-history-length 23)
;; Resume clocking task on clock-in if the clock is open
(setq org-clock-in-resume t)
(setq org-clock-in-switch-to-state "STARTED")
;; Show the time-clock in the modeline.
(setq org-clock-modeline-total 'current)
;; Keybindings. I don't want Org Mode to grab the movement keys for indentation.
(setq org-replace-disputed-keys t)
;; Separate drawers for clocking and logs
(setq org-drawers (quote ("PROPERTIES" "LOGBOOK" "CLOCK" "SCHEDULE" "HIDDEN")))
;; Time Tracking
(setq org-log-done (quote time))
(setq org-log-into-drawer "LOGBOOK")
(setq org-log-repeat 'time)
;; Save clock data and state changes and notes in the LOGBOOK drawer
(setq org-clock-into-drawer t)
;; Sometimes I change tasks I'm clocking quickly - this removes clocked tasks with 0:00 duration
(setq org-clock-out-remove-zero-time-clocks t)
;; Clock out when moving task to a done state
(setq org-clock-out-when-done t)
;; Save the running clock and all clock history when exiting Emacs, load it on startup
(setq org-clock-persist t)
;; Do not prompt to resume an active clock
(setq org-clock-persist-query-resume nil)
;; Enable auto clock resolution for finding open clocks
(setq org-clock-auto-clock-resolution (quote when-no-clock-is-running))
(setq bh/keep-clock-running nil)
(defun bh/is-project-p ()
"Any task with a todo keyword subtask"
(save-restriction
(widen)
(let ((has-subtask)
(subtree-end (save-excursion (org-end-of-subtree t)))
(is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1)))
(save-excursion
(forward-line 1)
(while (and (not has-subtask)
(< (point) subtree-end)
(re-search-forward "^\*+ " subtree-end t))
(when (member (org-get-todo-state) org-todo-keywords-1)