emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] master 449954d: Trim JSONRPC events buffer when it's too l


From: João Távora
Subject: [Emacs-diffs] master 449954d: Trim JSONRPC events buffer when it's too large
Date: Thu, 9 Aug 2018 08:04:59 -0400 (EDT)

branch: master
commit 449954dda84aa392312ab714f918a756c12adb32
Author: João Távora <address@hidden>
Commit: João Távora <address@hidden>

    Trim JSONRPC events buffer when it's too large
    
    * lisp/jsonrpc.el (Version): Bump to 1.0.2
    (jsonrpc--events-buffer-scrollback-size): New
    jsonrpc-connection slot.
    (jsonrpc--log-event): Use it to trim buffer.
---
 lisp/jsonrpc.el | 37 ++++++++++++++++++++++++++-----------
 1 file changed, 26 insertions(+), 11 deletions(-)

diff --git a/lisp/jsonrpc.el b/lisp/jsonrpc.el
index 8e1e2ab..a137616 100644
--- a/lisp/jsonrpc.el
+++ b/lisp/jsonrpc.el
@@ -6,7 +6,7 @@
 ;; Maintainer: João Távora <address@hidden>
 ;; Keywords: processes, languages, extensions
 ;; Package-Requires: ((emacs "25.2"))
-;; Version: 1.0.1
+;; Version: 1.0.2
 
 ;; This is an Elpa :core package.  Don't use functionality that is not
 ;; compatible with Emacs 25.2.
@@ -74,7 +74,11 @@
     :documentation "A hash table of request ID to continuation lambdas.")
    (-events-buffer
     :accessor jsonrpc--events-buffer
-    :documentation "A buffer pretty-printing the JSON-RPC RPC events")
+    :documentation "A buffer pretty-printing the JSONRPC events")
+   (-events-buffer-scrollback-size
+    :initarg :events-buffer-scrollback-size
+    :accessor jsonrpc--events-buffer-scrollback-size
+    :documentation "If non-nil, maximum size of events buffer.")
    (-deferred-actions
     :initform (make-hash-table :test #'equal)
     :accessor jsonrpc--deferred-actions
@@ -660,15 +664,26 @@ originated."
                       (if type
                           (format "-%s" subtype)))))
         (goto-char (point-max))
-        (let ((msg (format "%s%s%s %s:\n%s\n"
-                           type
-                           (if id (format " (id:%s)" id) "")
-                           (if error " ERROR" "")
-                           (current-time-string)
-                           (pp-to-string message))))
-          (when error
-            (setq msg (propertize msg 'face 'error)))
-          (insert-before-markers msg))))))
+        (prog1
+            (let ((msg (format "%s%s%s %s:\n%s\n"
+                               type
+                               (if id (format " (id:%s)" id) "")
+                               (if error " ERROR" "")
+                               (current-time-string)
+                               (pp-to-string message))))
+              (when error
+                (setq msg (propertize msg 'face 'error)))
+              (insert-before-markers msg))
+          ;; Trim the buffer if it's too large
+          (let ((max (jsonrpc--events-buffer-scrollback-size connection)))
+            (when max
+              (save-excursion
+                (goto-char (point-min))
+                (while (> (buffer-size) max)
+                  (delete-region (point) (progn (forward-line 1)
+                                                (forward-sexp 1)
+                                                (forward-line 2)
+                                                (point))))))))))))
 
 (provide 'jsonrpc)
 ;;; jsonrpc.el ends here



reply via email to

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