Emacs -- 如何创建垂直删除线效果 [英] Emacs -- How to create a vertical strike-through effect

查看:14
本文介绍了Emacs -- 如何创建垂直删除线效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一些关于如何创建垂直删除线的视觉效果的建议(字符在垂直条的顶部(u007C")仍然可见).如果可以分层,则垂直条应位于下方,以便字母大部分可见.

I'm looking for some suggestions, please, of how to create the visual effect of a vertical strike-through (with the character on top of the vertical bar ("u007C") still being visible). If layering is possible, then the vertical bar should be underneath so that the letter is mostly visible.

我搜索了一种叠加字符、分层叠加的方法,并查看了一些 xpm 图像,但是,我没有找到任何与我正在寻找的东西相近的东西.目标是获得类似于下图的真正十字准线效果——灰色背景将替换为黄色垂直删除线,以便字母仍然可见.

I searched for a method of superimposing characters, layering overlays, and I looked at some xpm images, however, I have not found anything remotely close to what I'm looking for. The goal is to have a true cross-hairs effect similar to the image below -- the gray background would be replaced with a yellow vertical strike-through so that the letters would still be visible.

推荐答案

Feature Request #17684 (crosshairs) [ https://debbugs.gnu.org/cgi/bugreport.cgi?bug=17684 ] 和功能请求 22873(多个假光标)[ https://debbugs.gnu.org/cgi/bugreport.cgi?bug=22873 ] 是一项工作进行中.尽管这些功能是否会被纳入官方 Emacs 尚不得而知,但有一个工作草案证明概念已发布到上述两个功能请求中.在从主分支(X11、Windows 或 NS)构建 Emacs 的 GUI 版本之前,这些功能需要对 C 和 Lisp 内部结构进行修改.

Feature Request #17684 (crosshairs) [ https://debbugs.gnu.org/cgi/bugreport.cgi?bug=17684 ] and Feature Request 22873 (multiple fake cursors) [ https://debbugs.gnu.org/cgi/bugreport.cgi?bug=22873 ] are a work in progress. Although it is unknown whether these features will ever be incorporated into the official Emacs, there is a working draft proof concept that has been posted to both of the above-mentioned feature requests. The features require modifications to both the C and Lisp internals prior to building a GUI version of Emacs from the master branch -- X11, Windows or NS.

示例 1,共 3 个:

以下代码片段适用于 some 操作系统上的 some 字体——例如,它在 Windows 上开箱即用;但是,它在 OSX 10.6.8 Snow Leopard 或 Snow Leopard Server 10.6.8 上对作者不起作用.[参见错误报告编号 20537 -- https://debbugs.gnu.org/cgi/bugreport.cgi?bug=20537 -- 尽管 Emacs 开发团队已正式关闭该错误报告,但该作者在错误修复"之后始终无法在 Snow Leopard 上使用该功能".:( ] 用户可能希望对字形参考点进行试验,composite.el 中的变量 reference-point-alist 有一个与此相关的详细文档字符串. 用户也可能希望尝试使用 after-stringbefore-string 显示属性.vline.elhref="http://www.emacswiki.org/emacs/vline.el" rel="nofollow noreferrer">http://www.emacswiki.org/emacs/vline.el 有一个名为 vline-style,可以设置为'face'compose'mixed——后两者设置会导致 vline 使用此代码片段的轻微变体 [参见所述库的第 362 至 370 行].

The following code snippet works with some fonts on some operating systmes -- e.g., it works out of the box on Windows; however, it does not work for this author on OSX 10.6.8 Snow Leopard or Snow Leopard Server 10.6.8. [See bug report number 20537 -- https://debbugs.gnu.org/cgi/bugreport.cgi?bug=20537 -- even though the bug report has been officially closed by the Emacs development team, this author has never been able to get that feature working on Snow Leopard subsequent to the "bug fix". :( ] The user may wish to experiment with the glyph reference points, and the variable reference-point-alist in composite.el has a detailed doc-string in relation thereto. The user may also wish to experiment with using an after-string or before-string display property. The library vline.el at http://www.emacswiki.org/emacs/vline.el has a variable named vline-style, which can be set to 'face, 'compose, or 'mixed -- the latter two settings cause vline to use a slight variation of this code snippet [see lines 362 to 370 of said library].

(let* (
    (point-min (point-min))
    (point-max (point-max))
    (pt (point))
    (pt+1 (1+ pt))
    (char (char-after pt))
    (line-char (string-to-char "|"))
    (str (when char (compose-chars char '(tc . tc) line-char))) ) 
  (overlay-put (make-overlay pt pt+1) 'display str)
  (sit-for 2)
  (remove-overlays point-min point-max 'display str))

<小时>

示例 2,共 3 个:

以下代码片段使用称为带空格的零的 unicode 字符(即 uFEFF).由于空间无法接收前景色,因此使用背景色为零宽度空间提供了一条细长的垂直线的外观,该线延伸了整个线高.在此代码片段的上下文中使用时,零宽度空间的宽度为 1 个像素,并且连接字符的大小减小,因此两个组合字符的宽度等于 frame-char-width.此代码段的测试是在 OSX 操作系统上使用 -*-Monaco-normal-normal-normal-*-12-*-*-*-m-0-iso10646-1.在此示例中,光标会被移除一小段时间,以便可以更清楚地看到叠加层.

The following code snippet uses a unicode character known as a zero-with space (i.e., uFEFF). Because a space cannot receive a foreground color, a background color is used to give the zero-width space the apparance of a thin vertical line that stretches the entire line height. As used in the context of this code snippet, the zero-width space has a width of 1 pixel and the concatenated charcter is reduced in size so that the two combined characters have a width equal to the frame-char-width. Testing of this snippet was done on an OSX operating system using the default font of -*-Monaco-normal-normal-normal-*-12-*-*-*-m-0-iso10646-1. The cursor is removed for a short duration during this example so that the overlay can be seen more clearly.

(let* (
    (point-min (point-min))
    (point-max (point-max))
    (pt (point))
    (pt+1 (1+ pt))
    (char (char-after pt))
    (char-str (when char (char-to-string char)))
    (ln-char-str (char-to-string ?uFEFF))
    (str (when char
      (concat
        (propertize ln-char-str 'face '(:background "red"))
        (propertize char-str 'face '(:height 100))))) )
  (internal-show-cursor nil nil)
  (overlay-put (make-overlay pt pt+1) 'display str)
  (sit-for 2)
  (internal-show-cursor nil t)
  (remove-overlays point-min point-max 'display str))

<小时>

示例 3,共 3 个:

以下是对支持 xpm 图像格式的图形 Emacs 版本使用带有 xpm 图像的叠加层的示例.它是 11 像素宽;20 像素高;并有 4 种预选颜色.我在运行 Snow Leopard 10.6.8 的 Mac 上使用 Emacs 时我喜欢的字体是 -*-Courier-normal-normal-normal-*-18-*-*-*-m-0-iso10646-1 -- frame-char-width 为 11,frame-char-height 为 20.我在左边添加了一条细的垂直黄线以大写字母A"为例,说明如何绘制自定义图像.可以使用 (char-after (point)) 以编程方式替换点处的字符并取该数字 - 在本例中为大写字母A"的 65 - 并替换适当的变量——例如,(cond ((eq (char-after (point)) 65) cap-ltr-a-xpm) . . . -- 并在叠加放置中使用该变量-- 例如,(overlay-put (make-overlay (point) (1+ (point))) 'display cap-ltr-a-xpm).这对于截断的缓冲区和也使用自动换行,因为单词中间字符上的 display 覆盖属性不会导致自动换行认为单词的第一部分属于前一行的末尾.当然,创建一个收藏的 xpm 图像的自定义库需要时间.在此示例中,光标会被短暂移除,以便可以更清晰地看到叠加层.

The following is an example using an overlay with an xpm image for graphical Emacs versions that support xpm image format. It is 11 pixels wide; 20 pixels high; and has 4 preselected colors. I am on a Mac running Snow Leopard 10.6.8 and the font I prefer when using Emacs is -*-Courier-normal-normal-normal-*-18-*-*-*-m-0-iso10646-1 -- the frame-char-width is 11 and the frame-char-height is 20. I have added a thin vertical yellow line to the left of the capital letter "A" as an example of how to draw custom images. Substitution of the character at point can be made programmatically using (char-after (point)) and taking that number -- which in this case is 65 for the capital letter "A" -- and substituting the appropriate variable -- e.g., (cond ((eq (char-after (point)) 65) cap-ltr-a-xpm) . . . -- and using that variable in the the overlay placement -- e.g., (overlay-put (make-overlay (point) (1+ (point))) 'display cap-ltr-a-xpm). This works very nicely for both truncated buffers and also with word-wrap because the display overlay property on a character in the middle of a word does not cause word-wrap to think that the first part of the word belongs at the end of the previous line. Naturally, it will take time to create a custom library of favorite xpm images. The cursor is removed for a short duration during this example so that the overlay can be seen more clearly.

ImageMagick 能够根据特定的字体系列和大小生成特定字符的半准确 xpm,但它没有我希望的那么精确——这里是使用该外部实用程序的说明的链接:https://stackoverflow.com/a/14168154/2112489 简而言之,用户应该准备好花时间进行自定义他/她喜欢的 xpm 图像.

ImageMagick is capable of producing a semi-accurate xpm of a particular character based on a specific font family and size, but it was not as precise as I had hoped -- here is a link to instructions for using that external utility: https://stackoverflow.com/a/14168154/2112489 In a nutshell, the user should be prepared to spend time customizing the xpm images to his / her liking.

(let* (
    (pt (point))
    (pt+1 (1+ pt))
    (point-min (point-min))
    (point-max (point-max))
    (cap-ltr-a-xpm `(image :type xpm :mask nil :ascent center :data
      "/* XPM */
      static char * letters_xpm[] = {
      /* columns rows colors chars-per-pixel */
      /* columns = 1 pixel in width -- see also (frame-char-width) */
      /* rows = 1 pixel in height -- see also (frame-char-height) */
      "11 20 4 1",
      ". c #000000",
      "+ c #FF0000",
      "@ c #7F0000",
      "% c yellow",
      "%..........",
      "%....++....",
      "%....++....",
      "%..++..++..",
      "%..++..++..",
      "%++......++",
      "%++......++",
      "%++......++",
      "%++......++",
      "%++......++",
      "%++......++",
      "%++++++++++",
      "%++++++++++",
      "%++......++",
      "%++......++",
      "%++......++",
      "%++......++",
      "%++......++",
      "%++......++",
      "%.........."};"))  )
  (internal-show-cursor nil nil)
  (overlay-put (make-overlay pt pt+1) 'display cap-ltr-a-xpm)
  (sit-for 2)
  (internal-show-cursor nil t)
  (remove-overlays point-min point-max 'display cap-ltr-a-xpm))

下面的代码片段与上面的代码片段类似,只是它使用了after-string 显示属性.在此功能期间,光标会被短暂移除,以便更清晰地看到叠加层.

The following code snippet is similar to the one above, except it uses the after-string display property. The cursor is removed for a short duration during this function so that the overlay can be seen more clearly.

(let* (
    (point-min (point-min))
    (point-max (point-max))
    (peol (point-at-eol))
    (pilcrow `(image :type xpm :mask nil :ascent center :data
      "/* XPM */
      static char * pilcrow_xpm[] = {
      "11 20 4 1",
      ". c #000000",
      "+ c orange",
      "@ c #7F0000",
      "% c yellow",
      "%..........",
      "%..........",
      "%..........",
      "%..........",
      "%..++++++..",
      "%.++++.+...",
      "%.++++.+...",
      "%.++++.+...",
      "%..+++.+...",
      "%....+.+...",
      "%....+.+...",
      "%....+.+...",
      "%....+.+...",
      "%....+.+...",
      "%..........",
      "%..........",
      "%..........",
      "%..........",
      "%..........",
      "%.........."};"))
    (pilcrow-str (propertize " " 'display pilcrow)) )
  (overlay-put (make-overlay peol peol) 'after-string pilcrow-str)
  (sit-for 2)
  (remove-overlays point-min point-max 'after-string pilcrow-str))

<小时>

以下屏幕截图是使用第二个示例制作的.


The following screenshot was made using the second example.

这篇关于Emacs -- 如何创建垂直删除线效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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