forked from voyeg3r/dotfaster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemacs
242 lines (204 loc) · 8.08 KB
/
emacs
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
;; https://github.com/jekor/.emacs
;;(tool-bar-mode -1)
;;(menu-bar-mode -1)
;;(scroll-bar-mode -1)
;; smart beginning of line ======================================
(defun my-smart-beginning-of-line ()
"Move point to beginning-of-line. If repeat command it cycle
position between `back-to-indentation' and `beginning-of-line'."
(interactive "^")
(if (and (eq last-command 'my-smart-beginning-of-line)
(= (line-beginning-position) (point)))
(back-to-indentation)
(beginning-of-line)))
(global-set-key (kbd "C-a") 'my-smart-beginning-of-line)
;; ============ Reload ~/.emacs ===========================
(defun reload-init-file ()
(interactive)
(load-file "~/.emacs"))
(global-set-key (kbd "C-c C-l") 'reload-init-file) ; Reload .emacs filea
;; kill region =============================================================
(defun xah-delete-current-text-block ()
"Delete the current text block or selection, and copy to `kill-ring'.
A “block” is text between blank lines.
URL `http://ergoemacs.org/emacs/emacs_delete_block.html'
Version 2017-07-09"
(interactive)
(let ($p1 $p2)
(if (use-region-p)
(setq $p1 (region-beginning) $p2 (region-end))
(progn
(if (re-search-backward "\n[ \t]*\n+" nil "move")
(progn (re-search-forward "\n[ \t]*\n+")
(setq $p1 (point)))
(setq $p1 (point)))
(re-search-forward "\n[ \t]*\n" nil "move")
(setq $p2 (point))))
(kill-region $p1 $p2)))
(global-set-key (kbd "C-c k") 'xah-delete-current-text-block)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; kill line if no region active ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; http://emacs-fu.blogspot.co.uk/2009/11/copying-lines-without-selecting-them.html
(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)))))
;; =============== Highlight current line =========================
;; In every buffer, the line which contains the cursor will be fully
;; highlighted
(global-hl-line-mode 0)
;; ========== Enable Line and Column Numbering ==========
;; Show line-number in the mode line
(line-number-mode 1)
;; Show column-number in the mode line
(column-number-mode 1)
;; Added by Package.el. This must come before configurations of
;; installed packages. Don't delete this line. If you don't want it,
;; just comment it out by adding a semicolon to the start of the line.
;; You may delete these explanatory comments.
(package-initialize)
;; font setting
(set-default-font "FuraMono Nerd Font 14" nil t)
;; Set line number mode to always be on
(global-linum-mode t)
;; no startup message
(setq inhibit-startup-message t)
(setq frame-title-format
(list (format "%s %%S: %%j " (system-name))
'(buffer-file-name "%f" (dired-directory dired-directory "%b"))))
;; Ctrl-RET Ctrl-Shift-RET
;; Insert new line below current line
;; and move cursor to new line
;; it will also indent newline
(global-set-key (kbd "<C-return>") (lambda ()
(interactive)
(end-of-line)
(newline-and-indent)))
;; Insert new line above current line
;; and move cursor to previous line (newly inserted line)
;; it will also indent newline
;; TODO: right now I am unable to goto previous line, FIXIT
(global-set-key (kbd "<C-S-return>") (lambda ()
(interactive)
(beginning-of-line)
(newline-and-indent)
(previous-line)))
(recentf-mode 1)
(setq recentf-max-menu-items 25)
(global-set-key "\C-x\ \C-r" 'recentf-open-files)
;; adjust transpose-chars to switch previous two characters
;; source: http://pragmaticemacs.com/emacs/transpose-characters/
(global-set-key (kbd "C-t")
(lambda () (interactive)
(backward-char)
(transpose-chars 1)))
; make end and home keys go to the start/end of buffers
(global-set-key (kbd "<end>") 'end-of-buffer)
(global-set-key (kbd "<home>") 'beginning-of-buffer)
(define-key input-decode-map "\e[1;5A" [C-up])
(define-key input-decode-map "\e[1;5B" [C-down])
(global-set-key (kbd "C->") 'end-of-buffer)
(global-set-key (kbd "C-<") 'beginning-of-buffer)
;; let's see if it works
(global-set-key (kbd "C-x G") 'end-of-buffer)
(global-set-key (kbd "C-x gg") 'beginning-of-buffer)
(global-set-key (kbd "M-<") 'end-of-buffer)
(global-set-key (kbd "M->") 'beginning-of-buffer)
; ignore case when searching
(setq-default case-fold-search 1)
; show the current line and column numbers in the stats bar as well
(line-number-mode 1)
(column-number-mode 1)
; highlight parentheses when the cursor is next to them
(require 'paren)
(show-paren-mode 1)
; source: https://stackoverflow.com/a/88828/2571881
; (defun duplicate-line()
; (interactive)
; (move-beginning-of-line 1)
; (kill-line)
; (yank)
; (newline)
; (yank)
; )
; (global-set-key (kbd "C-d") 'duplicate-line)
; https://stackoverflow.com/a/3446738/2571881
(defun duplicate-line (&optional arg)
"Duplicate it. With prefix ARG, duplicate ARG times."
(interactive "p")
(save-excursion
(let ((beg (line-beginning-position))
(end
(progn (forward-line (1- arg)) (line-end-position))))
(copy-region-as-kill beg end)
(end-of-line) (newline)
(yank)))
(next-line arg))
(global-set-key (kbd "C-S-d") 'duplicate-line)
(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.
'(ansi-color-faces-vector
[default default default italic underline success warning error])
'(ansi-color-names-vector
["#242424" "#e5786d" "#95e454" "#cae682" "#8ac6f2" "#333366" "#ccaa8f" "#f6f3e8"])
'(custom-enabled-themes (quote (whiteboard)))
'(ido-mode (quote both) nil (ido))
'(package-archives
(quote
(("gnu" . "http://elpa.gnu.org/packages/")
("marmelade" . "http://marmalade-repo.org/packages/"))))
'(package-selected-packages
(quote
(evil expand-region ergoemacs-mode evil-visual-mark-mode solarized-theme org color-theme-solarized))))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
)
;; Tirgger recorded macro
(define-key global-map [f4] 'call-last-kbd-macro)
;; turn on highlighting current line
(global-hl-line-mode 1)
;; turn on bracket match highlight
(show-paren-mode 1)
;; remember cursor position, for emacs 25.1 or later
(save-place-mode 1)
;; stop creating those #auto-save# files
(setq auto-save-default nil)
;; y/n instead of yes/no
(defalias 'yes-or-no-p 'y-or-n-p)
(defun duplicate-current-line-or-region (arg)
"Duplicates the current line or region ARG times.
If there's no region, the current line will be duplicated. However, if
there's a region, all lines that region covers will be duplicated."
(interactive "p")
(let (beg end (origin (point)))
(if (and mark-active (> (point) (mark)))
(exchange-point-and-mark))
(setq beg (line-beginning-position))
(if mark-active
(exchange-point-and-mark))
(setq end (line-end-position))
(let ((region (buffer-substring-no-properties beg end)))
(dotimes (i arg)
(goto-char end)
(newline)
(insert region)
(setq end (point)))
(goto-char (+ origin (* (length region) arg) arg)))))
;;Then bind a key to it. I use C-c d.
;; to copy current line 5 times just:
;; M-5 C-c d
(global-set-key (kbd "C-c d") 'duplicate-current-line-or-region)
;; ================= melpa ==========================================
(add-to-list 'package-archives
'("marmalade" . "http://marmalade-repo.org/packages/") t)
(require 'evil)
;;(evil-mode 1)