emacs-devel
[Top][All Lists]
Advanced

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

recentering for next-error


From: Thien-Thi Nguyen
Subject: recentering for next-error
Date: Thu, 21 Jun 2007 11:39:25 +0200
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1.50 (gnu/linux)

sometimes i grep "lambda", and would like to see the hits `next-error'
displays such that the hit is near the top of the window w/ the body (of
the lambda) following.  the attached diff adds this recentering capability,
and additionally makes it easier to tweak.

here are two equivalent customizations to demonstrate the change:

 cur: (add-hook 'next-error-hook (lambda () (recenter 2)) t)
 new: (setq next-error-recenter 2)

to change recentering behavior, the current method requires replacing the
anonymous function in `next-error-hook' with another one.  the new method
is less cumbersome.  on the downside, expanding `next-error' "API" can be
considered unnecessary feature creep.

here is a changelog entry:

        * simple.el (next-error-recenter): New defcustom.
        (next-error, next-error-internal): Recenter if specified,
        immediately prior to running `next-error-hook'.

below is the diff.  what do people think?

thi

____________________________________
Index: simple.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/simple.el,v
retrieving revision 1.861
diff -c -r1.861 simple.el
*** simple.el   20 May 2007 03:12:20 -0000      1.861
--- simple.el   21 Jun 2007 09:15:00 -0000
***************
*** 156,161 ****
--- 156,169 ----
    :group 'next-error
    :version "22.1")
  
+ (defcustom next-error-recenter nil
+   "*Display the line in the visited source file recentered to this number.
+ If nil, don't do any recentering."
+   :type '(choice (number :tag "Argument for `recenter'")
+                  (const :tag "No recentering" nil))
+   :group 'next-error
+   :version "23.1")
+ 
  (defcustom next-error-hook nil
    "*List of hook functions run by `next-error' after visiting source file."
    :type 'hook
***************
*** 305,310 ****
--- 313,320 ----
      ;; we know here that next-error-function is a valid symbol we can funcall
      (with-current-buffer next-error-last-buffer
        (funcall next-error-function (prefix-numeric-value arg) reset)
+       (when next-error-recenter
+         (recenter next-error-recenter))
        (run-hooks 'next-error-hook))))
  
  (defun next-error-internal ()
***************
*** 313,318 ****
--- 323,330 ----
    ;; we know here that next-error-function is a valid symbol we can funcall
    (with-current-buffer next-error-last-buffer
      (funcall next-error-function 0 nil)
+     (when next-error-recenter
+       (recenter next-error-recenter))
      (run-hooks 'next-error-hook)))
  
  (defalias 'goto-next-locus 'next-error)

reply via email to

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