8

I'd love to replace the ugly pixel arrows indicating truncated or wrapped lines with simple, tasteful text (maybe even a nice unicode character, like a \u2026 ellipsis). Is this possible?

4

2 回答 2

4

不它不是。边缘“位图”实际上是位图,即 0/1 位的矢量,覆盖在边缘上。没有办法直接将任意 unicode 字符渲染到边缘。

您可以做的是自己将 unicode 字符渲染为 0/1 位图。任何体面的图像编辑器(例如 Gimp、Photoshop、Pixelmator、Paint.net 等)都可以做到这一点。然后将此位图转换为边缘位图矢量。自定义边缘位图中描述了边缘位图的格式。

最终,您可以使用这些位图矢量来替换left-arrowright-arrow(对于截断的行)left-curly-arrow、 和right-curly-arrow(对于连续的行)位图,使用函数define-fringe-bitmap.

但是,我想说这比它的价值更麻烦。边缘为 8 像素宽,因此您必须将漂亮的 unicode 字符压缩到 8x8 位图中。这意味着没有亚像素渲染,没有锯齿,没有字节码渲染,没有什么能让屏幕上的字符变得漂亮和花哨。它会和你替换的箭头一样丑陋。

于 2013-04-20T10:45:46.953 回答
0

lunaryorn 的答案是正确的,但它可能超出了 Emacs 新手用户的能力——例如,像我这样的程序员爱好者。

fringe-helper-convertNikolaj Schumacher 在他的 Fringe Helper 库中编写的函数——https: //github.com/nschum/fringe-helper.el——使像我这样的 Emacs 爱好者可以轻松创建函数使用的向量define-fringe-bitmap(在 Emacs 的 C 源代码中定义)。我选择了pilcrow,但用户可以自由创建任何适合的图像——例如,使用大写字母X和句.点,用户可以创建字母的形状。

;; AUTHOR:  Nikolaj Schumacher -- https://github.com/nschum/fringe-helper.el
(defun fringe-helper-convert (&rest strings)
"Convert STRINGS into a vector usable for `define-fringe-bitmap'.
Each string in STRINGS represents a line of the fringe bitmap.
Periods (.) are background-colored pixel; Xs are foreground-colored. The
fringe bitmap always is aligned to the right. If the fringe has half
width, only the left 4 pixels of an 8 pixel bitmap will be shown.
For example, the following code defines a diagonal line.
\(fringe-helper-convert
\"XX......\"
\"..XX....\"
\"....XX..\"
\"......XX\"\)"
  (unless (cdr strings)
  ;; only one string, probably with newlines
    (setq strings (split-string (car strings) "\n")))
  (apply 'vector
    (mapcar
      (lambda (str)
        (let ((num 0))
          (dolist (c (string-to-list str))
            (setq num (+ (* num 2) (if (eq c ?.) 0 1))))
          num))
      strings)))

下面的示例假定 aframe-char-height为 20 像素——因此位图图像与缓冲区中的文本高度相同。let-bound 代码段在行尾的右边缘创建一个枕形形状(评估代码段时的任何点)。该示例假定右边缘的宽度至少为 11——例如,(add-to-list 'default-frame-alist '(right-fringe . 11)) 转换为字符串的 unicode 符号——(char-to-string ?\uE000)可能会替换为" ".

(define-fringe-bitmap 'pilcrow (fringe-helper-convert
  "......."
  "......."
  "......."
  "......."
  "......."
  ".XXXXXX"
  "XXXX.X."
  "XXXX.X."
  "XXXX.X."
  ".XXX.X."
  "...X.X."
  "...X.X."
  "...X.X."
  "...X.X."
  "...X.X."
  "...X.X."
  "......."
  "......."
  "......."
  "......."))

(let ((peol (point-at-eol)))
  (overlay-put (make-overlay peol peol) 'after-string
    (propertize (char-to-string ?\uE000) 'display
      '(right-fringe pilcrow font-lock-keyword-face))))
于 2015-03-22T17:05:16.827 回答