word-wrap -- 在视线末尾覆盖'after-string时使用''cursor t'

word-wrap -- using `'cursor t` when overlay 'after-string at end of visual line

问题:当点位于视觉上环绕的行的末尾(但不在行的最末端)时,光标不遵守 cursor t 叠加设置 after-string -- 即,光标出现在 next 视觉换行的开头,而不是 current 的末尾 视觉上换行。

在这个例子/问题中,让我们假设变量word-wrapt,变量truncate-linesnil。它不一定是 visual-line-mode 处于活动状态,但它肯定可以。目标是在视觉线的末端向右 window 边缘延伸一个水平标尺,并解决当点在视觉包裹线的末端时出现的问题(但不是在最末端)线)。

下面的代码适用于所有情况 除了 当光标位于可视化换行的末尾(但不是在行的最后)时。以编程方式,在这种情况下,光标如何在视觉上保持在叠加层的开头 after-string

(defun example ()
(interactive)
  (let* (
    peovl
    peovl+1
    (col-eovl
      (save-excursion
          (let ((movement-indicator (vertical-motion 1)))
            (when (= movement-indicator 1)
              (backward-char 1)))
          (setq peovl (point))
          (setq peovl+1 (1+ peovl))
          (- (current-column) (progn (vertical-motion 0) (current-column)))))
    (current-underline-length (- (window-width) col-eovl))
    (underline (propertize (char-to-string ?\u2009)
          'display `(space :width ,current-underline-length)
          'face '(:underline "blue")
          'cursor t)))
  (remove-overlays)
  (unless (= peovl (point-at-eol))
    (overlay-put (make-overlay peovl peovl+1) 'display ""))
  (overlay-put (make-overlay peovl peovl) 'after-string underline)))

在可视化换行的最后一点向 space 字符(即数字 32 字符代码)添加带有 'after-string 属性 的叠加层时,光标将 完全跳过 叠加层。 cursor t 属性 将被忽略。

solution/workaround是用'display属性代替,试图达到楼主描述的视觉效果。

(defun example ()
(interactive)
  (remove-overlays)
  (let* (
    result
    peovl
    peovl+1
    (opoint (point))
    (peol (point-at-eol))
    (underscore "_")
    (col-eovl
      (save-excursion
          (let ((movement-indicator (vertical-motion 1)))
            (when (= movement-indicator 1)
              (backward-char 1)))
          (setq peovl (point))
          (setq peovl+1 (1+ peovl))
          (- (current-column) (progn (vertical-motion 0) (current-column)))))
    (current-underline-length (- (window-width) col-eovl))
    (eol-underline (propertize (char-to-string ?\u2009)
          'display `(space :width ,current-underline-length)
          'face '(:underline "blue")
          'cursor t))
    (underscore-concatenated
      (progn
        (dotimes (i current-underline-length)
          (setq result (concat underscore result))) result))
    (wrapped-peovl-underline (propertize underscore-concatenated
          'face '(:foreground "blue")
          'cursor t)) )
    (if
        (and
          (= opoint peovl)
          (not (= peovl peol)))
      (overlay-put (make-overlay peovl peovl+1) 'display wrapped-peovl-underline)
      (unless (= peovl peol)
        (overlay-put (make-overlay peovl peovl+1) 'display ""))
      (overlay-put (make-overlay peovl peovl) 'after-string eol-underline))))