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

law*_*ist 5 emacs elisp

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

示例:我们希望在屏幕外的某个位置移动到缓冲区的新区域,并在到达时放置叠加层.我们可能正在使用向下翻页或向下滚动或向下翻页或结束缓冲区.当我们到达那个点时,我们想要计算新的 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)")`.
Run Code Online (Sandbox Code Playgroud)

(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)
Run Code Online (Sandbox Code Playgroud)

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

例


缓冲区结束 - end-of-buffer从缓冲区开头的某个点执行交互式功能时发生错误.

Error in post-command-hook (my-eol-ruler-function):
  (error "Invalid search bound (wrong side of point)")
Run Code Online (Sandbox Code Playgroud)

例

law*_*ist 2

另请参见 Emacs bug tracker feature request #22404(尚未实现,但邮件存档包含一个草稿基本补丁,该补丁为该特定问题创建了一个新的钩子): https ://debbugs.gnu.org/cgi/ bugreport.cgi?bug=22404

  • window-start用于测试和视觉重新显示之前的次要模式window-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`.") ))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Run Code Online (Sandbox Code Playgroud)