-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrefactoring.el
182 lines (161 loc) · 4.34 KB
/
refactoring.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
(defun end-of-include ()
"moves to beg of line after last include"
(beginning-of-buffer)
(while (search-forward "#include" nil t))
(beginning-of-line)
(next-line)
(point)
)
(defun start-of-include ()
(beginning-of-buffer)
(search-forward "#include" nil t)
(beginning-of-line)
(point)
)
(defun sort-includes ()
"sort the include statements alphabetically"
(let ( (p1 (start-of-include))
(p2 (end-of-include))
)
(sort-lines nil p1 p2)
)
)
(defun close-and-next ()
"close the current buffer and open next error"
(interactive)
(kill-buffer)
(next-error)
)
(defun doxy-group (group-name)
"Create an \addtogroup groupname statement for everything in this file."
(interactive "Mgroup-name: ")
(beginning-of-buffer)
(while (re-search-forward "^namespace" nil t) )
(search-forward "{")
(let ( (insertion-pos (point))
)
(backward-char)
(forward-sexp)
(backward-char)
(insert "/** @} */\n")
(goto-char insertion-pos)
(forward-char)
(insert "/** @addtogroup " group-name "\n*@{\n*/\n")
)
)
(defun save-and-close ()
"save the current buffer, and close it."
(interactive)
(save-buffer)
(kill-buffer)
)
(defun fsc ()
"fix the headers, save and close"
(interactive)
(fix-includes)
(save-and-close)
)
(defun doxyfix-comment ()
"take the nearest comment above, and turn it into a ///< style comment."
(interactive)
(save-excursion
(let ( (beg-com (search-backward "/*" nil t))
(end-com (search-forward "*/")))
(replace-regexp "\\\\brief" "" nil beg-com end-com)
(setq end-com (search-forward "*/"))
(replace-regexp "^\\([\t\s]*\\)" " \\1//" nil beg-com end-com)
(setq end-com (search-forward "*/"))
(goto-char end-com)
(delete-line)
(goto-char beg-com)
(delete-line)
)
)
)
(defun get-comment-bounds ()
"remove the uneccesary \brief from the comment"
(interactive)
(save-excursion
(cons (search-backward "/*" nil t) (search-forward "*/" nil t))
)
)
(defun delete-line()
"deletes the current line"
(interactive)
(save-excursion
(delete-region (progn (forward-line 0)(point))
(progn (forward-line 1)(point))
)
))
(defun do-within-comment ()
)
(defun com-online ()
" Take an ugly ass comment and make it into a one-liner"
(interactive)
(save-excursion)
(search-backward "//-------")
(delete-line)
(search-forward "//-------")
(delete-line)
(replace-string (search-backward "\*") (search-forward "*/") "\brief" "")
)
(defun doxy-convert-comment ()
"take the current comment and convert it to c++ style"
(interactive)
(save-excursion
(let ( (begp (search-backward "/*" nil ))
(endp (search-forward "*/" nil ))
)
(replace-regexp "/\\*." "///" nil begp endp)
(replace-regexp "\\\\brief" "" nil begp endp)
(let ((endp (search-forward "*/" nil ))
(beg-waste (re-search-backward "[^*/\s]"))
)
(delete-region beg-waste endp)
(replace-regexp "^" " ///" nil begp beg-waste)
)
(indent-region begp endp)
)
)
)
(defun indent-buffer ()
"indent the whole buffer"
(interactive)
(indent-region (point-min) (point-max))
)
(defun clean-me ()
"clean up common problems in our bacntetd. throwaway funciton"
(interactive)
(save-excursion
(beginning-of-buffer)
(while (re-search-forward "^[\s\t]*//--------------+$" nil t)
(insert "found")
(delete-line))
(indent-buffer)
(save-buffer)
)
)
(defun make-comment-block (blockname)
"insert a comment block with the given text"
(interactive "M block text: ")
(let ( (block-width 51))
(let ( (half-block-width (/ (- block-width 3) 2))
(word-width (length blockname))
(half-word-width (/ (length blockname) 2)) )
(let(
(num-spc-before (- half-block-width (+ half-word-width 2)))
)
(let(
(num-spc-after (- block-width (+ 4 num-spc-before word-width)))
)
(insert "//") (insert-char ?= (- block-width 1) ) (insert "\n")
(insert "//=") (insert-char ? (- block-width 3) ) (insert "=\n")
(insert "//=") (insert-char ? num-spc-before) (insert blockname)
(insert-char ? num-spc-after) (insert "=\n")
(insert "//=") (insert-char ? (- block-width 3) ) (insert "=\n")
(insert "//") (insert-char ?= (- block-width 1) ) (insert "\n")
)
)
)
)
)