unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* recentering for next-error
@ 2007-06-21  9:39 Thien-Thi Nguyen
  2007-06-21  9:50 ` Andreas Schwab
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Thien-Thi Nguyen @ 2007-06-21  9:39 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 962 bytes --]

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

____________________________________

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: .ttn.diff --]
[-- Type: text/x-diff, Size: 1582 bytes --]

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)

[-- Attachment #3: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: recentering for next-error
  2007-06-21  9:39 recentering for next-error Thien-Thi Nguyen
@ 2007-06-21  9:50 ` Andreas Schwab
  2007-06-22  1:51 ` Richard Stallman
  2007-06-22 19:32 ` Juri Linkov
  2 siblings, 0 replies; 6+ messages in thread
From: Andreas Schwab @ 2007-06-21  9:50 UTC (permalink / raw)
  To: Thien-Thi Nguyen; +Cc: emacs-devel

Thien-Thi Nguyen <ttn@gnuvola.org> writes:

> 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.

You could use a named function instead, or make it use a variable
instead of hardcoding the number.  This variable could even be named
next-error-recenter.

Andreas.

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: recentering for next-error
  2007-06-21  9:39 recentering for next-error Thien-Thi Nguyen
  2007-06-21  9:50 ` Andreas Schwab
@ 2007-06-22  1:51 ` Richard Stallman
  2007-06-22 19:32 ` Juri Linkov
  2 siblings, 0 replies; 6+ messages in thread
From: Richard Stallman @ 2007-06-22  1:51 UTC (permalink / raw)
  To: Thien-Thi Nguyen; +Cc: emacs-devel

It looks good; please install it in the trunk.
(Please add it to NEWS too.)

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: recentering for next-error
  2007-06-21  9:39 recentering for next-error Thien-Thi Nguyen
  2007-06-21  9:50 ` Andreas Schwab
  2007-06-22  1:51 ` Richard Stallman
@ 2007-06-22 19:32 ` Juri Linkov
  2007-06-22 22:11   ` Thien-Thi Nguyen
  2 siblings, 1 reply; 6+ messages in thread
From: Juri Linkov @ 2007-06-22 19:32 UTC (permalink / raw)
  To: Thien-Thi Nguyen; +Cc: emacs-devel

> 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.

One of the allowed arguments of `recenter' is C-u that means putting point
in the center of the window.  This is useful argument for next-error to put
the source line to the center of the window.  But when I set the `recenter'
argument in the Customization buffer to the value `(4)', this doesn't work.

-- 
Juri Linkov
http://www.jurta.org/emacs/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: recentering for next-error
  2007-06-22 19:32 ` Juri Linkov
@ 2007-06-22 22:11   ` Thien-Thi Nguyen
  2007-06-22 22:22     ` Juri Linkov
  0 siblings, 1 reply; 6+ messages in thread
From: Thien-Thi Nguyen @ 2007-06-22 22:11 UTC (permalink / raw)
  To: Juri Linkov; +Cc: emacs-devel

() Juri Linkov <juri@jurta.org>
() Fri, 22 Jun 2007 22:32:23 +0300

   when I set the `recenter' argument in the Customization
   buffer to the value `(4)', this doesn't work.

i see expected behavior using:

  (setq next-error-recenter '(4))

presently, the defcustom for next-error-recenter permits only
numbers and nil.  how about this one?

(defcustom next-error-recenter nil
  "*Display the line in the visited source file recentered as specified.
If non-nil, the value is passed directly to `recenter'."
  :type '(choice (integer :tag "Line to recenter to")
                 (const :tag "Center of window" (4))
                 (const :tag "No recentering" nil))
  :group 'next-error
  :version "23.1")

changes: s/number/integer/, add const (4), docstring update.

thi

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: recentering for next-error
  2007-06-22 22:11   ` Thien-Thi Nguyen
@ 2007-06-22 22:22     ` Juri Linkov
  0 siblings, 0 replies; 6+ messages in thread
From: Juri Linkov @ 2007-06-22 22:22 UTC (permalink / raw)
  To: Thien-Thi Nguyen; +Cc: emacs-devel

> presently, the defcustom for next-error-recenter permits only
> numbers and nil.  how about this one?
>
> (defcustom next-error-recenter nil
>   "*Display the line in the visited source file recentered as specified.
> If non-nil, the value is passed directly to `recenter'."
>   :type '(choice (integer :tag "Line to recenter to")
>                  (const :tag "Center of window" (4))
>                  (const :tag "No recentering" nil))
>   :group 'next-error
>   :version "23.1")
>
> changes: s/number/integer/, add const (4), docstring update.

Thanks, it works.

-- 
Juri Linkov
http://www.jurta.org/emacs/

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2007-06-22 22:22 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-06-21  9:39 recentering for next-error Thien-Thi Nguyen
2007-06-21  9:50 ` Andreas Schwab
2007-06-22  1:51 ` Richard Stallman
2007-06-22 19:32 ` Juri Linkov
2007-06-22 22:11   ` Thien-Thi Nguyen
2007-06-22 22:22     ` Juri Linkov

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).