我写了在modeline中判断当前的symbol使用数量和当前是第几个的函数。这个函数在遇到某些特殊字符或者通过鼠标选中多个字符的时候会卡死emacs。没有必现条件。都是偶发。还没找到规律。
我判断是获取当前符号的时候某些条件判断有问题。由于对elisp不是很熟。道友们帮忙看看函数是否有不合理的地方?还所某些特殊情况没有想到导致无限循环卡死了?
;;
(defun vw/modeline–symbol-count-info ()
(let* ((symbol (thing-at-point 'symbol))
(cur-bound (bounds-of-thing-at-point 'symbol)))
(when (and symbol cur-bound)
(let*((cur (point))
(cur-start (car cur-bound))
(cur-end (cdr cur-bound))
(cur-length (- cur-end cur-start))
(total 0)
(curindex 0))
(save-excursion
(save-restriction
(when symbol
(goto-char (point-min))
(while (re-search-forward symbol nil t)
(let* ((bound (bounds-of-thing-at-point 'symbol))
(end (cdr bound))
(start (car bound))
(len (- end start)))
(if (= cur-length len)
(progn
(setq total (+ total 1))
(if (and (>= cur start) (<= cur end))
(setq curindex total))))))
(format "T:%d.C:%d" total curindex))))))))
doom-modeline 调用是这样的
(doom-modeline-def-segment vw/modeline–symbol-count
"Displays Symbol Count info."
(unless (minibufferp)
(vw/modeline--symbol-count-info)))