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
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.
- 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 messageInvalid read syntax: "?"sandric– sandric2016-07-20 02:14:31 +00:00Commented 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– artscan2016-07-20 02:24:46 +00:00Commented Jul 20, 2016 at 2:24
- Well, my emacs is 25.1.50.1sandric– sandric2016-07-20 02:44:46 +00:00Commented Jul 20, 2016 at 2:44
- just a quick note - I made it work just changing in
help-function-defandhelp-variable-deffunction calls ofpop-to-buffertoswitch-to-buffer. Its looking not very good so I'll wait for other answers though.sandric– sandric2016-07-20 03:13:58 +00:00Commented Jul 20, 2016 at 3:13 - I've fixed time: 0.01 instead of 0. Now it works on my emacs 25.1.50.2artscan– artscan2016-07-21 12:17:00 +00:00Commented Jul 21, 2016 at 12:17