Emacs - 计算新窗口 - 开始/结束而不重新显示

 白变小樱啊 发布于 2023-01-12 17:42

是否可以在没有重新显示的情况下计算窗口 - 开始/结束?如果是这样,那么一个例子将非常感激.如果没有,那么接近它的最佳方法是什么?

示例:我们希望在屏幕外的某个位置移动到缓冲区的新区域,并在到达时放置叠加层.我们可能正在使用向下翻页或向下滚动或向下翻页或结束缓冲区.当我们到达那个点时,我们想要计算新的 window-start新的 window-end.但是,我们希望避免使用没有任何叠加层的瞬间裸露缓冲区.理想情况下,一旦添加了这些叠加层,就会发生重新显示.我想基于窗口 - 开始/结束将新叠加限制到新区域.

Point-Min:point = 1

旧窗口开始:点= 1000

旧窗口结束:点= 1500

新窗口开始:点= 3500

新窗口结束:点= 4000

Point-Max:point = 6000

问题:当使用post-command-hook尝试并计算出新的 window-start新的 window-end,以前的显示位置被代替-即 window-start window-end.


这是我正在进行的项目的示例.没有修复window-start\ window-end问题,我收到以下错误:

Error in post-command-hook (my-eol-ruler-function):
  (error "Invalid search bound (wrong side of point)")`.

(point-min)使用交互式功能从缓冲区结束时发生错误end-of-buffer.在这个错误的背景下,(point-max)是超越旧的 window-end.


编辑:更新了代码以包含消息: (message "point: %s | window-start: %s | window-end: %s | point-max: %s" (point) (window-start) (window-end) (point-max) ).该消息用于演示新内容 window-start新内容 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)")

例

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有