【发布时间】:2014-05-28 23:16:51
【问题描述】:
是否可以计算 new 窗口开始/结束 不发生重新显示?如果是这样,那么一个例子将不胜感激。如果不是,那么近似它的最佳方法是什么?
示例:我们想要移动到屏幕外某处缓冲区的新区域,并在到达那里时放置叠加层。我们可能正在使用向下翻页或向下滚动或向下段落或缓冲区结束。当我们到达那个 new 点时,我们想要计算 new window-start 和 new window-end。但是,我们希望避免出现没有任何覆盖的瞬间裸露的缓冲区。理想情况下,一旦添加了这些叠加层,就会重新显示。我想根据 new window-start/end 将新的叠加层限制在新区域。
Point-Min:点 = 1
旧窗口开始:点 = 1000
旧窗口结束:点 = 1500
新窗口开始:点 = 3500
新窗口结束:point = 4000
点-最大值:点 = 6000
问题:当使用post-command-hook尝试并计算新window-start和新 window-end,正在使用之前的显示位置 - 即 old window-start 和 old window-end。
这是我正在进行的项目的示例。没有修复 window-start \ window-end 问题,我收到以下错误:
Error in post-command-hook (my-eol-ruler-function):
(error "Invalid search bound (wrong side of point)")`.
使用交互函数end-of-buffer 从(point-min) 到缓冲区末尾时会发生错误。在此错误的上下文中,(point-max) 超出了旧 window-end。
编辑:更新代码以包含一条消息:(message "point: %s | window-start: %s | window-end: %s | point-max: %s" (point) (window-start) (window-end) (point-max) )。该消息用于证明 new window-start 和 new window-end 未在 post-command-hook 内计算,因为尚未发生重新显示。但是,我试图避免重新显示,直到放置新的叠加层之后——否则,一个没有叠加层的裸缓冲区会在瞬间可见。
(defvar my-eol-ruler nil
"A horizontal ruler stretching from eol (end of line) to the window edge.")
(make-variable-buffer-local 'my-eol-ruler)
(defvar my-eol-pilcrow nil
"A pilcrow symbol placed at the end of every line except the current line.")
(make-variable-buffer-local 'my-eol-pilcrow)
(defun my-eol-ruler-function ()
(let* (
(opoint (point))
(window-width (window-width))
(window-start (window-start))
(window-end (window-end))
(col-eovl
(save-excursion
(vertical-motion 1)
(skip-chars-backward " \r\n" (- (point) 1))
(- (current-column) (progn (vertical-motion 0) (current-column)))))
(my-current-line-length (- (- window-width col-eovl) 3))
(pilcrow
(propertize (char-to-string ?\u00B6)
'face '(:foreground "white")
'cursor t))
(pilcrow-underlined
(propertize (char-to-string ?\u00B6)
'face '(:foreground "white" :underline "yellow")
'cursor t))
(underline (propertize (char-to-string ?\u2009)
'display `(space :width ,my-current-line-length)
'face '(:underline "yellow")
'cursor t)))
(when (or my-eol-ruler my-eol-pilcrow)
(dolist (description `(
,my-eol-ruler
,my-eol-pilcrow ))
(remove-overlays (point-min) (point-max)
'after-string description)) )
(setq my-eol-ruler (concat pilcrow-underlined underline))
(setq my-eol-pilcrow pilcrow)
(save-excursion
(end-of-line)
(overlay-put (make-overlay (point) (point))
'after-string my-eol-ruler ) )
(message "point: %s | window-start: %s | window-end: %s | point-max: %s"
(point)
(window-start)
(window-end)
(point-max) )
(save-excursion
(goto-char window-end)
(while (re-search-backward "\n" window-start t)
(let* (
(pbol (point-at-bol))
(pbovl (save-excursion (vertical-motion 0) (point)))
(peol (point))
(peol-pbol-region-p
(if (region-active-p)
(= peol pbol)))
(eol-inside-region-p
(if (region-active-p)
(and
(<= reg-beg peol)
(> reg-end peol))))
(col-eovl
(save-excursion
(vertical-motion 1)
(skip-chars-backward " \r\n" (- (point) 1))
(- (current-column) (progn (vertical-motion 0) (current-column)))))
(my-last-column (current-column))
(window-width-bug-p (= my-last-column (- window-width 1)))
(shazbot-pbol
(save-excursion
(end-of-line)
(re-search-backward "\s\\|\t" pbol t) (+ (point) 1)))
(wrapped-window-width-bug-p (= col-eovl (- window-width 1))) )
(when
(or
(< opoint pbol)
(> opoint peol))
(overlay-put (make-overlay peol peol) 'after-string my-eol-pilcrow))))) ))
(add-hook 'post-command-hook 'my-eol-ruler-function)
缓冲区的开始,在错误发生之前。
缓冲区结束--从缓冲区开始处执行交互函数end-of-buffer时发生错误。
Error in post-command-hook (my-eol-ruler-function):
(error "Invalid search bound (wrong side of point)")
【问题讨论】: