gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 20:07:20 24 4
gpt4 key购买 nike

是否可以计算 没有重新显示的窗口开始/结束?如果是这样,那么一个例子将不胜感激。如果不是,那么近似它的最佳方法是什么?

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

  • 点-最小值:点 = 1
  • 旧窗口开始:点 = 1000
  • 旧窗口结束:点 = 1500
  • 新窗口开始:点 = 3500
  • 新窗口结束:点 = 4000
  • 最大点数:点 = 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)

    缓冲区的开始,在错误发生之前。

    Example

    缓冲区结束——执行交互函数时发生错误end-of-buffer从缓冲区开始处的某个点开始。
    Error in post-command-hook (my-eol-ruler-function):
    (error "Invalid search bound (wrong side of point)")

    Example

    最佳答案

    另请参阅 Emacs 错误跟踪器功能请求 #22404(尚未实现,但邮件存档包含一个粗略的基本补丁草稿,为这个特定问题创建了一个新钩子(Hook)):https://debbugs.gnu.org/cgi/bugreport.cgi?bug=22404

  • 用于测试的次要模式 window-startwindow-end在视觉重新显示之前。

  • ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;; test-mode
    ;; A minor-mode for testing `window-start` / `window-end` BEFORE visual redisplay.

    (defvar test-this-command nil
    "This local variable is set within the `post-command-hook`; and,
    is also used by the `window-scroll-functions` hook.")
    (make-variable-buffer-local 'test-this-command)

    (defun test-post-command-hook-fn ()
    "A function attached to the `post-command-hook`."
    (setq test-this-command this-command)
    (test-demo-fn))

    (defun test-window-scroll-functions-fn (win _start)
    "A function attached to the `window-scroll-functions` hook."
    (test-demo-fn))

    (defun test-demo-fn ()
    "This is a test-mode demonstration function."
    (when
    (and
    test-mode
    test-this-command
    (window-live-p (get-buffer-window (current-buffer)))
    (not (minibufferp))
    (pos-visible-in-window-p (point)
    (get-buffer-window (current-buffer) (selected-frame)) t))
    (let* (
    (selected-window (selected-window))
    (window-start (window-start selected-window))
    (window-end (window-end selected-window t)) )
    (message "window-start: %s | window-end: %s" window-start window-end)
    (setq test-this-command nil) )))

    (define-minor-mode test-mode
    "A minor-mode for testing `window-start` / `window-end` BEFORE visual redisplay."
    :init-value nil
    :lighter " TEST"
    :keymap nil
    :global nil
    :group nil
    (cond
    (test-mode
    (set (make-local-variable 'scroll-conservatively) 101)
    (add-hook 'post-command-hook 'test-post-command-hook-fn nil t)
    (add-hook 'window-scroll-functions 'test-window-scroll-functions-fn nil t)
    (when (called-interactively-p 'any)
    (message "Turned ON `test-mode`.")))
    (t
    (kill-local-variable 'scroll-conservatively)
    (kill-local-variable 'test-this-command)
    (remove-hook 'post-command-hook 'test-post-command-hook-fn t)
    (remove-hook 'window-scroll-functions 'test-window-scroll-functions-fn t)
    (when (called-interactively-p 'any)
    (message "Turned OFF `test-mode`.") ))))

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

    关于Emacs - 计算新窗口开始/结束而不重新显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23923371/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com