Wilfred / helpful

A better Emacs *help* buffer
1.11k stars 62 forks source link

Suggestion: `helpful--navigate` should respect `display-buffer-alist` #316

Open ksqsf opened 1 year ago

ksqsf commented 1 year ago

I customize display-buffer-alist to control where windows and buffers should be placed inside a frame, and I use something like this for *help* buffers and helpful buffers:

(setq display-buffer-alist
  ("^\\*[Hh]elp"
    (display-buffer-reuse-window
     display-buffer-in-side-window)
    (side . right)
    (window-height . 0.4)
    (window-width . 80)
    (slot . 0)
    (dedicated . t)))

However, helpful does not respect the dedicated parameter, ie. when I press RET on a link, it opens the file in the same window as the helpful buffer, whereas the expected behavior is to visit this file in a window that is placed elsewhere, and keep the helpful window as-is. (*Help* does this correctly.)

The cause lies in helpful--navigate, which uses find-file. find-file internally uses pop-to-buffer-same-window. A corrected version is:

(defun helpful--navigate (button)
  "Navigate to the path this BUTTON represents."
  (pop-to-buffer (find-file-noselect (substring-no-properties (button-get button 'path))))
  ;; We use `get-text-property' to work around an Emacs 25 bug:
  ;; http://git.savannah.gnu.org/cgit/emacs.git/commit/?id=f7c4bad17d83297ee9a1b57552b1944020f23aea
  (-when-let (pos (get-text-property button 'position
                                     (marker-buffer button)))
    (helpful--goto-char-widen pos)))
jstamant commented 1 year ago

I agree that helpful's navigation should be changed in this way. I don't use the display-buffer-alist variable, but I've found navigation with helpful to be unintuitive. Helpful keeps trying to open links in other windows, instead of reusing the same one.