emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 2612488: Support inserting images in tabulated-list-mode columns


From: Stefan Kangas
Subject: master 2612488: Support inserting images in tabulated-list-mode columns
Date: Tue, 2 Nov 2021 12:45:04 -0400 (EDT)

branch: master
commit 2612488c36e6306f3624bb9082004b499f9da354
Author: Stefan Kangas <stefan@marxist.se>
Commit: Stefan Kangas <stefan@marxist.se>

    Support inserting images in tabulated-list-mode columns
    
    * lisp/emacs-lisp/tabulated-list.el (tabulated-list-print-col):
    Support using an image descriptor to insert an image in a column.
    (tabulated-list-entries):
    * doc/lispref/modes.texi (Tabulated List Mode): Update documentation
    to reflect above change.
---
 doc/lispref/modes.texi            |  9 +++++----
 etc/NEWS                          |  8 ++++++++
 lisp/emacs-lisp/tabulated-list.el | 37 ++++++++++++++++++++++++++-----------
 3 files changed, 39 insertions(+), 15 deletions(-)

diff --git a/doc/lispref/modes.texi b/doc/lispref/modes.texi
index 1db991e..ee19da5 100644
--- a/doc/lispref/modes.texi
+++ b/doc/lispref/modes.texi
@@ -1150,10 +1150,11 @@ re-sorting entries.  Comparison is done with 
@code{equal}.
 @item
 @var{contents} is a vector with the same number of elements as
 @code{tabulated-list-format}.  Each vector element is either a string,
-which is inserted into the buffer as-is, or a list @code{(@var{label}
-. @var{properties})}, which means to insert a text button by calling
-@code{insert-text-button} with @var{label} and @var{properties} as
-arguments (@pxref{Making Buttons}).
+which is inserted into the buffer as-is, an image descriptor, which is
+used to insert an image (@pxref{Image Descriptors}), or a list
+@code{(@var{label} . @var{properties})}, which means to insert a text
+button by calling @code{insert-text-button} with @var{label} and
+@var{properties} as arguments (@pxref{Making Buttons}).
 
 There should be no newlines in any of these strings.
 @end itemize
diff --git a/etc/NEWS b/etc/NEWS
index 73f7607..211d943 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -406,6 +406,14 @@ This holds the value of the previous call to 
'set-locale-environment'.
 This macro can be used to change the locale temporarily while
 executing code.
 
+** Tabulated List Mode
+
++++
+*** A column can now be set to an image descriptor.
+The `tabulated-list-entries' variable now supports using an image
+descriptor, which means to insert an image in that column instead of
+text.  See the documentation string of that variable for details.
+
 +++
 ** 'define-key' now understands a new strict 'kbd' representation for keys.
 The '(define-key map ["C-c M-f"] #'some-command)' syntax is now
diff --git a/lisp/emacs-lisp/tabulated-list.el 
b/lisp/emacs-lisp/tabulated-list.el
index 0ae355e..8f6c655 100644
--- a/lisp/emacs-lisp/tabulated-list.el
+++ b/lisp/emacs-lisp/tabulated-list.el
@@ -115,16 +115,25 @@ where:
 This should be either a function, or a list.
 If a list, each element has the form (ID [DESC1 ... DESCN]),
 where:
+
  - ID is nil, or a Lisp object uniquely identifying this entry,
    which is used to keep the cursor on the \"same\" entry when
    rearranging the list.  Comparison is done with `equal'.
 
  - Each DESC is a column descriptor, one for each column
-   specified in `tabulated-list-format'.  A descriptor is either
-   a string, which is printed as-is, or a list (LABEL . PROPS),
-   which means to use `insert-text-button' to insert a text
-   button with label LABEL and button properties PROPS.
-   The string, or button label, must not contain any newline.
+   specified in `tabulated-list-format'.  The descriptor DESC is
+   one of:
+
+    - A string, which is printed as-is, and must not contain any
+      newlines.
+
+    - An image descriptor (a list), which is used to insert an
+      image (see Info node `(elisp) Image Descriptors').
+
+    - A list (LABEL . PROPS), which means to use
+      `insert-text-button' to insert a text button with label
+      LABEL and button properties PROPS.  LABEL must not contain
+      any newlines.
 
 If `tabulated-list-entries' is a function, it is called with no
 arguments and must return a list of the above form.")
@@ -547,7 +556,9 @@ Return the column number after insertion."
         (props     (nthcdr 3 format))
         (pad-right (or (plist-get props :pad-right) 1))
          (right-align (plist-get props :right-align))
-        (label     (if (stringp col-desc) col-desc (car col-desc)))
+         (label (cond ((stringp col-desc) col-desc)
+                      ((eq (car col-desc) 'image) " ")
+                      (t (car col-desc))))
          (label-width (string-width label))
         (help-echo (concat (car format) ": " label))
         (opoint (point))
@@ -571,11 +582,15 @@ Return the column number after insertion."
                             'display `(space :align-to ,(+ x shift))))
         (setq width (- width shift))
         (setq x (+ x shift))))
-    (if (stringp col-desc)
-       (insert (if (get-text-property 0 'help-echo label)
-                   label
-                 (propertize label 'help-echo help-echo)))
-      (apply 'insert-text-button label (cdr col-desc)))
+    (cond ((stringp col-desc)
+           (insert (if (get-text-property 0 'help-echo label)
+                       label
+                     (propertize label 'help-echo help-echo))))
+          ((eq (car col-desc) 'image)
+           (insert (propertize " "
+                               'display col-desc
+                               'help-echo help-echo)))
+          ((apply 'insert-text-button label (cdr col-desc))))
     (let ((next-x (+ x pad-right width)))
       ;; No need to append any spaces if this is the last column.
       (when not-last-col



reply via email to

[Prev in Thread] Current Thread [Next in Thread]