我正在编写一个例程来测试点是否在实际的最后一行。
(defun end-of-line-p ()
"T if there is only \w* between point and end of line"
(interactive)
(save-excursion
(set-mark-command nil) ;mark where we are
(move-end-of-line nil) ;move to the end of the line
(let ((str (buffer-substring (mark) (point)))) ;; does any non-ws text exist in the region? return false
(if (string-match-p "\W*" str)
t
nil))))
问题是,在运行它时,我在迷你缓冲窗口中看到“标记集”,而不是T或nil。
答案 0 :(得分:8)
(looking-at-p "\\s-*$")
答案 1 :(得分:1)
有一个名为eolp
的内置函数。 (编辑:但这不是你想要实现的,是吗......)
这是我的功能版本(虽然你必须比我更彻底地测试它):
(defun end-of-line-p ()
"true if there is only [ \t] between point and end of line"
(interactive)
(let (
(point-initial (point)) ; save point for returning
(result t)
)
(move-end-of-line nil) ; move point to end of line
(skip-chars-backward " \t" (point-min)) ; skip backwards over whitespace
(if (> (point) point-initial)
(setq result nil)
)
(goto-char point-initial) ; restore where we were
result
)
)