When I'm in Help-mode buffer generated from describe-function or similar command - after placing cursor on clickable filename text I wish to open this file in the same window (ideally I wish I could also kill this help buffer the same time). How can I achieve that?

1 Answer 1


Here is a push-button function wrapper:

(defun eab/push-button-on-file-same-window ()
  (let ((cwc (current-window-configuration))
        (hb (current-buffer))
        (file? (button-get (button-at (point)) 'help-args)))
     `(lambda ()
        (defun eab/push-button-on-file-same-window-internal ()
          (if (> (length ',file?) 1)
              (let ((cb (current-buffer)))
                (set-window-configuration ,cwc)
                (switch-to-buffer cb)
                (kill-buffer ,hb)))))))
  (call-interactively 'push-button)
  (run-with-timer 0.01 nil 'eab/push-button-on-file-same-window-internal))

It implements required behaviour.

Upd. Removed unnecessary file-exist-p checking. Now it works for C source files.

  • I tried to bind this function to enter like this (define-key button-map (kbd "<RET>") 'eab/push-button-on-file-same-window) and it still opens file in other window, but also showing message Invalid read syntax: "?"
    – sandric
    Commented Jul 20, 2016 at 2:14
  • Yes, I've just tested it in emacs 24.3.1 and it does not work. I use emacs 24.5.1 and it works there. I will think it over.
    – artscan
    Commented Jul 20, 2016 at 2:24
  • Well, my emacs is
    – sandric
    Commented Jul 20, 2016 at 2:44
  • just a quick note - I made it work just changing in help-function-def and help-variable-def function calls of pop-to-buffer to switch-to-buffer. Its looking not very good so I'll wait for other answers though.
    – sandric
    Commented Jul 20, 2016 at 3:13
  • I've fixed time: 0.01 instead of 0. Now it works on my emacs
    – artscan
    Commented Jul 21, 2016 at 12:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.