emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[elpa] externals/gcmh 72683e1 13/32: Update conventions


From: Andrea Corallo
Subject: [elpa] externals/gcmh 72683e1 13/32: Update conventions
Date: Mon, 16 Nov 2020 17:32:05 -0500 (EST)

branch: externals/gcmh
commit 72683e169beda961628bd00089625e0f26d16390
Author: Troy Hinckley <t.macman@gmail.com>
Commit: Troy Hinckley <t.macman@gmail.com>

    Update conventions
    
    First removed the unnecessary require statements. Then update some of
    the wording to be clearer. Reworked the minor mode to be cleaner and
    more consise. Split out the idle timer function to its own definition.
    Also removed the setting of garbage-collection-messages. It may not be
    desired behavior and does not disable with the minor mode. If the user
    wants to set it, they can do so.
---
 gcmh.el | 69 ++++++++++++++++++++++++++++-------------------------------------
 1 file changed, 30 insertions(+), 39 deletions(-)

diff --git a/gcmh.el b/gcmh.el
index 40b70bf..d5762c0 100644
--- a/gcmh.el
+++ b/gcmh.el
@@ -34,37 +34,32 @@
 
 ;;; Code:
 
-(require 'custom)
-(require 'message)
-(require 'timer)
-(require 'easy-mmode)
-
 (defcustom gcmh-low-cons-threshold 800000
-  "High cons gc threshold.
-This is the gc threshold used while while idling.  Default value is \
-the same of `gc-cons-threshold' default"
+  "Low cons gc threshold.
+This is the gc threshold used while while idling. Default value
+is the same of `gc-cons-threshold' default"
   :group 'gcmh
   :type 'number)
 
 (defcustom gcmh-high-cons-threshold #x40000000
   "High cons gc threshold.
-This should be set to a value that makes GC unlikely but does not make the OS \
-paging."
+This should be set to a value that makes GC unlikely but does not
+make the OS paging."
   :group 'gcmh
   :type 'number)
 
-(defcustom gcmh-time-constant 15
+(defcustom gcmh-idle-delay 15
   "Idle time to wait in seconds before triggering GC."
   :group 'gcmh
   :type 'number)
 
 (defcustom gcmh-verbose nil
-  "If t print a message when garbage collecting."
+  "If t, print a message when garbage collecting."
   :group 'gcmh
   :type 'boolean)
 
-(defvar gcmh-timer nil
-  "Idle timer set for trigering GC.")
+(defvar gcmh-idle-timer nil
+  "Idle timer for trigering GC.")
 
 (defmacro gcmh-time (&rest body)
   "Measure and return the time it takes to evaluate BODY."
@@ -77,35 +72,31 @@ paging."
 This is to be used with the `pre-command-hook'."
   (setq gc-cons-threshold gcmh-high-cons-threshold))
 
+(defun gcmh-idle-garbage-collect ()
+  "Run garbage collection after `gcmh-idle-delay'."
+  (if gcmh-verbose
+      (message "Garbage Collector ran for %.06f sec"
+               (gcmh-time (garbage-collect)))
+    (garbage-collect))
+  (setq gc-cons-threshold gcmh-low-cons-threshold))
+
 ;;;###autoload
 (define-minor-mode gcmh-mode
-  "Minor mode tweak Garbage Collection strategy."
+  "Minor mode to tweak Garbage Collection strategy."
   :lighter " GCMH"
-  :require 'gcmh
   :global t
-  (cond
-   (gcmh-mode
-    (progn
-      (setq gc-cons-threshold gcmh-high-cons-threshold)
-      ;; Print a message when garbage collecting
-      (setq garbage-collection-messages gcmh-verbose)
-      ;; When idle for 15sec run the GC no matter what.
-      (unless gcmh-timer
-       (setq gcmh-timer
-             (run-with-idle-timer gcmh-time-constant t
-                                  (lambda ()
-                                    (if gcmh-verbose
-                                        (message "Garbage Collector has run 
for %.06fsec"
-                                                 (gcmh-time (garbage-collect)))
-                                      (garbage-collect))
-                                    (setq gc-cons-threshold 
gcmh-low-cons-threshold)))))
-      ;; Release severe GC strategy before the user restart to working
-      (add-hook 'pre-command-hook #'gcmh-set-high-threshold)))
-   (t (progn
-       (setq gc-cons-threshold gcmh-low-cons-threshold)
-       (cancel-timer gcmh-timer)
-       (setq gcmh-timer nil)
-       (remove-hook 'pre-command-hook #'gcmh-set-high-threshold)))))
+  (if gcmh-mode
+      (progn
+        (setq  gc-cons-threshold gcmh-high-cons-threshold
+               ;; When idle for gcmh-idle-delay, run the GC no matter what.
+               gcmh-idle-timer (run-with-idle-timer gcmh-idle-delay t
+                                                    
#'gcmh-idle-garbage-collect))
+        ;; Release severe GC strategy before the user restart to working
+        (add-hook 'pre-command-hook #'gcmh-set-high-threshold))
+    (cancel-timer gcmh-idle-timer)
+    (setq gc-cons-threshold gcmh-low-cons-threshold
+          gcmh-idle-timer nil)
+    (remove-hook 'pre-command-hook #'gcmh-set-high-threshold)))
 
 (provide 'gcmh)
 



reply via email to

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