-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcopy-comment.el
33 lines (31 loc) · 1.09 KB
/
copy-comment.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
;;=======================================================================
;; Copy comments between windows
;;=======================================================================
;;;###autoload
(defun copy-comment-to-other-window ()
"Copy a comment from one window to another, adjusting for major mode."
(interactive)
(let ((comment (or (grab-comment)
(error "No comment on this line"))))
(other-window 1)
(if (eq major-mode 'c-mode)
(c-indent-for-comment)
(indent-for-comment))
(insert comment)
(end-of-line)))
(defun grab-comment ()
"Extract the text of a comment."
(save-excursion
(let ((eol (save-excursion (end-of-line) (point)))
boc eoc)
(beginning-of-line)
(if (not (or (and comment-line-start-skip
(re-search-forward comment-line-start-skip eol t))
(and comment-start-skip
(re-search-forward comment-start-skip eol t))))
nil
(setq boc (or (match-end 1) (match-end 0)))
(and (> (length comment-end) 0)
(search-forward comment-end eol t)
(setq eoc (- (point) (length comment-end))))
(buffer-substring boc (or eoc eol))))))