forked from redguardtoo/emacs.d
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit-gud.el
78 lines (66 loc) · 2.2 KB
/
init-gud.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
(defvar gud-overlay
(let* ((ov (make-overlay (point-min) (point-min))))
(overlay-put ov 'face 'secondary-selection)
ov)
"Overlay variable for GUD highlighting.")
(defadvice gud-display-line (after my-gud-highlight activate)
"Highlight current line."
(let* ((ov gud-overlay)
(bf (gud-find-file true-file)))
(with-current-buffer bf
(move-overlay ov (line-beginning-position) (line-beginning-position 2)
(current-buffer)))))
(defun gud-kill-buffer ()
(if (derived-mode-p 'gud-mode)
(delete-overlay gud-overlay)))
(add-hook 'kill-buffer-hook 'gud-kill-buffer)
;; {{ hack buffer
;; move the cursor to the end of last line if it's gud-mode
(defun hack-gud-mode ()
(when (string= major-mode "gud-mode")
(goto-char (point-max))))
(defadvice switch-to-buffer (after switch-to-buffer-after activate)
(hack-gud-mode))
(defadvice select-window-by-number (after select-window-by-number-after activate)
(hack-gud-mode))
;; windmove-do-window-select is from windmove.el
(defadvice windmove-do-window-select (after windmove-do-window-select-after activate)
(hack-gud-mode))
;; }}
(defun gud-cls (&optional num)
"clear gud screen"
(interactive "p")
(let ((old-window (selected-window)))
(save-excursion
(cond
((buffer-live-p (get-buffer "*gud-main*"))
(select-window (get-buffer-window "*gud-main*"))
(end-of-buffer)
(recenter-top-bottom)
(if (> num 1) (recenter-top-bottom))
(select-window old-window))
(t (error "GUD buffer doesn't exist!"))
))
))
(eval-after-load 'gud
'(progn
(gud-def gud-kill "kill" "\C-k" "Kill the debugee")
))
(defun gud-kill-yes ()
"gud-kill and confirm with y"
(interactive)
(let ((old-window (selected-window)))
(save-excursion
(cond
((buffer-live-p (get-buffer "*gud-main*"))
(gud-kill nil)
(select-window (get-buffer-window "*gud-main*"))
(insert "y")
(comint-send-input)
(recenter-top-bottom)
(select-window old-window))
(t (error "GUD buffer doesn't exist!"))
))
))
(global-set-key "\C-x\C-a\C-g" 'gud-run)
(provide 'init-gud)