[POC] Emacs buffer 文本块渲染及布局实现

当前的方案是无法实现的,因为上边框使用的是一行的 overline 属性,而非独占一行。@yibie 的方式应该可以轻松的实现,因为边框使用的是这些特殊的 unicode 字符: ┌ ┬ ┐ ─ │ ├ ┼ ┤,字符都是独占一行。

我之前在这两种边框的实现方式选择中纠结过:使用unicode字符意味着边框和文字之间始终会有一个基础的空隙,使用 space 像素宽度的属性可以做到任意像素宽度的 padding 和 margin 的精确控制。但是这种方式的代价就是无法实现你说的这种效果。

或许我可以考虑兼容这两种情况,当在边框上设置了title,使用 unicode字符的边框,一般情况就使用 space 属性。但估计不会优先搞这个。

1 个赞

尝试用 ETML 来重绘我的 WeChat 插件。感觉效果不错:

但是现在会打印很多message

Accessing slot ‘border’ via obsolete initarg name ‘:border’ [2 times]
Accessing slot ‘margin’ via obsolete initarg name ‘:margin’ [2 times]
Accessing slot ‘padding’ via obsolete initarg name ‘:padding’ [2 times]
Accessing slot ‘justify’ via obsolete initarg name ‘:justify’
Accessing slot ‘height’ via obsolete initarg name ‘:height’

我是使用的 Emacs igc 分支,macOS

2 个赞

是不是这个分支使用的 eieio 包标记了 initarg 后续不受支持了,你可以看看你的版本的 defclass 的文档是怎么获取 slot 的,我没用过这个分支。

(defun eieio--slot-name-index (class slot)
  "In CLASS find the index of the named SLOT.
The slot is a symbol which is installed in CLASS by the `defclass' call.
If SLOT is the value created with :initarg instead,
reverse-lookup that name, and recurse with the associated slot value."
  ;; Removed checks to outside this call
  (let* ((fsi (gethash slot (cl--class-index-table class))))
    (if (integerp fsi)
        fsi
      (when eieio-backward-compatibility
	(let ((fn (eieio--initarg-to-attribute class slot)))
	  (when fn
            (when (eq eieio-backward-compatibility 'warn)
              (message "Accessing slot `%S' via obsolete initarg name `%S'"
                       fn slot))
            ;; Accessing a slot via its :initarg is accepted by EIEIO
            ;; (but not CLOS) but is a bad idea (for one: it's slower).
            (eieio--slot-name-index class fn)))))))

我看了一下代码,Message 信息是这个函数打出的。

应该是 eiei-oref 获取对象属性的值支持两种方式。

  1. (eiei-oref block :width)
  2. (eiei-oref block 'width)

第一种是通过 :initarg, 第二种是通过 slot 的名字。

使用 initarg 获取对象属性时,兼容模式下会打印信息。你可以看看,有没有必要改一下。从我这个分支的代码注释上来看,不推荐使用 initarg 来获取,可能会慢一点。

如果用 oref 来访问,两种方式的格式是:

  1. (oref block :width)
  2. (oref block width)
1 个赞

确实,30.1的也是推荐使用 slot-name 直接获取值,只不过没有打印信息。

已经修改,拉取最新的 main 分支即可,感谢反馈!

1 个赞

越看越强大 :clap: :clap: :clap:

3 个赞