emacs-diffs
[Top][All Lists]
Advanced

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

scratch/memrep 26c76a0 3/3: Add a new function to buttonize a string


From: Lars Ingebrigtsen
Subject: scratch/memrep 26c76a0 3/3: Add a new function to buttonize a string
Date: Thu, 10 Dec 2020 20:37:51 -0500 (EST)

branch: scratch/memrep
commit 26c76a022ef1dd3cc079f9aea15cd2a7e0b12869
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    Add a new function to buttonize a string
---
 lisp/button.el                   | 12 ++++++++++++
 lisp/emacs-lisp/memory-report.el | 19 +++++++------------
 2 files changed, 19 insertions(+), 12 deletions(-)

diff --git a/lisp/button.el b/lisp/button.el
index ba06823..0d97124 100644
--- a/lisp/button.el
+++ b/lisp/button.el
@@ -613,6 +613,18 @@ button at point is the button to describe."
       (button--describe props)
       t)))
 
+(defun button-buttonize (string callback &optional data)
+  "Make STRING into a button.
+When clicked, CALLBACK will be called with the optional DATA parameter."
+  (propertize string
+              'face 'button
+              'button t
+             'follow-link t
+             'category t
+              'button-data data
+              'keymap button-map
+              'action callback))
+
 (provide 'button)
 
 ;;; button.el ends here
diff --git a/lisp/emacs-lisp/memory-report.el b/lisp/emacs-lisp/memory-report.el
index f2ea80f..10a9783 100644
--- a/lisp/emacs-lisp/memory-report.el
+++ b/lisp/emacs-lisp/memory-report.el
@@ -24,6 +24,8 @@
 ;;; Code:
 
 (require 'seq)
+(require 'subr-x)
+(eval-when-compile (require 'cl-lib))
 
 ;;;###autoload
 (defun memory-report ()
@@ -223,15 +225,9 @@
                                                       buffers)
                      do (insert (memory-report--format size)
                                 "  "
-                                (propertize
+                                (button-buttonize
                                  (buffer-name buffer)
-                                 'face 'button
-                                 'button t
-                                'follow-link t
-                                'category t
-                                 'button-data buffer
-                                 'keymap button-map
-                                 'action #'memory-report--buffer-details)
+                                 #'memory-report--buffer-details buffer)
                                 "\n"))
             (buffer-string)))))
 
@@ -239,10 +235,9 @@
   (with-current-buffer buffer
     (apply
      #'message
-     "Buffer text: %s; local variables: %s; text properties: %s; overlays: %s"
-     (mapcar
-      #'string-trim (mapcar #'memory-report--format
-                            (memory-report--buffer-data buffer))))))
+     "Buffer text: %s; variables: %s; text properties: %s; overlays: %s"
+     (mapcar #'string-trim (mapcar #'memory-report--format
+                                   (memory-report--buffer-data buffer))))))
 
 (defun memory-report--buffer (buffer)
   (seq-reduce #'+ (memory-report--buffer-data buffer) 0))



reply via email to

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