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: Tue, 26 Jan 2021 22:21:16 +0100

X-Debbugs-Cc: Juri Linkov <juri@jurta.org>,uyennhi.qm@gmail.com
Severity: wishlist
Tags: patch

As a regular greper with a tiny screen I tend to use this command quite often.

Tentatively, I have named it `this-error-recenter'; if you find a
better name for it, please let me know.

--8<-----------------------------cut here---------------start------------->8---
commit 8cf1b91190013154a82a731a067cdf7d18288379
Author: Tino Calancha <ccalancha@suse.com>
Date:   Tue Jan 26 21:57:50 2021 +0100

    Add command to recenter errors from Occur/Grep buffers
    
    It allows to scroll up/down the current displayed occurrence/error
    without abandon the Occur/Grep buffer.
    
    * 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 the new command to l.
    * lisp/replace.el (occur-mode-map):
    Bind the new command to l.
    * etc/NEWS (Changes in Specialized Modes and Packages in Emacs 28.1):
    Announce it.

diff --git a/etc/NEWS b/etc/NEWS
index e038076e96..a51a6b4f63 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -454,9 +454,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..6da1dec003 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)))
+
 
 ;;;
 

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

In GNU Emacs 28.0.50 (build 9, x86_64-pc-linux-gnu, X toolkit, cairo version 
1.16.0, Xaw scroll bars)
 of 2021-01-26 built on localhost.example.com
Repository revision: 8cf1b91190013154a82a731a067cdf7d18288379
Repository branch: this-error-recenter
Windowing system distributor 'The X.Org Foundation', version 11.0.12010000
System Description: openSUSE Tumbleweed

Configured using:
 'configure --with-x-toolkit=lucid'

Configured features:
CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GSETTINGS HARFBUZZ JPEG
LIBSELINUX LIBXML2 MODULES NOTIFY INOTIFY PDUMPER PNG SOUND THREADS TIFF
TOOLKIT_SCROLL_BARS X11 XDBE XIM XPM LUCID ZLIB






reply via email to

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