-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbindings.el
108 lines (91 loc) · 3.86 KB
/
bindings.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
(defadvice find-file-at-point (around goto-line compile activate)
(let ((line (and (looking-at ".*:\\([0-9]+\\)")
(string-to-number (match-string 1)))))
ad-do-it
(and line (goto-line line))))
(defun asok/setup-nav-bindings (modifier)
(global-set-key (kbd (concat modifier "-h")) 'windmove-left)
(global-set-key (kbd (concat modifier "-l")) 'windmove-right)
(global-set-key (kbd (concat modifier "-j")) 'windmove-down)
(global-set-key (kbd (concat modifier "-k")) 'windmove-up)
(global-set-key (kbd (concat modifier "-d")) 'previous-buffer)
(global-set-key (kbd (concat modifier "-f")) 'next-buffer))
(if (string= system-type "gnu/linux")
(asok/setup-nav-bindings "M")
(asok/setup-nav-bindings "s"))
(global-set-key (kbd "C-q") (lambda () (interactive) (switch-to-prev-buffer (previous-window))))
(global-set-key (kbd "C-w") (lambda () (interactive) (switch-to-next-buffer (previous-window))))
(global-set-key (kbd "C-h C-f") #'find-function)
(add-hook 'ido-setup-hook 'asok/ido-keys)
(defun asok/ido-keys ()
(define-key ido-completion-map (kbd "<SPC>") 'ido-next-match)
(define-key ido-completion-map [?\C- ] 'ido-prev-match))
(defun visit-shell ()
"If the current buffer is:
1) a running shell named *shell*, rename it.
2) a non shell, go to an already running shell
or start a new one while killing a defunt one"
(interactive)
(if (and (string= "shell-mode" major-mode) (string= "*shell*" (buffer-name)))
(call-interactively 'rename-buffer)
(shell)))
(global-set-key (kbd "<f2>") 'visit-shell)
(global-unset-key (kbd "s-t"))
(global-unset-key (kbd "s-y"))
(global-unset-key (kbd "s-u"))
(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)
(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)
(defun asok/org-notes ()
(interactive)
(switch-to-buffer
(generate-new-buffer (generate-new-buffer-name "*org-notes*")))
(org-mode)
(insert (concat "* " (format-time-string "%d-%m-%Y @ %H:%M") "\n** "))
(evil-insert-state))
(defun asok/leader-kbd (key)
(kbd (format "<SPC> %s" key)))
;; (defvar asok/highlight-map
;; (let ((map (make-sparse-keymap)))
;; (define-key map (kbd "s") 'highlight-symbol-at-point)
;; (define-key map (kbd "h") 'hi-lock-mode)
;; map))
;; (defvar asok/eval-map
;; (let ((map (make-sparse-keymap)))
;; (define-key map (kbd "e") #'eval-expression)
;; (define-key map (kbd "d") #'eval-defun)
;; (define-key map (kbd "b") #'eval-buffer)
;; (define-key map (kbd "l") #'eval-last-sexp)
;; map))
(defun asok/at-comment-p ()
(let ((face (face-at-point t)))
(or
(eq face 'font-lock-comment-delimiter-face)
(eq face 'font-lock-comment-face))))