1

TASK 1:

If I run C-h f goto-line(or any other function) it will open help buffer with clickable text like this.

enter image description here

If I click this text, it will open that file in a new buffer and it will take to that definition. But the point will be on last line like this.

enter image description here

TASK 2:

If I call (recenter 0), it will place point in top line like this.

enter image description here

How can I link both of these tasks, so that every time I click on a button it will place point on top line of buffer? I couldn't find any useful hooks to do these.

2 Answers 2

3

After digging through source, I failed at finding any such hook. So as a final resort you can advice the function help-button-action to recenter after jump.

(defun my-recenter-on-find-function (orig &rest args) (let ((result (apply orig args))) (when result (recenter)) result)) (advice-add 'help-button-action :around #'my-recenter-on-find-function) 

The buttons in the help-buffer are defined using define-button-type. While creating buttons one can attach additional properties to them, of these the property of interest to us is the action property which is called whenever a button is hit. Additionally a button can inherit from other buttons (which basically means the default values from parent are inherited), in our case all the buttons in help buffer inherit from help-xref button which sets the action property to help-button-action.

All this is important because the buttons in help-buffer define the properties help-function and help-args, which are used by help-button-action to jump to the definition. The interesting button here is help-function-def. We cannot advice the help-function in this case since it is a lambda (and I am not sure there is any way to advice lambdas) so the only option left is advice help-button-action

0

I think the problem is in your configuration. Maybe you have some lines for smooth scrolling in your .emacs... You can launch emacs -q and try your scenario for testing. For smooth scrolling you can do something like this:

(setq scroll-margin 3) (setq scroll-step 0) (setq scroll-conservatively 10) (setq scroll-preserve-screen-position t) 
2
  • I dont think its config problem. The code for linked text is designed just to go to that location but not re aligning position. Commented Sep 2, 2015 at 12:57
  • You really should try with emacs -q. Every time I click on this kind of link, the defun is centered (I don't think it's a coincidence). I tries with C-h f goto-line, C-h f find-file and many others ... Commented Sep 2, 2015 at 14:10

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.