Skip to content

Commit a1ba25e

Browse files
committed
Make change timeout configurable, don't run typecheck if not needed
This is for psibi#17. It looks like there was already some intent expressed in the code to not run the after change hook if `dhall-use-header-line` was disabled, but it wasn't enacted when the hook showed up. At first I thought I might just not register the hook if `dhall-use-header-line` was disabled, but that would create confusing behavior if the user live-configured their emacs to enable that. So the hook will always fire but it will be a no-op if the type won't be used. Also for good measure I moved the timeout into an option so folks who are having performance problems but don't want to completely abandon buffer type can make a tradeoff in feedback cycle time for responsiveness. The motivation behind this is that on moderately large files, running the type check every second makes any modification to the buffer completely lock up. I'm happy to turn off the buffer type feature keep the rest of the functionality like auto-reformatting and syntax highlighting.
1 parent 5aa24b8 commit a1ba25e

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

dhall-mode.el

+9-2
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,12 @@ If specified, this should be the complete path to your dhall-format executable,
131131
:group 'dhall
132132
:safe t)
133133

134+
(defcustom dhall-type-check-inactivity-timeout 1
135+
"How long to wait in seconds between inactivity in the buffer before evaluating the buffer type. You can try increasing this if type checking is slowing things down. You can also disable type-checking entirely by setting dhall-use-header-line to nil."
136+
:type 'number
137+
:group 'dhall
138+
:safe 'numberp)
139+
134140
(defun dhall-buffer-type ()
135141
"Return the type of the expression in the current buffer."
136142
(interactive)
@@ -262,9 +268,10 @@ STRING-TYPE type of string based off of Emacs syntax table types"
262268

263269
(defun dhall-after-change (&optional _beg _end _length)
264270
"Called after any change in the buffer."
265-
(when dhall-buffer-type-compute-timer
271+
(when dhall-use-header-line
272+
(when dhall-buffer-type-compute-timer
266273
(cancel-timer dhall-buffer-type-compute-timer))
267-
(setq dhall-buffer-type-compute-timer (run-at-time 1 nil 'dhall-buffer-type-compute)))
274+
(setq dhall-buffer-type-compute-timer (run-at-time dhall-type-check-inactivity-timeout nil 'dhall-buffer-type-compute))))
268275

269276
;; The main mode functions
270277
;;;###autoload

0 commit comments

Comments
 (0)