bug-gnu-emacs
[Top][All Lists]
Advanced

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

bug#46119: 28.0.50; this-error-recenter


From: Tino Calancha
Subject: bug#46119: 28.0.50; this-error-recenter
Date: Wed, 03 Feb 2021 14:03:09 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Juri Linkov <juri@jurta.org> writes:

> Would it be possible to avoid code duplication between
> next-error-no-select and recenter-current-error?

How about adding this macro?

(defmacro with-selected-locus (n &rest body)
  "Visit the Nth error and execute BODY, then select the previously selected 
window."
  (declare (indent 1) (debug (form body)))
  `(save-selected-window
     (let ((next-error-highlight next-error-highlight-no-select)
           (display-buffer-overriding-action
            '(nil (inhibit-same-window . t))))
       (next-error ,n)
       ,@body)))

(defun next-error-no-select (&optional n)
  "Move point to the next error in the `next-error' buffer and highlight match.
Prefix arg N says how many error messages to move forwards (or
backwards, if negative).
Finds and highlights the source line like \\[next-error], but does not
select the source buffer."
  (interactive "p")
  (with-selected-locus n))

(defun recenter-current-error (&optional arg)
  "Recenter the current displayed error in the `next-error' buffer."
  (interactive "P")
  (with-selected-locus 0
    (set-buffer (window-buffer))
    (recenter-top-bottom arg)))





reply via email to

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