Emacs - 使用变量值删除覆盖`after-string` [英] Emacs -- remove an overlay `after-string` with a variable value

查看:182
本文介绍了Emacs - 使用变量值删除覆盖`after-string`的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么正确的方法,请删除 after-string 覆盖变量值?

What is the proper way, please, to remove after-string overlays with variable values?

当使用 Cu Cx = ,它只显示为 after-string 而不说明该值。

When using C-u C-x =, it only shows up as after-string without stating what the value is.

例如,一旦我使用(overlay-put(make-overlay(point)(point)))放置一个叠加''after-string my-concatenated-string ),我想删除它,而不需要编程Emacs记住以前在缓冲区中使用的每个 my-concatenated-string - 每行上可能有几个不同的对象?

For example, once I lay an overlay using (overlay-put (make-overlay (point) (point)) 'after-string my-concatenated-string), I would like to be able to delete it without programming Emacs to remember every single my-concatenated-string that was previously used in the buffer -- there might be a few different ones on every line?

是否足够使用?:(remove-overlays(window-start) (window-end))'after-string)

或者,最好使用?:(remove -overlays(window-start)(window-end))'after-string t)

或者还有另一种方法来获取它们所有?

Or, is there another method to get them all?

EDIT (2014年3月17日):我的conf使用情况显然来自于对象属性之间的误解。

EDIT (March 17, 2014):  My confusion is apparently coming from a misunderstanding between an object and a property.

通常,覆盖 >属性创建如下:

(overlay-put (make-overlay (point) (point)) 'my-property 'property-number-one )

通常,覆盖创建如下:

In general, an overlay object is created as follows:

(overlay-put (make-overlay (point) (+ (point) 1))
  'face '(:background "gray50" :foreground "black"))

这是一个独特的情况,一个'after-string 闻起来像一个对象。我的假设是:如果它像一个对象闻起来,那么在尝试删除它时,可能需要包含一个,这样我就没有留下>断开连接 'after-string

Here is a unique situation where an 'after-string smells-like an object. My assumption is: if it smells-like an object, then perhaps a value needs to be included when attempting to remove it so that I'm not left with a disconnected 'after-string:

(save-excursion
  (end-of-line)
  (let ((eol-floating-column (+ (current-column) 10)))
    (overlay-put (make-overlay (point) (point))
                 'after-string
                 (concat
                  (propertize (char-to-string ?\uE001)
                              'display
                              `((space :align-to ,eol-floating-column)
                                (space :width 0)))
                  (propertize (char-to-string ?\u00B6)
                              'face '(:background "gray50" :foreground "black")
                              'cursor t) ))))


推荐答案

(defun lawlist-remove-overlays (beg end name val)
  "Remove the overlays."
  ;; DEBUGGING
  ;; (unless (and beg end name val)
  ;;   (message "ERROR -- beg:  %s | end:  %s | name:  %s | val:  %s" beg end name val))
  (let* (
      (point-max (point-max))
      (point-min (point-min))
      (narrowed-p (not (equal (- point-max point-min) (buffer-size))))
      (beg (if beg beg point-min))
      (end
        (cond
          ((and
              (not narrowed-p)
              end)
            end)
          ((and
              (not narrowed-p)
              (null end))
            point-max)
          ((and
              narrowed-p
              end
              (< end point-max))
            end)
          ((and
              narrowed-p
              end
              (= end point-max))
            (1+ end))
          ((and
              narrowed-p
              (null end))
            (1+ point-max)) )))
    (when (and beg end name val)
      (overlay-recenter end)
      (dolist (o (overlays-in beg end))
        (when (eq (overlay-get o name) val)
          (delete-overlay o))))))

  (dolist (description `(
    ,fci-pre-limit-string
    ,fci-pre-limit-active-region-string
    ,fci-at-limit-string
    ,fci-post-limit-string
    ,fci-wrapped-limit-string
    ,fci-cursor-at-eol-string
    ,fci-tab-text-left
    ,fci-tab-text-right
    ,fci-tab-sandwiched))
  (lawlist-remove-overlays nil nil 'after-string description))

另请参见这个相关的线程,其中涉及到具有值的定位重叠包含文本属性:

See also this related thread which deals with targeting overlays with values containing text properties:

https://emacs.stackexchange.com / a / 9847/2287

这篇关于Emacs - 使用变量值删除覆盖`after-string`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆