emacs-diffs
[Top][All Lists]
Advanced

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

master 5d506a7eab6: gdb-mi.el: Configure variable order and length in lo


From: Eli Zaretskii
Subject: master 5d506a7eab6: gdb-mi.el: Configure variable order and length in local-vars window
Date: Sat, 10 Dec 2022 08:27:43 -0500 (EST)

branch: master
commit 5d506a7eab693bbd3ef4c9a6f2ff6e61ee5b84b7
Author: Gustaf Waldemarson <gustaf.waldemarson@gmail.com>
Commit: Eli Zaretskii <eliz@gnu.org>

    gdb-mi.el: Configure variable order and length in local-vars window
    
    This changes allows users to configure the order of various properties
    as well as truncating their length.  The full description of each
    property is available as a help-text (tooltip).
    * lisp/progmodes/gdb-mi.el (gdb-locals-table-row-config): New user
    option.
    (gdb-locals-value-filter): Don't limit the values here.
    (gdb-locals-table-columns-list): New function.
    (gdb-locals-handler-custom): Call it.  (Bug#59730)
    
    * etc/NEWS: Announce the change.
---
 etc/NEWS                 | 14 +++++++++++++
 lisp/progmodes/gdb-mi.el | 53 +++++++++++++++++++++++++++++++++++++++---------
 2 files changed, 57 insertions(+), 10 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index 61f813568f0..e92e3b84682 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -40,6 +40,20 @@ connection.
 
 
 * Changes in Specialized Modes and Packages in Emacs 30.1
+---
+** Variable order and truncation can now be configured in gdb-many-window mode.
+The new variable `gdb-locals-table-row-config' allows users to
+configure the order and max length of various properties in the local
+variables buffer when using `gdb-many-windows'.
+
+By default, this variable is set to write the properties in the order:
+name, type and value.  Where the name and type are truncated to 20
+characters, and the value is truncated to the value of
+`gdb-locals-value-limit'.
+
+In order to restore the old display behavior, set
+`gdb-locals-table-row-config' to `((type . 0)(name . 0)(value
+. ,gdb-locals-value-limit)).
 
 ** VC
 
diff --git a/lisp/progmodes/gdb-mi.el b/lisp/progmodes/gdb-mi.el
index e8d8f9104e4..9cbee50ce31 100644
--- a/lisp/progmodes/gdb-mi.el
+++ b/lisp/progmodes/gdb-mi.el
@@ -4355,6 +4355,24 @@ member."
   :group 'gud
   :version "29.1")
 
+(defcustom gdb-locals-table-row-config `((name . 20)
+                                         (type . 20)
+                                         (value . ,gdb-locals-value-limit))
+  "Configuration for table rows in the local variable display.
+
+An alist that controls the display of the name, type and value of
+local variables inside the currently active stack-frame.  The key
+controls which column to change whereas the value determines the
+maximum number of characters to display in each column.  A value
+of 0 means there is no limit.
+
+Additionally, the order the element in the alist determines the
+left-to-right display order of the properties."
+  :type '(alist :key-type 'symbol :value-type 'integer)
+  :group 'gud
+  :version "30.1")
+
+
 (defvar gdb-locals-values-table (make-hash-table :test #'equal)
   "Mapping of local variable names to a string with their value.")
 
@@ -4384,12 +4402,9 @@ member."
 
 (defun gdb-locals-value-filter (value)
   "Filter function for the local variable VALUE."
-  (let* ((no-nl (replace-regexp-in-string "\n" " " value))
-         (str (replace-regexp-in-string "[[:space:]]+" " " no-nl))
-         (limit gdb-locals-value-limit))
-    (if (>= (length str) limit)
-        (concat (substring str 0 limit) "...")
-      str)))
+  (let* ((no-nl (replace-regexp-in-string "\n" " " (or value "<Unknown>")))
+         (str (replace-regexp-in-string "[[:space:]]+" " " no-nl)))
+    str))
 
 (defun gdb-edit-locals-value (&optional event)
   "Assign a value to a variable displayed in the locals buffer."
@@ -4403,6 +4418,22 @@ member."
       (gud-basic-call
        (concat  "-gdb-set variable " var " = " value)))))
 
+
+(defun gdb-locals-table-columns-list (alist)
+  "Format and arrange the columns in locals display based on ALIST."
+  (let (columns)
+    (dolist (config gdb-locals-table-row-config columns)
+      (let* ((key  (car config))
+             (max  (cdr config))
+             (prop (alist-get key alist)))
+        (when prop
+          (if (and (> max 0) (length> prop max))
+              (push (propertize (string-truncate-left prop max) 'help-echo 
prop)
+                    columns)
+            (push prop columns)))))
+    (nreverse columns)))
+
+
 ;; Complex data types are looked up in `gdb-locals-values-table'.
 (defun gdb-locals-handler-custom ()
   "Handler to rebuild the local variables table buffer."
@@ -4431,12 +4462,14 @@ member."
                                             help-echo "mouse-2: edit value"
                                             local-map ,gdb-edit-locals-map-1)
                                value))
+        (setf (gdb-table-right-align table) t)
+        (setq name (propertize name 'font-lock-face 
font-lock-variable-name-face))
+        (setq type (propertize type 'font-lock-face font-lock-type-face))
         (gdb-table-add-row
          table
-         (list
-          (propertize type 'font-lock-face font-lock-type-face)
-          (propertize name 'font-lock-face font-lock-variable-name-face)
-          value)
+         (gdb-locals-table-columns-list `((name  . ,name)
+                                          (type  . ,type)
+                                          (value . ,value)))
          `(gdb-local-variable ,local))))
     (insert (gdb-table-string table " "))
     (setq mode-name



reply via email to

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