Skip to content

Instantly share code, notes, and snippets.

@chuntaro
Created November 30, 2016 07:20
Show Gist options
  • Select an option

  • Save chuntaro/b152f9e215ea816f7effb9dc3dad3f83 to your computer and use it in GitHub Desktop.

Select an option

Save chuntaro/b152f9e215ea816f7effb9dc3dad3f83 to your computer and use it in GitHub Desktop.
;; #Emacs でコーディングしてて、コメント内に TODO とか色々書き残したりするけど
;; 後でまとめてそれらを抜き出したりしたい時に役立つelisp
;;
;; Emacs はコメントを認識してるから、それを使って言語非依存になってる!
(defun comment-traversal (beg end func)
(save-excursion
(let (spt ept)
(goto-char beg)
(while (and (< (point) end)
(setq spt (comment-search-forward end t)))
(setq ept (progn
(goto-char spt)
(unless (or (comment-forward)
(eobp))
(error "Can't find the comment end"))
(point)))
(funcall func spt ept)))))
(defun test-comment-traversal ()
"`comment-traversal' のテストコード.
test.cpp なんかのバッファ内で実行すると *Messages* にコメント行を表示する."
(interactive)
(let ((count 0))
(comment-traversal (point-min)
(point-max)
(lambda (beg end)
(message "%d: %s"
(setq count (1+ count))
(buffer-substring beg end))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment