[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/beardbolt 041234b499 241/323: Improve auto-compilation
From: |
ELPA Syncer |
Subject: |
[elpa] externals/beardbolt 041234b499 241/323: Improve auto-compilation |
Date: |
Thu, 9 Mar 2023 10:58:35 -0500 (EST) |
branch: externals/beardbolt
commit 041234b499c6d7b38bedf4ff88934efc08e1e065
Author: Erik Arvstedt <erik.arvstedt@gmail.com>
Commit: Erik Arvstedt <erik.arvstedt@gmail.com>
Improve auto-compilation
- Start the auto-compilation when the src buffer has been unchanged for
`rmsbolt-compile-delay` seconds.
Previously, auto-compilation ran with a fixed timer, which could
trigger while the user was typing.
This also removes the last remaining global timer.
Because of this change and the previous commit
(`Auto stop an existing compilation`), we can decrease the default
`rmsbolt-compile-delay` while keeping the UI updating smoothly.
- Support the new `rmsbolt-automatic-recompile` value `on-save`.
When set, auto-compilation is only run when the buffer is saved.
- Enable auto-compilation for emacs-lisp-mode, which works just fine.
---
rmsbolt.el | 98 +++++++++++++++++++++++++++++++++++---------------------------
1 file changed, 55 insertions(+), 43 deletions(-)
diff --git a/rmsbolt.el b/rmsbolt.el
index 4aa50f9264..ae6a7e1e35 100644
--- a/rmsbolt.el
+++ b/rmsbolt.el
@@ -100,11 +100,14 @@
:type 'integer
:group 'rmsbolt)
(defcustom rmsbolt-automatic-recompile t
- "Whether to automatically recompile on source buffer changes.
-Emacs-lisp does not support automatic-recompilation currently.
-This setting is automatically disabled on large buffers, use
-'force to force-enable it."
- :type 'boolean
+ "Whether to automatically save and recompile the source buffer.
+This setting is automatically disabled on large buffers, set
+'force to force-enable it.
+To only recompile when the buffer is manually saved, set 'on-save."
+ :type '(choice (const :tag "Off" nil)
+ (const :tag "On save" on-save)
+ (const :tag "On" t)
+ (const :tag "Always" force))
:group 'rmsbolt)
;;;;; Buffer Local Tweakables
@@ -224,7 +227,7 @@ may not be cleared to default as variables are usually."
(defvar rmsbolt-overlays nil
"List of overlays to use.")
-(defvar rmsbolt-compile-delay 1
+(defvar rmsbolt-compile-delay 0.4
"Time in seconds to delay before recompiling if there is a change.")
(defvar rmsbolt--automated-compile nil
"Whether this compile was automated or not.")
@@ -232,10 +235,6 @@ may not be cleared to default as variables are usually."
"Which shell to prefer if available.
Used to work around inconsistencies in alternative shells.")
-(defvar rmsbolt--idle-timer nil
- "Idle timer for rmsbolt overlays.")
-(defvar rmsbolt--compile-idle-timer nil
- "Idle timer for rmsbolt overlays.")
(defvar rmsbolt--temp-dir nil
"Temporary directory to use for compilation and other reasons.
@@ -1749,32 +1748,43 @@ and return it."
(eq (current-buffer) (buffer-local-value 'rmsbolt-src-buffer
output-buffer)))
(rmsbolt--remove-overlays))))
-(defun rmsbolt-hot-recompile ()
- "Recompile source buffer if we need to."
- (when-let ((should-hot-compile rmsbolt-mode)
- (should-hot-recompile rmsbolt-automatic-recompile)
- (output-buffer (get-buffer rmsbolt-output-buffer))
- (src-buffer (buffer-local-value 'rmsbolt-src-buffer
output-buffer))
- (src-buffer-live (buffer-live-p src-buffer))
- (is-not-elisp (not (eq 'emacs-lisp-mode
- (with-current-buffer src-buffer
- major-mode))))
- (is-not-large (or (< (with-current-buffer src-buffer
- (line-number-at-pos (point-max)))
- rmsbolt-large-buffer-size)
- (eq rmsbolt-automatic-recompile 'force)))
- (modified (buffer-modified-p src-buffer)))
- (with-current-buffer src-buffer
- ;; Clear `before-save-hook' to prevent things like whitespace cleanup or
- ;; aggressive indent from running (this is a hot recompile):
- ;;
https://github.com/syl20bnr/spacemacs/blob/c7a103a772d808101d7635ec10f292ab9202d9ee/layers/%2Bspacemacs/spacemacs-editing/local/spacemacs-whitespace-cleanup/spacemacs-whitespace-cleanup.el#L72
- ;; TODO does anyone want before-save-hook to run on a hot recompile?
- (let ((before-save-hook nil))
- ;; Write to disk
- (save-buffer))
- ;; Recompile
- (setq rmsbolt--automated-compile t)
- (rmsbolt-compile))))
+(defun rmsbolt--is-active-src-buffer ()
+ (when-let (output-buffer (get-buffer rmsbolt-output-buffer))
+ (eq (current-buffer) (buffer-local-value 'rmsbolt-src-buffer
output-buffer))))
+
+(defun rmsbolt--after-save ()
+ (when (and (rmsbolt--is-active-src-buffer)
+ rmsbolt-automatic-recompile)
+ (setq rmsbolt--automated-compile t)
+ (rmsbolt-compile)))
+
+;; Auto-save the src buffer after it has been unchanged for
`rmsbolt-compile-delay' seconds.
+;; The buffer is then automatically recompiled via `rmsbolt--after-save'.
+(defvar rmsbolt--change-timer nil)
+(defvar rmsbolt--buffer-to-auto-save nil)
+
+(defun rmsbolt--after-change (&rest _)
+ (when (and (rmsbolt--is-active-src-buffer)
+ rmsbolt-automatic-recompile
+ (not (eq rmsbolt-automatic-recompile 'on-save)))
+ (when rmsbolt--change-timer
+ (cancel-timer rmsbolt--change-timer))
+ (setq rmsbolt--buffer-to-auto-save (current-buffer)
+ rmsbolt--change-timer (run-with-timer rmsbolt-compile-delay nil
#'rmsbolt--on-change-timer))))
+
+(defun rmsbolt--on-change-timer ()
+ (setq rmsbolt--change-timer nil)
+ (when (buffer-live-p rmsbolt--buffer-to-auto-save)
+ (with-current-buffer rmsbolt--buffer-to-auto-save
+ (setq rmsbolt--buffer-to-auto-save nil)
+ (when (or (< (line-number-at-pos (point-max)) rmsbolt-large-buffer-size)
+ (eq rmsbolt-automatic-recompile 'force))
+ ;; Clear `before-save-hook' to prevent things like whitespace cleanup
+ ;; (e.g., set by spacemacs in `spacemacs-whitespace-cleanup.el`)
+ ;; and aggressive indenting from running (this is a hot recompile).
+ ;; TODO does anyone want before-save-hook to run on a hot recompile?
+ (let ((before-save-hook nil))
+ (save-buffer))))))
;;;; Mode Definition:
@@ -1794,16 +1804,18 @@ This mode is enabled in both src and assembly output
buffers."
(add-hook 'post-command-hook #'rmsbolt--post-command-hook nil t)
(add-hook 'kill-buffer-hook #'rmsbolt--on-kill-buffer nil t)
- ;; This idle timer always runs, even when we aren't in rmsbolt-mode
- ;; It won't do anything unless we are in rmsbolt-mode
- (unless (or rmsbolt--compile-idle-timer
- (not rmsbolt-automatic-recompile))
- (setq rmsbolt--compile-idle-timer (run-with-idle-timer
- rmsbolt-compile-delay t
- #'rmsbolt-hot-recompile)))
+ (when (and rmsbolt-automatic-recompile
+ ;; Only turn on auto-save in src buffers
+ (not (eq (current-buffer) (get-buffer rmsbolt-output-buffer))))
+ (add-hook 'after-save-hook #'rmsbolt--after-save nil t)
+ (when (eq rmsbolt-automatic-recompile t)
+ (add-hook 'after-change-functions #'rmsbolt--after-change nil t)))
+
(rmsbolt--gen-temp))
(t ;; Cleanup
(rmsbolt--remove-overlays)
+ (remove-hook 'after-change-functions #'rmsbolt--after-change t)
+ (remove-hook 'after-save-hook #'rmsbolt--after-save t)
(remove-hook 'kill-buffer-hook #'rmsbolt--on-kill-buffer t)
(remove-hook 'post-command-hook #'rmsbolt--post-command-hook t))))
- [elpa] externals/beardbolt 246377bbff 173/323: Add dummy panic handler to reduce size of zig diassembly, (continued)
- [elpa] externals/beardbolt 246377bbff 173/323: Add dummy panic handler to reduce size of zig diassembly, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 73dcaca98d 177/323: Remove unneeded variables, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 28ccabf318 190/323: Clean up overlays and simplify hook when asm buffer is closed, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 3a8964d537 204/323: Update Readme, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 7c81d55d3e 202/323: Format go block, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 9b1a5abbdf 208/323: Strip -flto flag from compile_commands.json by default, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt d257e51fce 244/323: starters/zig: Automatically export functions, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt ebbdebc66f 239/323: Improve compilation buffer display UX, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt f6b72fe0eb 248/323: First stab at rainbow overlays, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 3cace942b8 251/323: Fix buffer selection problems, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 041234b499 241/323: Improve auto-compilation,
ELPA Syncer <=
- [elpa] externals/beardbolt 2421b29094 255/323: Remove .ert-runner, .gitlab-ci.yml and Cask, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 49e2500be1 259/323: Use shorthands so I can just type bb- instead of beardbolt-, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 58b07a215c 268/323: Simplify some code, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 9f6d1cf10c 269/323: Remove some rmsbolt remnants, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 5deed3972e 276/323: * beardbolt.el (bb--reachable-p, bb--process-asm): Use obarrays., ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 291f82a324 266/323: Continue rewriting, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 3195997ccd 275/323: * beardbolt.el (bb--synch-relation-overlays): Rework and bugfix., ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt a13f8fe7f4 287/323: Reset beardbolt-specific locals before hacking them in, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 85d24d69f1 286/323: Add bb-kill-symbol-re option, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 10fe7307c3 291/323: Get a better C++ starter example, ELPA Syncer, 2023/03/09