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?
Asked
Active
Viewed 225 times
2

sandric
- 1,221
- 9
- 19
1 Answers
1
Here is a push-button
function wrapper:
(defun eab/push-button-on-file-same-window ()
(interactive)
(let ((cwc (current-window-configuration))
(hb (current-buffer))
(file? (button-get (button-at (point)) 'help-args)))
(funcall
`(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.

artscan
- 445
- 2
- 12
-
I tried to bind this function to enter like this `(define-key button-map (kbd "
") 'eab/push-button-on-file-same-window)` and it still opens file in other window, but also showing message `Invalid read syntax: "?"` – sandric Jul 20 '16 at 02: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 Jul 20 '16 at 02:24
-
Well, my emacs is 25.1.50.1 – sandric Jul 20 '16 at 02: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 Jul 20 '16 at 03:13
-
I've fixed time: 0.01 instead of 0. Now it works on my emacs 25.1.50.2 – artscan Jul 21 '16 at 12:17