tp/examples/static-properties.el
Kinneyzhang 0d35358e05 refactor(tp)!: implement retained reactive runtime
Replace the legacy managed layer renderer with one independent retained/reactive text runtime. TP now owns exact dependencies, stable objects, marker-backed mounts, property contribution composition, atomic publication, rollback, and direct text-property facades without ECSS or Ebox dependencies.\n\nBREAKING CHANGE: remove tp-render, tp-stack, scan-driven managed layers, inline runtime metadata, TP-owned CSS cascade APIs, and dollar-variable declarations.\n\nVerified: 290/290 ERT, shuffled 290/290 (seed 20260806), 8/8 doctests, WERROR compile-all, checkdoc, package-lint, diff-check, and isolated TP-only load.
2026-08-07 00:39:50 +08:00

57 lines
2.0 KiB
EmacsLisp

;;; static-properties.el --- Public API static TP property examples -*- lexical-binding: t; -*-
;; Copyright (C) 2026 Geekinney
;; SPDX-License-Identifier: GPL-3.0-or-later
;;; Commentary:
;; Examples that use only the one-shot public TP APIs: `tp-propertize` and
;; `tp-apply`. They do not rely on layer stacks, retained runtimes, or
;; managed state.
;;; Code:
(require 'tp)
(defconst tp-example-static-properties-caption-buffer-width 28
"Fixed width used by static diagnostics in this example set.")
(defvar tp-example-static-properties-keymap
(let ((map (make-sparse-keymap)))
(define-key map (kbd "RET") #'ignore)
map)
"Keymap stored literally on the static title string.")
(defun tp-example-static-properties-help (_window _object _position)
"Return help text for a static title.
WINDOW, OBJECT, and POSITION are supplied by Emacs help display."
"Static TP title")
(defun tp-example-static-properties-format-title (label)
"Return LABEL padded and styled as a static title.
LABEL is shown using native Emacs properties only.
The returned value is a propertized string (no surface, no anchor, no object)."
(let ((text (format (format "%%-%ds" tp-example-static-properties-caption-buffer-width)
label)))
(tp-propertize text
`(face ((:weight bold)
(:foreground "white" :background "#3c4656"))
keymap ,tp-example-static-properties-keymap
help-echo ,#'tp-example-static-properties-help
mouse-face nil))))
(defun tp-example-static-properties-mark-range (buffer start end &optional color)
"Apply a one-shot property run on BUFFER [START, END).
COLOR defaults to a light neutral background and preserves all existing
properties outside [START, END)."
(tp-apply buffer start end
`(face (:background ,(or color "#f0e6cc"))
help-echo "Static range marker")))
(provide 'static-properties)
;;; static-properties.el ends here