Created
January 12, 2012 07:05
-
-
Save takaxp/1599131 to your computer and use it in GitHub Desktop.
my-find-headings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (defun my-find-headings () | |
| (let ((eob (point-max)) | |
| (head-list '())) | |
| (save-excursion | |
| (goto-char (point-min)) | |
| (while (when (search-forward-regexp "^\*\\([^*]\\|$\\)" eob t) | |
| (setq head-list (cons (match-beginning 0) head-list)) | |
| (forward-line)))) | |
| (reverse head-list))) |
Author
'()を使うのは、(これから値を追加していく)空のリストであることを強調したつもりです。
nilだとnilであることに(真偽などの)意味があるような気がしてしまうので…。
スライド数が多くなるなら、consで結合しておいて最後にnreverseするのが一番速いと思います。
appendにしてもadd-to-listにしても毎ループごとにリストの末尾まで辿らないといけませんから。
add-to-listは破壊的なので、add-to-listとappendならadd-to-listの方が速いと思います。
Author
うう.たくさんのコメントありがとうございます(T-T)
ノウハウを色々と教えていただいたので本当に勉強になりますっ
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
あ.確かにwhile内部ですね point-max はOrz
ちなみに head-list を '() を nil としないは理由がありますか?
スライド数が数十だと,実は既存の実装でもあまり問題にならなかったりします.
5000千行,スライド数400,キーボードリピート30[ms] という環境でもたつくので,レア環境と言えばそこまでなのですが,でもこの実装はとり込もうと思います!