Skip to content

Commit

Permalink
fix: preserve point before widening and re-narrowing
Browse files Browse the repository at this point in the history
Some languages can narrow to a region not including point when
invoking narrow-to-defun.  This will cause the cursor to jump around
when the restriction is restored.

To prevent this, remember also the original point.
  • Loading branch information
Fuco1 committed Feb 12, 2023
1 parent b9bb6e4 commit 7c4bf1e
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions highlight-thing.el
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,16 @@ functionality."

(defun highlight-thing-buffer-do (buf regex)
(with-current-buffer buf
(save-restriction
(widen)
(cond ((highlight-thing-should-narrow-to-defun-p)
(narrow-to-defun))
((highlight-thing-should-narrow-to-region-p)
(let ((bounds (highlight-thing-narrow-bounds)))
(narrow-to-region (car bounds) (cdr bounds)))))
(highlight-thing-call-highlight-regexp regex)
(when highlight-thing-exclude-thing-under-point (highlight-thing-remove-overlays-at-point regex)))))
(save-excursion
(save-restriction
(widen)
(cond ((highlight-thing-should-narrow-to-defun-p)
(narrow-to-defun))
((highlight-thing-should-narrow-to-region-p)
(let ((bounds (highlight-thing-narrow-bounds)))
(narrow-to-region (car bounds) (cdr bounds)))))
(highlight-thing-call-highlight-regexp regex)
(when highlight-thing-exclude-thing-under-point (highlight-thing-remove-overlays-at-point regex))))))

(defun highlight-thing-call-highlight-regexp (regex)
(unless (string= "" regex)
Expand Down

0 comments on commit 7c4bf1e

Please sign in to comment.