-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinit.el
2938 lines (2296 loc) · 99 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
; Time-stamp: <2014-02-23 14:55:31 (rolando)>
;;(set-scroll-bar-mode 'right)
(tool-bar-mode 0)
(scroll-bar-mode 0)
(menu-bar-mode 0)
(when (fboundp 'horizontal-scroll-bar-mode)
;; "trunk" Emacs now also adds a horizontal scroll-bar
;; This disables it.
(horizontal-scroll-bar-mode 0))
;; Load CEDET
;; This should be near the top of your init file, so that this can
;; really replace the CEDET that ships with Emacs proper.
(ignore-errors (load-file "/home/rolando/src/bazaar/cedet/cedet-devel-load.el"))
;; Add further minor-modes to be enabled by semantic-mode.
;; See doc-string of `semantic-default-submodes' for other things
;; you can use here.
(add-to-list 'semantic-default-submodes 'global-semantic-idle-summary-mode)
(add-to-list 'semantic-default-submodes 'global-semantic-idle-completions-mode)
;; Enable Semantic
(semantic-mode 1)
;;; Need to require "nxml-mode" before loading any theme with the `load-theme' command, otherwise XML files won't be font-locked
(require 'nxml-mode)
;; TODO: Arranjar uma keybind para find-function (podera funcionar melhor que as tags)
;; TODO: Ver a funcao normal-top-level-add-subdirs-to-load-path
;; Load CEDET.
;; See cedet/common/cedet.info for configuration details.
;; IMPORTANT: For Emacs >= 23.2, you must place this *before* any
;; CEDET component (including EIEIO) gets activated by another
;; package (Gnus, auth-source, ...).
;; (load-file "~/.emacs.d/elisp/cedet/common/cedet.el")
;; Enable EDE (Project Management) features
;; (global-ede-mode 1)
;; Enable EDE for a pre-existing C++ project
;(ede-cpp-root-project "buntoids" :file "~/src/git/buntoids/source/Makefile")
;; Enabling Semantic (code-parsing, smart completion) features
;; Select one of the following:
;; * This enables the database and idle reparse engines
;(semantic-load-enable-minimum-features)
;; * This enables some tools useful for coding, such as summary mode
;; imenu support, and the semantic navigator
;(semantic-load-enable-code-helpers)
;; * This enables even more coding tools such as intellisense mode
;; decoration mode, and stickyfunc mode (plus regular code helpers)
;(semantic-load-enable-gaudy-code-helpers)
;; * This enables the use of Exuberent ctags if you have it installed.
;; If you use C++ templates or boost, you should NOT enable it.
;; (semantic-load-enable-all-exuberent-ctags-support)
;; Or, use one of these two types of support.
;; Add support for new languges only via ctags.
;; (semantic-load-enable-primary-exuberent-ctags-support)
;; Add support for using ctags as a backup parser.
;; (semantic-load-enable-secondary-exuberent-ctags-support)
;; Enable SRecode (Template management) minor-mode.
;; (global-srecode-minor-mode 1)
(defun yas/minor-mode-off ()
(yas-minor-mode -1))
(defvar *emacs-load-start* (current-time))
;; FIXME: c-annotation-face has a bad color
;; Experimentar usar a variavel default-directory ou user-emacs-directory
(defun where-am-i ()
"If it returns t, then I am on the laptop, otherwise I am on the desktop."
(let ((LAPTOP-HOSTNAME "rolando-laptop")
(DESKTOP-HOSTNAME "rolando-K8NF4G-VSTA"))
(cond ((string= system-name LAPTOP-HOSTNAME)
'laptop)
((string= system-name DESKTOP-HOSTNAME)
'desktop)
(t
'undefined))))
(defun running-on-laptop-p ()
(equal (where-am-i) 'laptop))
(defun running-on-desktop-p ()
(equal (where-am-i) 'desktop))
(defun running-on-undefined-p ()
(equal (where-am-i) 'undefined))
(defun running-linux-p ()
(equal system-type 'gnu/linux))
(defun running-windows-p ()
(equal system-type 'windows-nt))
;; (defconst +dot-emacs-whereami+ (Where-Am-i)
;; "If 'laptop, then we are on the laptop and in the linux system.
;; If 'desktop, then we are on the desktop system and in the linux system.
;; If 'undefined, then we don't know where we are.")
(require 'server)
(when (and (running-linux-p)
(not (server-running-p)))
(server-start))
;; Idea from http://nflath.com/2009/07/more-random-emacs-config/
(defun rolando-back-to-indentation-or-move-beginning-of-line ()
"Moves to the first caracter in the line, unless it's in it, in that case
it moves the cursor to the beginning-of-line"
(interactive)
(let ((current-point (point)))
(back-to-indentation)
(if (= current-point (point))
(move-beginning-of-line nil))))
(global-set-key (kbd "C-a") 'rolando-back-to-indentation-or-move-beginning-of-line)
(global-set-key (kbd "<home>") 'rolando-back-to-indentation-or-move-beginning-of-line)
(defun set-home-folder ()
(cond ((and (running-on-laptop-p) (not (running-windows-p)))
;"/media/JCARLOS/")
"/home/rolando/")
((running-windows-p)
(substring default-directory 0 -9))
((running-on-desktop-p)
"/home/rolando/")))
;(message (file-name-directory load-file-name))
(defconst +dot-emacs-home+ (concat (set-home-folder) ".emacs.d/"))
;; (defconst home (file-name-directory load-file-name))
(defun file-in-exec-path-p (filename)
"Returns t if FILENAME is in the system exec-path, otherwise returns nil"
(if (executable-find filename)
t
nil))
;; E necessario muitas vezes
(with-no-warnings
(require 'cl))
;; Load Emacs Code Browser
;; (add-to-list 'load-path (concat +dot-emacs-home+ ".emacs.d/elisp/ecb-snap"))
;; (require 'ecb)
(setq eldoc-idle-delay 0)
(setq visible-bell t)
(add-to-list 'load-path (concat +dot-emacs-home+ "elisp"))
(add-to-list 'load-path (concat +dot-emacs-home+ "elpa"))
(add-to-list 'load-path (concat +dot-emacs-home+ "elisp/use-package"))
;; Activate packages installed using package.el
(load "package")
(package-initialize)
(when window-system
;; (load-theme 'wombat)
;; (load-theme 'cyberpunk)
(load-theme 'zenburn))
(require 'use-package)
(use-package usage-memo
:init (umemo-initialize))
;; Check to see if the pydb emacs package is installed
(when (file-directory-p "/user/share/emacs/site-lisp/pydb")
(setq load-path (append '("/usr/share/emacs/site-lisp/pydb") load-path)))
(setq c-default-style "bsd")
(message "Stop 1 %ds" (destructuring-bind (hi lo ms &rest ignore) (current-time)
(- (+ hi lo) (+ (first *emacs-load-start*) (second *emacs-load-start*)))))
(setq require-final-newline t) ; Always newline at end of file
;; Mostrar os espacos vazios no final das linhas
;; FIXME: This should only be on the programming mode
(setq show-trailing-whitespace t)
(when window-system
(global-unset-key "\C-z")) ; iconify-or-deiconify-frame (C-x C-z)
(setq-default ispell-program-name "aspell") ; Use aspell instead of ispell
(setq ispell-dictionary "pt_PT") ; Set ispell dictionary
(setq frame-title-format "%b - emacs")
; Tabs expand to 4 spaces
(setq-default c-basic-offset 4
tab-width 4
indent-tabs-mode nil)
(setq backward-delete-char-untabify nil
tab-width 4)
;;;
;; SVN browser
(use-package psvn
:commands svn-status)
;; Some modes require this
(setq user-mail-address "finalyugi@sapo.pt"
user-full-name "Rolando Pereira")
;;;
; Activar Org-Mode
;;;;;
; Mostra so a * mais a direita no org-mode
(setq org-hide-leading-stars t)
;;;
;; The following lines are always needed. Choose your own keys.
;; (Configuracoes do Org-Mode)
(add-to-list 'auto-mode-alist '("\\.org$" . org-mode))
(global-set-key "\C-cl" 'org-store-link)
(global-set-key "\C-ca" 'org-agenda)
;; (global-set-key "\C-cb" 'org-iswitchb)
;;;;;
;; Activar flymake-mode para o python usando o pyflakes
(when (and (load "flymake" t) (file-in-exec-path-p "pyflakes"))
(defun flymake-pyflakes-init ()
(let* ((temp-file (flymake-init-create-temp-buffer-copy
'flymake-create-temp-inplace))
(local-file (file-relative-name
temp-file
(file-name-directory buffer-file-name))))
(list "pyflakes" (list local-file))))
(add-to-list 'flymake-allowed-file-name-masks
'("\\.py\\'" flymake-pyflakes-init)))
;; FIXME: flymake-find-file-hook should be used only if there is a makefile
;(add-hook 'find-file-hook 'flymake-find-file-hook)
;;;
; Flymake settings
(defun my-flymake-show-next-error()
(interactive)
(flymake-goto-next-error)
(flymake-display-err-menu-for-current-line))
(global-set-key [f8] 'my-flymake-show-next-error)
;; '(flymake-errline ((((class color)) (:underline "OrangeRed"))))
;; '(flymake-warnline ((((class color)) (:underline "yellow"))))
; Activar folding no Python
(defun my-python-mode-hook ()
(hs-minor-mode 1)
(eldoc-mode 1)
'(lambda ()
(local-set-key (kbd "RET") 'newline-and-indent)))
(add-hook 'python-mode-hook 'my-python-mode-hook)
(use-package nlinum)
;; C/C++/Java/C# Mode
(defun my-c-mode-common-hook ()
(setq show-paren-style 'parenthesis)
;(setq c-hungry-delete-key t)
;(setq c-auto-newline 1)
(highlight-fixmes-mode)
(hs-minor-mode)
; (lambda ()
; (font-lock-add-keywords nil
; '(("\\<\\(FIXME\\|TODO\\|BUG\\):" 1 font-lock-warning-face t))))
;(flymake-mode t)
;(yas/minor-mode)
;; Show line numbers
(nlinum-mode)
)
(message "Stop 2 %ds" (destructuring-bind (hi lo ms &rest ignore) (current-time)
(- (+ hi lo) (+ (first *emacs-load-start*) (second *emacs-load-start*)))))
(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
; Mudar a theme do emacs
;; (when window-system
;; (require 'color-theme)
;; ;(require 'color-theme-tango)
;; (require 'zenburn)
;; (require 'color-theme-dark-bliss)
;; ;(require 'color-theme-sunburst)
;; (color-theme-initialize)
;; ;(color-theme-charcoal-black))
;; ;(color-theme-taming-mr-arneson))
;; ; (color-theme-goldenrod)
;; ;(color-theme-tango))
;; ;(color-theme-zenburn))
;; ;(color-theme-sunburst))
;; ;(color-theme-taylor))
;; ;(color-theme-dark-bliss)
;; (color-theme-midnight))
;; ;(require 'color-theme-twilight)
;; ;; (color-theme-twilight))
;; ; Other themes: midnight, white on black, charcoal black, Calm Forest, Billw,
;; ; Arjen, Clarity and Beauty, Cooper Dark, Comidia, Dark Blue 2, Dark Laptop,
;; ; Deep Blue, Hober, Late Night, Lethe, Linh Dang Dark, Taming Mr Arneson,
;; ; Subtle Hacker, TTY Dark, Taylor, White On Black, Robin Hood
;; ;;;
; Add colors to shell
(add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on)
;;
;; zooming in and zooming out in emacs like in firefox
;; zooming; inspired by http://blog.febuiles.com/page/2/
(defun djcb-zoom (n) (interactive)
(set-face-attribute 'default (selected-frame) :height
(+ (face-attribute 'default :height) (* (if (> n 0) 1 -1) 10))))
(global-set-key (kbd "C-+") '(lambda()(interactive(djcb-zoom 1))))
(global-set-key [C-kp-add] '(lambda()(interactive(djcb-zoom 1))))
(global-set-key (kbd "C--") '(lambda()(interactive(djcb-zoom -1))))
(global-set-key [C-kp-subtract] '(lambda()(interactive(djcb-zoom -1))))
(global-set-key [(control tab)] 'ffap)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; time-stamps
;; when there is a "Time-stamp: <>" in the first 10 lines of the file,
;; emacs will write time-stamp information there when saving the file.
;; see the top of this file for an example...
(setq
time-stamp-active t ; do enable time-stamps
time-stamp-line-limit 10 ; check first 10 buffer lines for Time-stamp: <>
time-stamp-format "%04y-%02m-%02d %02H:%02M:%02S (%u)") ; date format
(add-hook 'write-file-hooks 'time-stamp) ; update when saving
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; turn on autofill for all text-related modes
(toggle-text-mode-auto-fill)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Elisp
(defun djcb-emacs-lisp-mode-hook ()
(interactive)
;; overrides the global f7 for compilation
(local-set-key (kbd "<f7>") 'eval-buffer)
(set-input-method nil) ; i don't want accented chars, funny "a etc.
(setq lisp-indent-offset 2) ; indent with two spaces, enough for lisp
(font-lock-add-keywords nil
'(("\\<\\(FIXME\\|TODO\\|XXX+\\|BUG\\):"
1 font-lock-warning-face prepend)))
(font-lock-add-keywords nil
'(("\\<\\(require-maybe\\|add-hook\\|setq\\)"
1 font-lock-keyword-face prepend)))
(font-lock-add-keywords nil
'(("\\<use-package" . font-lock-keyword-face)))
;; (font-lock-add-keywords nil
;; '(("\\<use-package \\([[:word:]]*\\)" 1
;; font-lock-constant-face)))
(show-paren-mode 1)
(setq show-paren-style 'parenthesis)
(eldoc-mode 1))
(add-hook 'emacs-lisp-mode-hook 'djcb-emacs-lisp-mode-hook)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(message "Stop 3 %ds" (destructuring-bind (hi lo ms &rest ignore) (current-time)
(- (+ hi lo) (+ (first *emacs-load-start*) (second *emacs-load-start*)))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; backups (emacs will write backups and number them)
(setq make-backup-files t ; do make backups
backup-by-copying t ; and copy them ...
backup-directory-alist '(("." . "~/.emacs.d/backup/")) ; ... here
version-control t
kept-new-versions 2
kept-old-versions 5
delete-old-versions t)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Activar winner
(winner-mode 1)
;;;
; Colocar o text-mode como default ao abrir um ficheiro e fazer com que o o
; texto so tenha 78 caracteres de largura
(setq-default major-mode 'text-mode)
(setq fill-column 78)
(auto-fill-mode t)
(add-hook 'text-mode-hook 'turn-on-auto-fill)
;;;
; Indicar o tamanho do ficheiro
(size-indication-mode t)
;;;
;; W3m configurations
(use-package w3m
:load-path "elisp/emacs-w3m"
:commands (w3m w3m-browse-url)
:if (not (running-windows-p))
:config (progn
(setq browse-url-browser-function (lambda (url ignore)
(w3m-browse-url url t)))
(setq w3m-use-cookies t)
;; Mudar keybinding
(define-key w3m-mode-map "q" 'w3m-previous-buffer)
(define-key w3m-mode-map "w" 'w3m-next-buffer)
(define-key w3m-mode-map "x" 'w3m-delete-buffer)
;; Gravar sessions
;; (cond ((= emacs-major-version 22)
(use-package w3m-session
:init (progn
(setq w3m-session-file "~/.emacs.d/w3m-session")
(setq w3m-session-save-always t)
(setq w3m-session-load-always t)
(setq w3m-session-autosave-period 30)
(setq w3m-session-duplicate-tabs 'always)
;; Load last sessions
(setq w3m-session-load-last-sessions t)))
;; Utitilizar numeros para saltar para links
;; http://emacs.wordpress.com/2008/04/12/numbered-links-in-emacs-w3m/
;; (use-package w3m-lnum)
;; (defun jao-w3m-go-to-linknum ()
;; "Turn on link numbers and ask for one to go to."
;; (interactive)
;; (let ((active w3m-link-numbering-mode))
;; (when (not active) (w3m-link-numbering-mode))
;; (unwind-protect
;; (w3m-move-numbered-anchor (read-number "Anchor number: "))
;; (when (not active) (w3m-link-numbering-mode)))))
;; (define-key w3m-mode-map "f" 'jao-w3m-go-to-linknum)
;; Use "M" to open a link in the external browser
;; Use sessions on w3m (from Emacs Wiki)
(define-key w3m-mode-map "S" 'w3m-session-save)
(define-key w3m-mode-map "L" 'w3m-session-load)
(define-key w3m-mode-map (kbd "C-j") 'w3m-search-new-session)
;; Download youtube video at point
(defun w3m-yt-view ()
"View a YouTube link with mplayer."
(interactive)
(let ((url (or (w3m-anchor) (w3m-image))))
(cond ((string-match "youtube" url)
(string-match "[^v]*v.\\([^&]*\\)" url)
(let* ((vid (match-string 1 url))
(info (with-temp-buffer
(w3m-retrieve
(format "http://www.youtube.com/get_video_info?video_id=%s"
vid))
(buffer-string))))
(string-match "&token=\\([^%]*\\)" info)
(let ((vurl (format "http://www.youtube.com/get_video?video_id=%s&t=%s=&fmt=18"
vid
(match-string 1 info))))
(start-process "mplayer" nil "mplayer" "-quiet" "-cache" " 8192"
(nth 5 (w3m-attributes vurl))))))
(t
(message "Not yt URL.")))))
))
;; ;Activar o AUCTeX
(use-package latex
:load-path "elpa/auctex-11.86/"
:init (progn
(setq TeX-save-query nil) ;;autosave before compiling
(setq TeX-PDF-mode t)
(setq TeX-auto-save t)
(setq TeX-parse-self t)
(setq-default TeX-master nil)
(use-package latex-units)
(use-package reftex
:config (setq reftex-plug-into-AUCTeX t)
:commands reftex-mode)
(use-package preview
:config (add-to-list 'preview-document-pt-list 8)))
:config (progn
(defun change-outline-keys ()
(local-set-key (kbd "<M-up>") 'outline-move-subtree-up)
(local-set-key (kbd "<M-down>") 'outline-move-subtree-down)
;; (local-set-key (kbd "C-d") 'outline-toggle-children)
)
(add-hook 'LaTeX-mode-hook 'change-outline-keys)
(add-hook 'LaTeX-mode-hook 'outline-minor-mode)
(add-hook 'LaTeX-mode-hook 'latex-math-mode)
(add-hook 'LaTeX-mode-hook 'flyspell-mode)
(setq outline-minor-mode-prefix "\C-c\C-o")
(add-hook 'LaTeX-mode-hook 'reftex-mode)
(add-hook 'LaTeX-mode-hook 'orgtbl-mode)
(setq LaTeX-math-abbrev-prefix "'")))
;;;;;
;; spellcheck in LaTex mode
(add-hook 'TeX-mode-hook 'flyspell-mode)
(add-hook 'bibtex-mode-hook 'flyspell-mode)
;;;;;
(message "Stop 4 %ds" (destructuring-bind (hi lo ms &rest ignore) (current-time)
(- (+ hi lo) (+ (first *emacs-load-start*) (second *emacs-load-start*)))))
; Dias do calendario traduzidos para PT
(setq calendar-date-style 'european)
(setq calendar-week-start-day 1
calendar-day-name-array
["Domingo" "Segunda" "Terça"
"Quarta" "Quinta" "Sexta" "Sábado"]
calendar-month-name-array
["Janeiro" "Fevereiro" "Março" "Abril"
"Maio" "Junho" "Julho" "Agosto" "Setembro"
"Outubro" "Novembro" "Dezembro"])
;;;;;
; Colocar o calendario mais bonito
(setq calendar-view-diary-initially-flag t
calendar-mark-diary-entries-flag t
diary-number-of-entries 7)
(add-hook 'diary-display-hook 'fancy-diary-display)
(add-hook 'today-visible-calendar-hook 'calendar-mark-today)
;;;;;
;; Fazer highline das palavras TODO e FIXME, entre outras
(use-package highlight-fixmes-mode
:commands highlight-fixmes-mode)
;; FIXME: Add this to programming hooks
;(highlight-fixmes-mode t)
;;;
;; Show line-number and column-number in the mode line
(line-number-mode 1)
(column-number-mode 1)
;;;;;
;; Activar font-lock mode para todos os buffers
(global-font-lock-mode 1)
;;;;;
;; ============================
;; Setup syntax, background, and foreground coloring
;; ============================
(setq font-lock-maximum-decoration t)
;;;;;
;; ============================
;; ============================
;; Key mappings
;; ============================
;; use F1 key to go to a man page
(global-set-key [f1] 'man)
;; use F3 key to kill current buffer
(global-set-key [f3] 'kill-this-buffer)
;; use F5 to get help (apropos)
(global-set-key [f5] 'apropos)
;; use F6 to kill current buffer and window
(global-set-key [f6] 'kill-buffer-and-window)
;; ============================
;; ============================
;; Mouse Settings
;; ============================
;; mouse button one drags the scroll bar
(global-set-key [vertical-scroll-bar down-mouse-1] 'scroll-bar-drag)
;; ============================
;; ============================
;; DisplaY
;; ============================
;; setup font
;; This ones don't work on Windows
(if (not (running-windows-p))
(if (>= emacs-major-version 23)
;(set-default-font "Bitstream Vera Sans Mono-12")
(set-frame-font "Inconsolata 16")
(set-frame-font
"-adobe-courier-medium-r-normal-*-14-100-*-*-*-*-iso10646-1"))
(set-frame-font "-outline-Consolas-normal-r-normal-normal-14-97-96-96-c-*-iso8859-1"))
; Mostrar linhas lado esquerdo
(add-hook 'emacs-lisp-mode-hook 'nlinum-mode)
(add-hook 'python-mode-hook 'nlinum-mode)
(add-hook 'haskell-mode-hook 'nlinum-mode)
(global-set-key (kbd "<f2>") 'nlinum-mode)
;;;
(message "Stop 5 %ds" (destructuring-bind (hi lo ms &rest ignore) (current-time)
(- (+ hi lo) (+ (first *emacs-load-start*) (second *emacs-load-start*)))))
;; display the current time
(setq display-time-24hr-format t)
(display-time)
;; alias y to yes and n to no
(defalias 'yes-or-no-p 'y-or-n-p)
;; highlight matches from searches
(setq isearch-highlight t
search-highlight t)
(setq-default transient-mark-mode t)
;; Cursor should not blink
(when (fboundp 'blink-cursor-mode)
(blink-cursor-mode -1))
;; ===========================
;; ===========================
;; Behaviour
;; ===========================
; See the commands I'm writing
(setq echo-keystrokes 0.1)
;; Pgup/dn will return exactly to the starting point.
(setq scroll-preserve-screen-position 1)
;Define mnemonic key bindings for moving to 'M-x compile' and 'M-x grep' matches
(global-set-key "\C-cn" 'next-error)
(global-set-key "\C-cp" 'previous-error)
; Don't bother entering search and replace args if the buffer is read-only
(defadvice query-replace-read-args (before barf-if-buffer-read-only activate)
"Signal a 'buffer-read-only' error if the current buffer is read-only."
(barf-if-buffer-read-only))
;; scroll just one line when hitting the bottom of the window
(setq scroll-step 1)
(setq scroll-conservatively 1)
;; show a menu only when running within X (save real estate when
;; in console)
;(menu-bar-mode (if window-system 1 -1))
;; resize the mini-buffer when necessary
(setq resize-minibuffer-mode t)
;; highlight during searching
(setq query-replace-highlight t)
;; ===============================
;; ===========================
;; HTML/CSS stuff
;; ===========================
;; take any buffer and turn it into an html file,
;; including syntax hightlighting
(use-package htmlize
:commands (htmlize-buffer))
;; ===========================
;; ===========================
;; Custom Functions
;; ===========================
; resize man page to take up whole screen
(setq Man-notify 'bully)
;;
; SSH, etc.
(require 'tramp)
(setq tramp-default-method "telnet")
(setq tramp-debug-buffer t)
(setq tramp-verbose 10)
; host + user > proxy
;; (add-to-list 'tramp-default-proxies-alist
;; '("\\." nil "/telnet:ei08150@tcpgate.fe.up.pt:"))
;; (add-to-list 'tramp-default-proxies-alist
;; '("\\.riff\\.fe\\.up\\.pt\\'" nil nil))
; Aceder ao site da sapo
(setenv "SITE" "/ftp:rolando.do.sapo.pt@ftp.homepages.sapo.pt:~")
;;
;; Put autosave files (ie #foo#) in one place, *not*
;; scattered all over the file system!
(defvar autosave-dir
(concat "~/.emacs.d/autosaves/" (user-login-name) "/"))
(make-directory autosave-dir t)
(message "Stop 6 %ds" (destructuring-bind (hi lo ms &rest ignore) (current-time)
(- (+ hi lo) (+ (first *emacs-load-start*) (second *emacs-load-start*)))))
(defun auto-save-file-name-p (filename)
(string-match "^#.*#$" (file-name-nondirectory filename)))
(defun make-auto-save-file-name ()
(concat autosave-dir
(if buffer-file-name
(concat "#" (file-name-nondirectory buffer-file-name) "#")
(expand-file-name
(concat "#%" (buffer-name) "#")))))
;; Put backup files (ie foo~) in one place too. (The backup-directory-alist
;; list contains regexp=>directory mappings; filenames matching a regexp are
;; backed up in the corresponding directory. Emacs will mkdir it if necessary.)
(defvar backup-dir (concat "~/.emacs.d/backups/" (user-login-name) "/"))
(setq backup-directory-alist (list (cons "." backup-dir)))
;; Auto-Completation on files
;; http://emacs-fu.blogspot.com/2009/02/switching-buffers.html
(ido-mode t) ; for both buffers and files
(setq
ido-ignore-buffers ; ignore these guys
'("\\` " "^\*Mess" "^\*Back" ".*Completion" "^\*Ido" "\*scratch\*" "^\*w3m" "^irc\."
"\*slime-events\*" "\*slime-events\*" "\*gnus trace\*"
"\*n?n?imap" "\*slime-compilation\*" "newsrc")
; ido-work-directory-list '("~/" "~/Desktop")
ido-case-fold t ; be case-insensitive
; ido-use-filename-at-point nil ; don't use filename at point (annoying)
; ido-use-url-at-point nil ; don't use url at point (annoying)
ido-enable-flex-matching t ; be flexible
; ido-max-prospects 10 ; don't spam my minibuffer
; ido-confirm-unique-completion t ; wait for RET, even with unique completion
ido-create-new-buffer 'always) ; I'm always creating new buffers
; Saltar para onde se estava quando abrir um ficheiro
(use-package saveplace
:init (setq-default save-place t))
;;;;;
; Cursor do rato nao cobre o texto
(mouse-avoidance-mode 'jump)
;;;;;
; Yasnippet
;; (add-to-list 'load-path (concat +dot-emacs-home+ "plugins/yasnippet"))
(use-package yasnippet
:disabled t
:init (progn
(setq yas-snippet-dirs (list
(concat +dot-emacs-home+ "plugins/yasnippet/snippets")
(concat +dot-emacs-home+ "plugins/yasnippet/extras/imported/")))
(yas-global-mode 1)))
;;;;;
;; Remove splash screen
(setq inhibit-splash-screen t)
;;;
;; Detaching the custom-file
;; http://www.emacsblog.org/2008/12/06/quick-tip-detaching-the-custom-file/
(setq custom-file "~/.emacs.d/custom.el")
(load custom-file 'noerror)
;;;
(defun djcb-term-start-or-switch (prg &optional use-existing)
"* run program PRG in a terminal buffer. If USE-EXISTING is non-nil
and PRG is already running, switch to that buffer instead of starting
a new instance."
(interactive)
(let ((bufname (concat "*" prg "*")))
(when (not (and use-existing
(let ((buf (get-buffer bufname)))
(and buf (buffer-name (switch-to-buffer bufname))))))
(ansi-term prg prg))))
(defmacro djcb-program-shortcut (name key &optional use-existing)
"* macro to create a key binding KEY to start some terminal program PRG;
if USE-EXISTING is true, try to switch to an existing buffer"
`(global-set-key ,key
'(lambda()
(interactive)
(djcb-term-start-or-switch ,name ,use-existing))))
;; terminal programs are under Shift + Function Key
(djcb-program-shortcut "zsh" (kbd "<S-f1>") t) ; the ubershell
(djcb-program-shortcut "mutt" (kbd "<S-f2>") t) ; mail client
(djcb-program-shortcut "slrn" (kbd "<S-f3>") t) ; nttp client
(djcb-program-shortcut "htop" (kbd "<S-f4>") t) ; my processes
(djcb-program-shortcut "mc" (kbd "<S-f5>") t) ; midnight commander
(djcb-program-shortcut "raggle"(kbd "<S-f6>") t) ; rss feed reader
(djcb-program-shortcut "irssi" (kbd "<S-f7>") t) ; irc client
(djcb-program-shortcut "tt++ " (kbd "<S-f8>") t) ; MUD client
;;;;;;;;
(message "Stop 7 %ds" (destructuring-bind (hi lo ms &rest ignore) (current-time)
(- (+ hi lo) (+ (first *emacs-load-start*) (second *emacs-load-start*)))))
;; Move between windows using Meta+arrow keys
;; http://www.emacsblog.org/2008/05/01/quick-tip-easier-window-switching-in-emacs/
(windmove-default-keybindings 'meta)
;;
(message "Stop 8 %ds" (destructuring-bind (hi lo ms &rest ignore) (current-time)
(- (+ hi lo) (+ (first *emacs-load-start*) (second *emacs-load-start*)))))
;; Load bookmarks
;; http://www.emacsblog.org/2007/03/22/bookmark-mania/
(use-package bm
:init (progn
(setq bm-restore-repository-on-load t)
;; make bookmarks persistent as default
(setq-default bm-buffer-persistence t)
;; Loading the repository from file when on start up.
(add-hook' after-init-hook 'bm-repository-load)
;; Restoring bookmarks when on file find.
(add-hook 'find-file-hooks 'bm-buffer-restore)
;; Saving bookmark data on killing a buffer
(add-hook 'kill-buffer-hook 'bm-buffer-save)
;; Saving the repository to file when on exit.
;; kill-buffer-hook is not called when emacs is killed, so we
;; must save all bookmarks first.
(add-hook 'kill-emacs-hook '(lambda nil
(bm-buffer-save-all)
(bm-repository-save)))
(global-set-key (kbd "<C-f4>") 'bm-toggle)
(global-set-key (kbd "<f4>") 'bm-next)
(global-set-key (kbd "<S-f4>") 'bm-previous)
))
(message "Stop 9 %ds" (destructuring-bind (hi lo ms &rest ignore) (current-time)
(- (+ hi lo) (+ (first *emacs-load-start*) (second *emacs-load-start*)))))
;;;;;;;;;;;;;
;; Need to find some keybindings for the laptop
(require 'fold-dwim)
(if (running-on-laptop-p)
(progn
(global-set-key [(C J)] 'fold-dwim-hide-all)
(global-set-key [(C K)] 'fold-dwim-toggle)
(global-set-key [(C L)] 'fold-dwim-show-all))
;; On the numpad
(global-set-key [(C kp-left)] 'fold-dwim-hide-all) ; Key 4
(global-set-key [(C kp-begin)] 'fold-dwim-toggle) ; Key 5
(global-set-key [(C kp-right)] 'fold-dwim-show-all)) ; Key 6
;; % works the same as vim
;; http://mewde.blogspot.com/2007_05_01_archive.html
(global-set-key "%" 'match-paren)
(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)))))
;;;;;
;; A little game to help learn the keybindings
;; http://mewde.blogspot.com/2007_05_01_archive.html
(use-package keywiz
:commands keywiz)
;;
;; ;; Scheme Mode
;; (defun rolando-scheme-send-whole-buffer ()
;; "Sends the entire buffer to the inferior scheme process"
;; (interactive)
;; (save-excursion
;; (set-buffer "*scheme*")
;; (erase-buffer)
;; (save-excursion
;; (scheme-send-region (point-min) (point-max))
;; (if (get-buffer-window "*scheme*")
;; (display-buffer "*scheme*" t))
;; (unless (get-buffer-window "*scheme*")
;; (split-window-vertically)
;; (windmove-do-window-select 'down)
;; (set-window-buffer (selected-window) "*scheme*")))))
;; (defun rolando-scheme-mode-hook ()
;; (interactive)
;; (local-set-key (kbd "C-t") 'rolando-scheme-send-whole-buffer))
;; (add-hook 'scheme-mode-hook 'rolando-scheme-mode-hook)
;; ;;;;
;; F20 = Right Windows key
;; use "xmodmap -e 'keycode 133 = F20'" to set it
(defun rolando-switch-buffer ()
"Alternates buffers like GNU Screen and Ratpoison"
(interactive)
(switch-to-buffer (other-buffer)))
(global-set-key [f20] 'rolando-switch-buffer)
;;
(defun rolando-complete-python-symbol (symbol)
"Show the documentation for the python symbol on the cursor on a resized frame"
(interactive)
;; (interactive
;; (let ((symbol (with-syntax-table python-dotty-syntax-table
;; (current-word)))
;; (enable-recursive-minibuffers t))
;; (list (read-string (if symbol
;; (format "Describe symbol (default %s): " symbol)
;; "Describe symbol: ")
;; nil nil symbol))))
;; Usar o fit-window-to-buffer, display-buffer
(let ((name "*Python Documentation*"))
(save-excursion
;;(python-describe-symbol symbol) ; Cria um buffer com o nome *Help*
(get-buffer-create name)
(set-buffer name)