-
Notifications
You must be signed in to change notification settings - Fork 0
/
emacs.init.el
1680 lines (1432 loc) · 58.3 KB
/
emacs.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
;; Package repositories
(require 'package)
;;(package-initialize)
(setq package-archives '(("gnu" . "http://elpa.gnu.org/packages/")
;; ("marmalade" . "http://marmalade-repo.org/packages/")
("elpa" . "http://tromey.com/elpa/")
("melpa" . "http://melpa.org/packages/")))
;; From babcore, http://draketo.de/light/english/emacs/babcore
;; Make sure a package is installed
(defun package-require (package)
"Install a PACKAGE unless it is already installed
or a feature with the same name is already active.
Usage: (package-require 'package)"
; try to activate the package with at least version 0.
(package-activate package '(0))
; try to just require the package. Maybe the user has it in his local config
(condition-case nil
(require package)
; if we cannot require it, it does not exist, yet. So install it.
(error (package-install package))))
;; from http://cestlaz.github.io/posts/using-emacs-1-setup/
;; Bootstrap `use-package'
(unless (package-installed-p 'use-package)
(package-refresh-contents)
(package-install 'use-package))
(use-package try
:ensure t)
(use-package which-key
:ensure t
:config
(which-key-mode))
;; from http://cestlaz.github.io/posts/using-emacs-19-live
;; create a function for loading file only if it is available
;; good for defining specific configurations for every computer
(defun load-if-exists (f)
""
(if (file-readable-p f)
load-file f))
;; To customize the Welcome Message when loading Emacs
(setq initial-scratch-message "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\nHi augusto.
% Help choose theme
M-x customize-themes
% Repeat, negative argument
C-u, C-5 (etc), C--
% Getting help
C-h i (manual), C-h a (apropos), C-h m (describe-mode)
% Moving
M-m (moves to first non-whitespace character)
C-M-f, C-M-b (by sexp, balanced expressions)
C-M-d, C-M-u (down and up list)
C-M-n, C-M-p (next and previous list)
C-M-k (kill-sexp)
C-M-a, C-M-e (begin and end of defun)
M-{, M-} (start and end of paragraph)
M-g M-n, M-g M-p (jump to next/previous error)
% Kill C-M-k (kill sexp) C-M-w (append kill to kill ring)
% Transposing
C-t, M-t, C-M-t, C-x C-t (transpose character, word, sexp, lines)
% Filling and commenting
C-x f (sets the fill column width)
M-; and C-x C-; (comment/uncomment)
M-j, C-M j (insert new line with comment)
% Setting marks
M-h (marks next paragraph), M-@ (marks next word)
C-x h (marks entire buffer), C-M-h (marks defun)
C-M-<space> (marks by sexp)
% Search
C-M-s, C-M-r (by regexp)
M-x imenu
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
")
;; To adjust the size of the window when starting emacs
(if (window-system) (set-frame-size (selected-frame) 108 33))
;; to adjust the position of the window when starting emacs
(setq initial-frame-alist '((top . 30) (left . 90)))
;; Don't display the 'Welcome to GNU Emacs' buffer on startup
(setq inhibit-startup-message t)
;; Display on frame title the name of the file, host and some information
(setq frame-title-format
'("emacs%@" (:eval (system-name)) ": " (:eval (if (buffer-file-name)
(abbreviate-file-name (buffer-file-name))
"%b")) " [%*]"))
;; remove toolbar
(tool-bar-mode -1)
;; disable to scroll bar
(scroll-bar-mode -1)
;; save/restore opened files and windows config
(desktop-save-mode 1) ; 0 for off
;; ordering relevant results with apropos
(setq apropos-sort-by-scores t)
;; Sublimity mode (M-x sublimity-mode)
;; smooth-scrolling, minimap and distraction-free mode
;; For customization: https://github.com/zk-phi/sublimity
(require 'sublimity)
(require 'sublimity-scroll)
;(require 'sublimity-map)
(require 'sublimity-attractive)
;; Load it by default
(sublimity-mode 1)
;; minimap
;(setq sublimity-map-size 20)
;(setq sublimity-map-fraction 0.3)
;(setq sublimity-map-text-scale -7)
;(add-hook 'sublimity-map-setup-hook
; (lambda ()
; (setq buffer-face-mode-face '(:family "Monospace"))
; (buffer-face-mode)))
;(sublimity-map-set-delay 5)
;; distraction-free
;;(sublimity-attractive-hide-bars)
(sublimity-attractive-hide-vertical-border)
(sublimity-attractive-hide-fringes)
;;(sublimity-attractive-hide-modelines)
;; To help find the cursor
(beacon-mode 1)
(setq beacon-push-mark 35)
(setq beacon-color "#666600")
;; Highlighting indentation (minor mode)
;; To activate: highlight-indentation-mode or highlight-indentation-current-column-mode
;; To customize colors:
(highlight-indentation-mode 1)
(set-face-background 'highlight-indentation-face "#e3e3d3")
(set-face-background 'highlight-indentation-current-column-face "#c3b3b3")
;; To enable Focus mode:
;; M-x focus-mode
;; Or, to initialize by default:
;; (focus-mode 1)
;; make cursor the width of the character it is under
;; i.e. full width of a TAB
(setq x-stretch-cursor t)
;; keep a list of recently opened files, available using F7
(recentf-mode 1)
(global-set-key (kbd "<f7>") 'recentf-open-files)
;; Flymake: on the fly syntax checking
; stronger error display
(defface flymake-message-face
'((((class color) (background light)) (:foreground "#b2dfff"))
(((class color) (background dark)) (:foreground "#b2dfff")))
"Flymake message face")
; show the flymake errors in the minibuffer
(package-require 'flymake-cursor)
;; To activate COPY from Emacs to other applications
; Not necessary anymore, for Emacs 24.4
;(setq x-select-enable-clipboard t)
;; for having small hints when using TAB for completion
(custom-set-variables
'(icomplete-mode t))
;; To use Semantic, with M-x semantic
;; It should provide useful context options
(eval-after-load "semantic"
'(progn
(add-to-list 'semantic-default-submodes
'global-semantic-decoration-mode)
(add-to-list 'semantic-default-submodes
'global-semantic-idle-summary-mode)
(add-to-list 'semantic-default-submodes
'global-semantic-idle-local-symbol-highlight-mode)
(add-to-list 'semantic-default-submodes
'global-semantic-mru-bookmark-mode)))
;; For using auto-completion features
(when (ignore-errors (require 'auto-complete-config nil t))
(ac-config-default)
(ac-flyspell-workaround)
(eval-after-load "semantic"
'(setq-default ac-sources
(cons 'ac-source-semantic ac-sources))))
;; Inline auto completion and suggestions
; I am not using package auto-complete anymore
; replace by company-mode
;(use-package auto-complete
; :ensure t
; :init
; (progn
; (ac-config-default)
; (global-auto-complete-mode t)
; ))
;; to have a smart C-a navigation
(defun smarter-move-beginning-of-line (arg)
"Move point back to indentation of beginning of line.
Move point to the first non-whitespace character on this line.
If point is already there, move to the beginning of the line.
Effectively toggle between the first non-whitespace character and
the beginning of the line.
If ARG is not nil or 1, move forward ARG - 1 lines first. If
point reaches the beginning or end of the buffer, stop there."
(interactive "^p")
(setq arg (or arg 1))
;; Move lines first
(when (/= arg 1)
(let ((line-move-visual nil))
(forward-line (1- arg))))
(let ((orig-point (point)))
(back-to-indentation)
(when (= orig-point (point))
(move-beginning-of-line 1))))
;; remap C-a to `smarter-move-beginning-of-line'
(global-set-key [remap move-beginning-of-line]
'smarter-move-beginning-of-line)
;; defining C-x C-u as undo (same as C-x u). It was upcase-region.
(define-key global-map "\C-x\C-u" 'undo)
;; undo-tree-mode
;; turn on everywhere
;; use C-x u to see the three
;;(global-undo-tree-mode 1)
;; make ctrl-z undo
(global-set-key (kbd "C-z") 'undo)
;; make ctrl-Z redo
(defalias 'redo 'undo-tree-redo)
(global-set-key (kbd "C-S-z") 'redo)
;; C-x u for a neat tree visualization; q for change and C-q for quit
;; Seeing color values
; M-x list-colors-display
;; Turn on font-lock mode to color text in certain modes
(global-font-lock-mode t)
;; Show line and column position of cursor
(column-number-mode 1)
;; Make sure spaces are used when indenting code
(setq-default indent-tabs-mode nil)
;; Using single space after dots to define the end of sentences
(setq sentence-end-double-space nil)
;; makes backspace and C-d erase all consecutive white space
;; (instead of just one)
(require 'hungry-delete)
(global-hungry-delete-mode)
;; use allout minor mode to have outlining everywhere.
(allout-mode)
;; Add proper word wrapping
(global-visual-line-mode t)
;; C-home goes to the start, C-end goes to the end of the file
(global-set-key (kbd "<C-home>")
(lambda()(interactive)(goto-char(point-min))))
(global-set-key (kbd "<C-end>")
(lambda()(interactive)(goto-char(point-max))))
;; Go to the last change
;; Super-cool!
(require 'goto-chg)
(global-set-key (kbd "C-c C-,") 'goto-last-change)
(global-set-key (kbd "C-c C-.") 'goto-last-change-reverse)
;; save cursor position between sessions
(require 'saveplace)
(setq-default save-place t)
;; make all "yes or no" prompts show "y or n" instead
(fset 'yes-or-no-p 'y-or-n-p)
;; Smooth scrolling
(require 'smooth-scroll)
(smooth-scroll-mode t)
;; To keep the point in a fixed position while scrolling
;; not necessary anymore because ivy already does it
;(global-set-key (kbd "M-n") (kbd "C-u 1 C-v"))
;(global-set-key (kbd "M-p") (kbd "C-u 1 M-v"))
;; To browse the kill-ring with C-c k
;removed to use helm for this task
;(require 'browse-kill-ring)
;(require 'browse-kill-ring+)
;(global-set-key (kbd "C-c k") 'browse-kill-ring)
;; To swap two windows using C-c s
(defun swap-windows ()
"If you have 2 windows, it swaps them."
(interactive)
(cond ((/= (count-windows) 2)
(message "You need exactly 2 windows to do this."))
(t
(let* ((w1 (first (window-list)))
(w2 (second (window-list)))
(b1 (window-buffer w1))
(b2 (window-buffer w2))
(s1 (window-start w1))
(s2 (window-start w2)))
(set-window-buffer w1 b2)
(set-window-buffer w2 b1)
(set-window-start w1 s2)
(set-window-start w2 s1))))
(other-window 1))
(global-set-key (kbd "C-c s") 'swap-windows)
;; Toggles between horizontal and vertical layout of two windows
(defun toggle-window-split ()
(interactive)
(if (= (count-windows) 2)
(let* ((this-win-buffer (window-buffer))
(next-win-buffer (window-buffer (next-window)))
(this-win-edges (window-edges (selected-window)))
(next-win-edges (window-edges (next-window)))
(this-win-2nd (not (and (<= (car this-win-edges)
(car next-win-edges))
(<= (cadr this-win-edges)
(cadr next-win-edges)))))
(splitter
(if (= (car this-win-edges)
(car (window-edges (next-window))))
'split-window-horizontally
'split-window-vertically)))
(delete-other-windows)
(let ((first-win (selected-window)))
(funcall splitter)
(if this-win-2nd (other-window 1))
(set-window-buffer (selected-window) this-win-buffer)
(set-window-buffer (next-window) next-win-buffer)
(select-window first-win)
(if this-win-2nd (other-window 1))))))
(global-set-key (kbd "C-c m") 'toggle-window-split)
;; use control + arrow keys to switch between visible buffers
;(require 'windmove)
;(windmove-default-keybindings 'control) ;; will be overridden
;(global-set-key (kbd "<C-s-left>") 'windmove-left)
;(global-set-key (kbd "<C-s-right>") 'windmove-right)
;(global-set-key (kbd "<C-s-up>") 'windmove-up)
;(global-set-key (kbd "<C-s-down>") 'windmove-down)
;; to activate winner mode - restore window configurations
;; usage: C-c left, C-c right
(when (fboundp 'winner-mode)
(winner-mode 1))
;; to setup ace-window, to easily navigate between windows
(use-package ace-window
:ensure t
:init
(progn
(global-set-key [remap other-window] 'ace-window)
(custom-set-faces
'(aw-leading-char-face
((t (:inherit ace-jump-face-foreground :height 3.0)))))
))
(setq aw-keys '(?a ?s ?d ?f ?g ?h ?j ?k ?l))
; old configuration
;(global-set-key (kbd "C-c w") 'ace-window)
;; For searching and replacing
(setq search-highlight t ;; highlight when searching...
query-replace-highlight t) ;; ...and replacing
(setq completion-ignore-case t ;; ignore case when completing...
read-file-name-completion-ignore-case t) ;; ...filenames too
;; Slick-copy: make copy-past a bit more intelligent
;; from: http://www.emacswiki.org/emacs/SlickCopy
;; Supercool!
;; ‘M-w’ copies the current line when the region is not active, and
;; ‘C-w’ deletes it.
(defadvice kill-ring-save (before slick-copy activate compile)
"When called interactively with no active region, copy a single
line instead."
(interactive
(if mark-active (list (region-beginning) (region-end))
(message "Copied line")
(list (line-beginning-position)
(line-beginning-position 2)))))
(defadvice kill-region (before slick-cut activate compile)
"When called interactively with no active region, kill a single
line instead."
(interactive
(if mark-active (list (region-beginning) (region-end))
(list (line-beginning-position)
(line-beginning-position 2)))))
;; key board / input method settings
(setq locale-coding-system 'utf-8)
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(set-selection-coding-system 'utf-8)
(prefer-coding-system 'utf-8)
(set-language-environment "UTF-8") ; prefer utf-8 for language settings
(set-input-method nil) ; no funky input for normal editing;
(setq read-quoted-char-radix 10) ; use decimal, not octal
;; global keybindings
;(global-set-key (kbd "RET") 'newline-and-indent)
;; Move more quickly, 5 lines or chars at a time
;; It works with capslock with usual commands
(global-set-key (kbd "C-S-n")
(lambda ()
(interactive)
(ignore-errors (next-line 5))))
(global-set-key (kbd "C-S-p")
(lambda ()
(interactive)
(ignore-errors (previous-line 5))))
(global-set-key (kbd "C-S-f")
(lambda ()
(interactive)
(ignore-errors (forward-char 5))))
(global-set-key (kbd "C-S-b")
(lambda ()
(interactive)
(ignore-errors (backward-char 5))))
;; To show line numbers when using M-x goto-line-with-feedback
;; It should be very useful when finding errors
(global-set-key [remap goto-line] 'goto-line-with-feedback)
(defun goto-line-with-feedback ()
"Show line numbers temporarily, while prompting for the line number input"
(interactive)
(unwind-protect
(progn
(linum-mode 1)
(goto-line (read-number "Goto line: ")))
(linum-mode -1)))
(defalias 'gl 'goto-line)
;; Moving by blocks
;; From ergoemacs
;; http://ergoemacs.org/emacs/emacs_move_by_paragraph.html
(defun ergoemacs-forward-block ()
"Move cursor forward to the beginning of next text block.
A text block is separated by 2 empty lines (or line with just
whitespace). In most major modes, this is similar to
`forward-paragraph', but this command's behavior is the same
regardless of syntax table."
(interactive)
(if (search-forward-regexp "\n[[:blank:]\n]*\n+" nil "NOERROR")
(progn (backward-char))
(progn (goto-char (point-max)) )
)
)
(defun ergoemacs-backward-block ()
"Move cursor backward to previous text block.
See: `ergoemacs-forward-block'"
(interactive)
(if (search-backward-regexp "\n[\t\n ]*\n+" nil "NOERROR")
(progn
(skip-chars-backward "\n\t ")
(forward-char 1)
)
(progn (goto-char (point-min)) )
)
)
(global-set-key (kbd "<prior>") 'ergoemacs-backward-block)
(global-set-key (kbd "<next>") 'ergoemacs-forward-block)
;; Binding for dynamic abbreviations (dabbrev)
;; It is super-cool! It also cycles around words
(global-set-key (kbd "C-<tab>") 'dabbrev-expand)
(define-key minibuffer-local-map (kbd "C-<tab>") 'dabbrev-expand)
;; allowing indentations when writing codes in certain modes
(electric-indent-mode +1)
;; Word count in selected region
(defun count-words-region ()
(interactive)
(message "Word count: %s" (how-many "\\w+" (point) (mark))))
;; Enable narrowing the selected region
;; Usage: In: C-x n n Out: C-x n w
(put 'narrow-to-region 'disabled nil)
;; Unfill paragraph and region
(defun unfill-paragraph ()
"Replace newline chars in current paragraph by single spaces.
This command does the inverse of `fill-paragraph'."
(interactive)
(let ((fill-column 90002000)) ; 90002000 is just random. you can use `most-positive-fixnum'
(fill-paragraph nil)))
(defun unfill-region (start end)
"Replace newline chars in region by single spaces.
This command does the inverse of `fill-region'."
(interactive "r")
(let ((fill-column 90002000))
(fill-region start end)))
;; company: to "complete anything"
;; to be available in all major-modes
(add-hook 'after-init-hook 'global-company-mode)
;; company with auctex
(require 'company-auctex)
(company-auctex-init)
;; company-statistics
(require 'company-statistics)
(company-statistics-mode)
;; to use flycheck, for syntax check in many languages, such as R
(use-package flycheck
:ensure t
:init
(global-flycheck-mode t))
;;YASnippet
(use-package yasnippet
:ensure t
:init
(yas-global-mode 1))
;; expand the marked region in semantic increments (negative prefix to reduce region)
(use-package expand-region
:ensure t
:config
(global-set-key (kbd "C-=") 'er/expand-region))
;; Treats CamelCase as distinct words
(subword-mode t)
;; Editing multiple words simultaneously
;; Select with C-; edit, then quit with C-;
(use-package iedit
:ensure t)
;; Defining a keybind for imenu - good for navigation
(global-set-key (kbd "M-i") 'imenu)
;; Adding a mode for html files
(use-package web-mode
:ensure t
:config
(add-to-list 'auto-mode-alist '("\\.html?\\'" . web-mode))
(setq web-mode-engines-alist
'(("django" . "\\.html\\'")))
(setq web-mode-ac-sources-alist
'(("css" . (ac-source-css-property))
("html" . (ac-source-words-in-buffer ac-source-abbrev)))))
(setq web-mode-enable-auto-closing t)
(setq web-mode-enable-current-element-highlight t)
(setq web-mode-enable-current-column-highlight t)
;; to use dead-keys for accents on some ubuntu distributions (problem with 16.04 on segovia)
(require 'iso-transl)
;; Trying to replace IDO mode with ivy mode, counsel and swiper
;; If I don't like it, just comment below and uncomment IDO configuration removing ";; "
(ivy-mode 1)
(setq ivy-use-virtual-buffers t)
(global-set-key (kbd "C-x b") 'ivy-switch-buffer)
(setq ivy-display-style 'fancy)
(global-set-key "\C-s" 'swiper)
(global-set-key "\C-r" 'swiper) ; see below if counsel-expression is better
(global-set-key (kbd "C-c C-r") 'ivy-resume)
(global-set-key (kbd "<f5>") 'ivy-resume)
(global-set-key (kbd "M-x") 'counsel-M-x)
(global-set-key (kbd "C-x C-f") 'counsel-find-file)
(global-set-key (kbd "<f1> f") 'counsel-describe-function)
(global-set-key (kbd "<f1> v") 'counsel-describe-variable)
(global-set-key (kbd "<f1> l") 'counsel-load-library)
(global-set-key (kbd "<f2> i") 'counsel-info-lookup-symbol)
(global-set-key (kbd "<f2> u") 'counsel-unicode-char)
(global-set-key (kbd "C-c g") 'counsel-git)
(global-set-key (kbd "C-c j") 'counsel-git-grep)
;(global-set-key (kbd "C-c k") 'counsel-ag) ;not working
(global-set-key (kbd "C-x l") 'counsel-locate)
(global-set-key (kbd "C-S-o") 'counsel-rhythmbox)
;(define-key read-expression-map (kbd "C-r") 'counsel-expression-history)
;;advise swiper to recenter on exit
(defun bjm-swiper-recenter (&rest args)
"recenter display after swiper"
(recenter)
)
(advice-add 'swiper :after #'bjm-swiper-recenter)
;; IDO mode, for autocompletion; use with C-x C-f
;; (ido-mode 1)
;; ;;(setq ido-enable-flex-matching t) ;not using this line
;; (custom-set-variables
;; '(ido-enable-flex-matching t)
;; '(ido-mode 'both)
;; '(ido-use-virtual-buffers t))
;; (setq ido-everywhere t) ;; to work on C-x C-f as well; with C-f is disabled
;; ;; when using ido, the confirmation is rather annoying...
;; (setq confirm-nonexistent-file-or-buffer nil)
;; ;; increase minibuffer size when ido completion is active
;; (add-hook 'ido-minibuffer-setup-hook
;; (function
;; (lambda ()
;; (make-local-variable 'resize-minibuffer-window-max-height)
;; (setq resize-minibuffer-window-max-height 1))))
;; A package with more options for dired
(require 'dired-details+)
;; To put deleted files on trash can
(setq delete-by-moving-to-trash t)
;;using the menu to define garbage files on dired
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(abbrev-mode t)
'(dired-garbage-files-regexp "\\(?:\\.\\(?:aux\\|bak\\|dvi\\|log\\|orig\\|rej\\|toc\\|snm\\|nav\\|out\\)\\)\\'"))
;; Backup and file versions
;; to save the backups on .emacs.d
(setq backup-directory-alist
`(("." . ,(concat user-emacs-directory "backup/")))
tramp-backup-directory-alist backup-directory-alist)
;; to keep some old versions of all files edited with Emacs
(setq delete-old-versions t
kept-new-versions 20
kept-old-versions 20
version-control t) ;;to also backup files under version control
;; Emacs 24.4 has a browser, eww
;; M-x eww
;; Minibuffer
;; I was using this configuration before 24.4,
;; but will try without them for a while
;; the minibuffer
;(setq
; enable-recursive-minibuffers nil ;; allow mb cmds in the mb
; max-mini-window-height .25 ;; max 2 lines
; minibuffer-scroll-window nil
; resize-mini-windows nil)
;; increase minibuffer size when ido completion is active
;(add-hook 'ido-minibuffer-setup-hook
; (function
; (lambda ()
; (make-local-variable 'resize-minibuffer-window-max-height)
; (setq resize-minibuffer-window-max-height 2))))
;; save minibuffer history
;; hint: a good way to type commands is C-r then a part of the command
(require 'savehist)
(savehist-mode t)
;; to use ibuffer with C-x C-b
;; this was replaced by helm-mini
;(global-set-key (kbd "C-x C-b") 'ibuffer)
;; uniquify: unique buffer names
(require 'uniquify) ;; make buffer names more unique
(setq
uniquify-buffer-name-style 'post-forward
uniquify-separator ":"
uniquify-after-kill-buffer-p t
uniquify-ignore-buffers-re "^\\*")
;; smex, for auto-complete on M-x
;(global-set-key (kbd "M-x") 'smex)
;(global-set-key (kbd "M-X") 'smex-major-mode-commands)
;; This is your old M-x.
;(global-set-key (kbd "C-c C-c M-x") 'execute-extended-command)
;; Find file at point
(defalias 'ff 'find-file-at-point)
;; Just type ~ to go home from ido-find-file
(add-hook 'ido-setup-hook
(lambda ()
;; Go straight home
(define-key ido-file-completion-map
(kbd "~")
(lambda ()
(interactive)
(if (looking-back "/")
(insert "~/")
(call-interactively 'self-insert-command))))))
;; Delete the file associated with the buffer, with C-c C-k
(defun delete-current-buffer-file ()
"Removes file connected to current buffer and kills buffer."
(interactive)
(let ((filename (buffer-file-name))
(buffer (current-buffer))
(name (buffer-name)))
(if (not (and filename (file-exists-p filename)))
(ido-kill-buffer)
(when (yes-or-no-p "Are you sure you want to remove this file? ")
(delete-file filename)
(kill-buffer buffer)
(message "File '%s' successfully removed" filename)))))
(global-set-key (kbd "C-x C-k") 'delete-current-buffer-file)
;; Rename the current buffer/file with C-x C-r
(defun rename-current-buffer-file ()
"Renames current buffer and file it is visiting."
(interactive)
(let ((name (buffer-name))
(filename (buffer-file-name)))
(if (not (and filename (file-exists-p filename)))
(error "Buffer '%s' is not visiting a file!" name)
(let ((new-name (read-file-name "New name: " filename)))
(if (get-buffer new-name)
(error "A buffer named '%s' already exists!" new-name)
(rename-file filename new-name 1)
(rename-buffer new-name)
(set-visited-file-name new-name)
(set-buffer-modified-p nil)
(message "File '%s' successfully renamed to '%s'"
name (file-name-nondirectory new-name)))))))
(global-set-key (kbd "C-x C-r") 'rename-current-buffer-file)
;; Auto refresh dired, without any message
(setq global-auto-revert-non-file-buffers t)
(setq auto-revert-verbose nil)
;; Search the web for words
(global-set-key (kbd "C-x g") 'webjump)
;; Add Urban Dictionary to webjump
(eval-after-load "webjump"
'(add-to-list 'webjump-sites
'("Urban Dictionary" .
[simple-query
"www.urbandictionary.com"
"http://www.urbandictionary.com/define.php?term="
""])))
;; For using avy mode, for faster navigation
(global-set-key (kbd "C-c j") 'avy-goto-word-or-subword-1)
(global-set-key (kbd "C-c c") 'avy-goto-char-timer)
;; Prettier text replacement with anzu
(global-anzu-mode +1)
(global-set-key (kbd "M-%") 'anzu-query-replace)
(global-set-key (kbd "C-M-%") 'anzu-query-replace-regexp)
;; Enabling helm, for better search
(require 'helm)
(require 'helm-config)
;(helm-mode 1)
(global-set-key (kbd "C-x C-b") 'helm-mini) ;for better buffer list
(global-set-key (kbd "M-y") 'helm-show-kill-ring)
(global-set-key (kbd "C-c k") 'helm-show-kill-ring)
(global-set-key (kbd "C-x r b") 'helm-bookmarks)
(defalias 'sb 'helm-bookmarks)
;; Hidding password when prompted in shell mode inside Emacs
(add-hook 'comint-output-filter-functions
'comint-watch-for-password-prompt)
;; To use colours when in M-x shell
(autoload 'ansi-color-for-comint-mode-on "ansi-color" nil t)
(add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on)
;; colored shell commands via C-!
(add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on)
(defun babcore-shell-execute(cmd)
"Execute a shell command in an interactive shell buffer."
(interactive "sShell command: ")
(shell (get-buffer-create "*shell-commands-buf*"))
(process-send-string (get-buffer-process "*shell-commands-buf*") (concat cmd "\n")))
(global-set-key (kbd "C-!") 'babcore-shell-execute)
;; better-shell package https://github.com/killdash9/better-shell
;; specially useful for open a shell on a remote server
(use-package better-shell
:ensure t
:bind (("C-'" . better-shell-shell)
("C-;" . better-shell-remote-open)))
;; useful ones
(defalias 'eb 'eval-buffer)
(defalias 'er 'eval-region)
(defalias 'ms 'magit-status)
(defalias 'tm 'git-timemachine)
(defalias 'lm 'linum-mode)
;; shortcut to open file .emacs
(defun dotemacs ()
(interactive)
(find-file "~/.emacs")
)
;; shortcut to open file emacs.init.org
(defun init ()
(interactive)
(find-file "~/[email protected]/emacs/dotemacs/emacs.init.org")
)
;; A function to "refresh" the buffer without asking confirmation
(defun my-revert-buffer()
"revert buffer without asking for confirmation"
(interactive "")
(revert-buffer t t)
)
;; a shortcut to use the function
(defalias 'ref 'my-revert-buffer)
;; To count words on region
(defalias 'cw 'count-words-region)
;; Reminders:
;; Use C-M-\ to indent code
;; Use C-h v to have information about what the function does
;; TRAMP: support multiprotocols, including ssh
;; to avoid problems with characters sent by the server:
;(custom-set-variables
; '(tramp-shell-prompt-pattern
; "v\\(?:^\\|
;\\)[^]#$%>\n]*#?[]#$%>] *\\(;?\\[[0-9;]*[a-zA-Z] *\\)*"))
;; All tramp connections follow the sintax below, after typing C-x C-f
;; Notice that if .authinfo.gpg is configured, one does not need to type passwords
;; /protocol:[user@]hostname[#port]:
;; For multiple hops, jumping to oboe using maestro as the initial destination
(require 'tramp)
(add-to-list 'tramp-default-proxies-alist
'("oboe" nil "/ssh:augusto@maestro:"))
;; To edit files as sudo without needing to use tramp/sudo first
;; Just use C-x F
;; From http://emacs-fu.blogspot.com.br/2013/03/editing-with-root-privileges-once-more.html
(defun find-file-as-root ()
"Like `ido-find-file, but automatically edit the file with
root-privileges (using tramp/sudo), if the file is not writable by
user."
(interactive)
(let ((file (ido-read-file-name "Edit as root: ")))
(unless (file-writable-p file)
(setq file (concat "/sudo:root@localhost:" file)))
(find-file file)))
;; or some other keybinding...
(global-set-key (kbd "C-x F") 'find-file-as-root)
;; tbemail.el --- Provide syntax highlighting for email editing via
;; Thunderbird's "External Editor" extension.
;; see: http://globs.org/articles.php?lng=en&pg=2&id=2
(require 'tbemail)
;; (add-to-list 'load-path "/usr/share/emacs24/site-lisp/mu4e")
;; (require 'mu4e)
;;default
;;(setq mu4e-maildir "~/Maildir")
;; (setq mu4e-drafts-folder "/[Gmail].Drafts")
;; (setq mu4e-sent-folder "/[Gmail].Sent Mail")
;; (setq mu4e-trash-folder "/[Gmail].Trash")
;; don't save message to Sent Messages, Gmail/IMAP takes care of this
;; (setq mu4e-sent-messages-behavior 'delete)
;; (See the documentation for `mu4e-sent-messages-behavior' if you have
;; additional non-Gmail addresses and want assign them different
;; behavior.)
;; setup some handy shortcuts
;; you can quickly switch to your Inbox -- press ``ji''
;; then, when you want archive some messages, move them to
;; the 'All Mail' folder by pressing ``ma''.
;; (setq mu4e-maildir-shortcuts
;; '( ("/INBOX" . ?i)
;; ("/[Gmail].Sent Mail" . ?s)
;; ("/[Gmail].Trash" . ?t)
;; ("/[Gmail].All Mail" . ?a)))
;; allow for updating mail using 'U' in the main view:
;; (setq mu4e-get-mail-command "offlineimap")
;; something about ourselves
;; (setq
;; user-mail-address "[email protected]"
;; user-full-name "A. Augusto F. Garcia"
;; mu4e-compose-signature
;; (concat
;; "Antonio Augusto Franco Garcia\n"
;; "http://about.me/augusto.garcia\n"))
;; sending mail using smtp in gmail
;; also, make sure the gnutls command line utils are installed
;; package 'gnutls-bin' in Debian/Ubuntu
;; login and password are encrypted on .authinfo.gpg
;; (require 'smtpmail)
;; (setq message-send-mail-function 'smtpmail-send-it
;; starttls-use-gnutls t
;; smtpmail-starttls-credentials '(("smtp.gmail.com" 587 nil nil))
;; smtpmail-auth-credentials
;; (expand-file-name "~/.authinfo.gpg")
;; smtpmail-default-smtp-server "smtp.gmail.com"
;; smtpmail-smtp-server "smtp.gmail.com"
;; smtpmail-smtp-service 587
;; smtpmail-debug-info t)
;; alternatively, for emacs-24 you can use:
;;(setq message-send-mail-function 'smtpmail-send-it
;; smtpmail-stream-type 'starttls
;; smtpmail-default-smtp-server "smtp.gmail.com"
;; smtpmail-smtp-server "smtp.gmail.com"
;; smtpmail-smtp-service 587)
;; show images
;; (setq mu4e-show-images t)
;; use imagemagick, if available
;; (when (fboundp 'imagemagick-register-types)
;; (imagemagick-register-types))
;; spell check
;; (add-hook 'mu4e-compose-mode-hook
;; (defun my-do-compose-stuff ()
;; "My settings for message composition."
;; (set-fill-column 72)
;; (flyspell-mode)))
;; don't keep message buffers around
;; (setq message-kill-buffer-on-exit t)
;; for encrypting password for offlineimap - FIXME
;; (defun offlineimap-get-password (host port)
;; (let* ((netrc (netrc-parse (expand-file-name "~/.netrc.gpg")))
;; (hostentry (netrc-machine netrc host port port)))
;; (when hostentry (netrc-get hostentry "password"))))
;; defining useful block types for Beamer
(setq latex-block-names '("frame" "block" "exampleblock" "alertblock"))
;; Using pdflatex as the default compiler for .tex files
(setq latex-run-command "pdflatex")
;; From AucTeX manual
;; To get a full featured LaTeX-section command
(setq LaTeX-section-hook
'(LaTeX-section-heading
LaTeX-section-title
LaTeX-section-toc
LaTeX-section-section
LaTeX-section-label))
;; To enable LaTeX Math mode by default
(add-hook 'LaTeX-mode-hook 'LaTeX-math-mode)
;; To automatic insert braces in sub and superscripts in math symbols
(setq TeX-electric-sub-and-superscript t)
;; To enable auto-fill to latex mode
(add-hook 'LaTeX-mode-hook 'turn-on-auto-fill)
;; To activate TeX fold mode
(add-hook 'LaTeX-mode-hook (lambda ()
(TeX-fold-mode 1)))
;; to autosave before compiling LaTeX in AucTex
(setq TeX-save-query nil)
;; In AUCTex, make PDF by default (can toggle with C-c C-t C-p)
(add-hook 'TeX-mode-hook '(lambda () (TeX-PDF-mode 1)))
;; To don't query for master file - it was causing some problems
(setq-default TeX-master t)
;; To add xelatex to the available commands for compiling with C-c C-c
(eval-after-load "tex"
'(add-to-list 'TeX-command-list
'("XeLaTeX" "xelatex -interaction=nonstopmode %s"
TeX-run-command t t :help "Run xelatex") t))