Skip to content

Commit

Permalink
Merge pull request #1723 from lem-project/fix-the-case-where-the-afte…
Browse files Browse the repository at this point in the history
…r-change-hook-was-not-called

Fix the case where the after-change-hook was not called.
  • Loading branch information
cxxxr authored Dec 30, 2024
2 parents d160287 + 97dd9cf commit cf0e261
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/buffer/internal/buffer-insert.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,13 @@
(run-hooks (make-per-buffer-hook :var 'after-change-functions :buffer buffer)
start end old-len)))

(defun need-to-call-after-change-functions-p ()
(defun need-to-call-after-change-functions-p (buffer)
(and (not *inhibit-modification-hooks*)
(or (variable-value 'after-change-functions)
(or (variable-value 'after-change-functions :buffer buffer)
(variable-value 'after-change-functions :global))))

(defun insert/after-change-function (point arg call-next-method)
(if (need-to-call-after-change-functions-p)
(if (need-to-call-after-change-functions-p (point-buffer point))
(with-point ((start point))
(prog1 (funcall call-next-method)
(with-point ((end start))
Expand All @@ -175,7 +175,7 @@
(funcall call-next-method)))

(defun delete/after-change-function (point call-next-method)
(if (need-to-call-after-change-functions-p)
(if (need-to-call-after-change-functions-p (point-buffer point))
(let ((string (funcall call-next-method)))
(with-point ((start point)
(end point))
Expand Down
14 changes: 14 additions & 0 deletions tests/buffer/internal.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,17 @@ qrstuvwxyz"
(ok (= 5 (lem:point-charpos end-point)))
(ok (= 1 (lem:line-number-at-point point))))
(check-corruption buffer)))

(deftest call-after-change-hook
(let ((buffer (lem:make-buffer "test" :temporary t))
received-parameters)
(lem:add-hook (lem:variable-value 'lem:after-change-functions :buffer buffer)
(lambda (start end old-len)
(setf received-parameters (list start end old-len))))
(lem:insert-string (lem:buffer-point buffer) "a")
(when (ok received-parameters)
(destructuring-bind (start end old-len)
received-parameters
(ok (= 1 (lem:position-at-point start)))
(ok (= 2 (lem:position-at-point end)))
(ok (= 0 old-len))))))

0 comments on commit cf0e261

Please sign in to comment.