Twidget - Emacs中的文本控件库

更新: twidget-text 支持多个 widget,新增属性 :textarea

1.我们知道 :format 属性值中的 [t] 代表一个widget, 渲染时会被替代成value值。现在支持多个widget,写法是 [t0], [t1], [t2]…, value 值为一个列表。例子:

(defvar twidget-text-format
  "Emacs is a family of [t0] that are characterized by their extensibility. The manual for the most widely used variant, [t1], describes it as \"the [t2], [t3], [t4], real-time display editor\". Development of the first Emacs began in the mid-1970s, and work on its direct descendant, GNU Emacs, continues actively as of 2021.")

(with-twidget-buffer "*Twidget Test*"
  (set-window-margins (selected-window) 3 3)
  (twidget-insert
   (propertize "♨ Twidget Test" 'face '(bold :height 1.4)))
  (twidget-insert
   "\n\n" (propertize "Emacs" 'face '(bold :height 1.2))
   "\n\nFrom Wikipedia, the free encyclopedia\n\n")
  (twidget-create 'twidget-text
    :bind 'twidget-test1
    :format twidget-text-format ;; multiple text widget
    :value '("text editors" "GNU Emacs" nil nil "self-documenting")
    :length 5))

twidget-multitext

2.当 :textarea 属性的值为 t 时,表示该控件是一个文本框。文本框输入时会在底部弹出一个 side window。在buffer中显示时会自动在控件前后换行。例子

(defvar notebook-default-content
  "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.")

(with-twidget-buffer "*Notebook*"
  (set-window-margins (selected-window) 3 3)
  (twidget-insert (propertize "📗 Notebook" 'face '(bold :height 1.5)))
  (twidget-insert "\n\n")
  (twidget-create 'twidget-text
    :bind 'notebook-note-title
    :format "Note title: [t]"
    :value "Default title")
  (twidget-insert "\n\n")
  (twidget-create 'twidget-text
    :bind 'notebook-note-content
    :format "Note content:\n[t]"
    :value notebook-default-content
    :textarea t) ;; a textarea widget.
  (twidget-insert "\n")
  (twidget-create 'twidget-choice
    :bind 'notebook-album
    :choices '("Default" "life" "study")
    :format "Choose notebook [t] "
    :separator "/"
    :value "Default")
  (twidget-create 'twidget-button
    :value "Add"))

twidget-textarea

3 个赞