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: Mon, 01 Feb 2021 20:17:31 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Juri Linkov <juri@jurta.org> writes:

>> Do you agree with adding two separated commands?
>
> Maybe two commands is fine.  Then the users can decide what command
> better suites user's needs.

I am posting now the approach using two new commands:

--8<-----------------------------cut here---------------start------------->8---
commit 16ea65701456ce7071f56d337f518d49a03e723f
Author: Tino Calancha <ccalancha@suse.com>
Date:   Mon Feb 1 20:07:22 2021 +0100

    Add command to recenter errors from Occur/Grep buffers
    
    To scroll up/down the current displayed occurrence/error
    without abandon the Occur/Grep buffer.
    
    Add also a command 'recenter-other-window' to recenter
    the other window from any kind of buffer.
    
    * lisp/window.el (recenter-other-window): New command.
    Bind recenter-other-window to M-C-l.
    
    * lisp/simple.el (this-error-recenter): New command.
    * lisp/progmodes/grep.el (grep-mode-map):
    Delete bidings for n and p.
    
    * lisp/progmodes/compile.el (compilation-minor-mode-map):
    Move here the n and p bindings.
    Bind `this-error-recenter' to l.
    * lisp/replace.el (occur-mode-map):
    Same.
    
    * etc/NEWS (Changes in Specialized Modes and Packages in Emacs 28.1):
    Announce the changes.

diff --git a/etc/NEWS b/etc/NEWS
index e038076e96..dbe53b3f29 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -85,6 +85,8 @@ useful on systems such as FreeBSD which ships only with 
"etc/termcap".
 
 * Changes in Emacs 28.1
 
+** The new command 'recenter-other-window' is bound to 'M-C-l'.
+
 ** The new NonGNU ELPA archive is enabled by default alongside GNU ELPA
 
 ** Minibuffer scrolling is now conservative by default.
@@ -454,9 +456,15 @@ applied when the option 'tab-line-tab-face-functions' is
 so-configured.  That option may also be used to customize tab-line
 faces in other ways.
 
-** New bindings in occur-mode, 'next-error-no-select' bound to 'n' and
+** Occur mode
+
+*** New bindings in occur-mode, 'next-error-no-select' bound to 'n' and
 'previous-error-no-select' bound to 'p'.
 
+*** The new command 'this-error-recenter', bound to 'l', recenters the
+current displayed occurrence from a Occur buffer and the current
+displayed error in a compilation buffer.
+
 ** EIEIO
 
 +++
diff --git a/lisp/progmodes/compile.el b/lisp/progmodes/compile.el
index 94e4f3c6fa..1031f835f8 100644
--- a/lisp/progmodes/compile.el
+++ b/lisp/progmodes/compile.el
@@ -2073,6 +2073,10 @@ compilation-minor-mode-map
     (define-key map "\M-p" 'compilation-previous-error)
     (define-key map "\M-{" 'compilation-previous-file)
     (define-key map "\M-}" 'compilation-next-file)
+    (define-key map "n" 'next-error-no-select)
+    (define-key map "p" 'previous-error-no-select)
+    (define-key map "l" 'this-error-recenter)
+
     (define-key map "g" 'recompile) ; revert
     ;; Set up the menu-bar
     (define-key map [menu-bar compilation]
diff --git a/lisp/progmodes/grep.el b/lisp/progmodes/grep.el
index 1a8435fde3..d6ee8bb423 100644
--- a/lisp/progmodes/grep.el
+++ b/lisp/progmodes/grep.el
@@ -275,8 +275,6 @@ grep-mode-map
     (define-key map "\C-c\C-f" 'next-error-follow-minor-mode)
 
     (define-key map "\r" 'compile-goto-error)  ;; ?
-    (define-key map "n" 'next-error-no-select)
-    (define-key map "p" 'previous-error-no-select)
     (define-key map "{" 'compilation-previous-file)
     (define-key map "}" 'compilation-next-file)
     (define-key map "\t" 'compilation-next-error)
diff --git a/lisp/replace.el b/lisp/replace.el
index db5b340631..bd3a96a26e 100644
--- a/lisp/replace.el
+++ b/lisp/replace.el
@@ -1135,6 +1135,7 @@ occur-mode-map
     (define-key map "\C-o" 'occur-mode-display-occurrence)
     (define-key map "n" 'next-error-no-select)
     (define-key map "p" 'previous-error-no-select)
+    (define-key map "l" 'this-error-recenter)
     (define-key map "\M-n" 'occur-next)
     (define-key map "\M-p" 'occur-prev)
     (define-key map "r" 'occur-rename-buffer)
diff --git a/lisp/simple.el b/lisp/simple.el
index c878fdab92..31a2ac3c88 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -496,6 +496,16 @@ next-error-message-highlight
         (overlay-put ol 'window (get-buffer-window))
         (setf next-error--message-highlight-overlay ol)))))
 
+(defun this-error-recenter (&optional arg)
+  "Recenter the current displayed error in the `next-error' buffer."
+  (interactive "P")
+  (if (not (or (eq major-mode 'occur-mode) (derived-mode-p 'compilation-mode)))
+      (user-error "This command is for *Occur* or *Grep* buffers")
+    (funcall next-error-function 0 nil)
+    (recenter-top-bottom arg)
+    (pop-to-buffer next-error-last-buffer)))
+
+
 
 ;;;
 
diff --git a/lisp/window.el b/lisp/window.el
index 0a37d16273..c75ed90ef5 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -9771,6 +9771,19 @@ recenter-top-bottom
 
 (define-key global-map [?\C-l] 'recenter-top-bottom)
 
+(defun recenter-other-window (&optional arg)
+  "Call `recenter-top-bottom' in the other window.
+
+A prefix argument is handled like `recenter':
+ With numeric prefix ARG, move current line to window-line ARG.
+ With plain `C-u', move current line to window center."
+  (interactive "P")
+  (with-selected-window (other-window-for-scrolling)
+    (recenter-top-bottom arg)
+    (pulse-momentary-highlight-one-line (point))))
+
+(define-key global-map [?\M-\C-l] 'recenter-other-window)
+
 (defun move-to-window-line-top-bottom (&optional arg)
   "Position point relative to window.
 

--8<-----------------------------cut here---------------end--------------->8---





reply via email to

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