大家好,这是我对 An Introduction to Programming in Emacs Lisp 12.6 Exercises with ‘re-search-forward’ 所做的练习。
• Write a function to search for a regular expression that matches two or more blank lines in sequence.
(defun check-two ()
(interactive)
(if (not (re-search-forward "^[ \t]*$" nil t))
(message "No blank lines."))
(catch 'exit-condition
(while (re-search-forward "^[ \t]*$" nil t)
(forward-char)
(if (re-search-forward "^[ \t]*$" nil t)
(let ((number-of-blank-lines 0))
(while (re-search-forward "^[ \t]*$" (1+ (point)) t)
(progn (forward-char)
(setq number-of-blank-lines (1+ number-of-blank-lines))))
(backward-char)
(if (< 1 number-of-blank-lines)
(progn (message "Numbers of blank lines are: %s" number-of-blank-lines)
(throw 'exit-condition number-of-blank-lines))))))))
虽然在运气好的时候,似乎能达到题目要求,但是正如大家所见,这个代码片 断写得像面条一样。
还请大家提供一些建议。
谢谢。