1

I have a number of macros for browsing source code for many emacs versions. I wrote this in 2009 and it's been solid until upgrading to U18.04. I know it worked in U16.04:

(defun get-file-from-buffer-other-window ()
  "Load a file into another window referenced by the string on the current line"
  (interactive)

;; get the filename and lineno (setq vals (get-fileline)) (print vals)

;; load the filename into the next window and goto linenumber (switch-to-buffer-other-window (find-file-noselect (nth 0 vals))) (goto-line (nth 1 vals)) )

I split a frame and have a file list in one window, select a file from the list, which loads it into a buffer and loads the buffer in the other window. Two windows in the frame.

In the new version 25.2.2, the default behavior changed. Now selecting a file opens a NEW window in the frame. Look at five files (key bind to f8) and five new windows are created. I traced the issue to the windows.el display-buffer macro. There is a tuning action named display-buffer-base-action. I try changing the behavior, specifically to display-buffer-reuse-window but cannot get it to recreate the behavior emacs has defaulted since I wrote it in 2009. WTF?

Any ideas? I'm sure it is something to do with display-buffer-reuse-window and this documentation. https://www.gnu.org/software/emacs/manual/html_node/elisp/Precedence-of-Action-Functions.html

Dave

dturvene
  • 121
  • 4
  • Incidentally, the primary macro to load the file/buffer into the existing window works fine using switch-to-buffer. But then I lose the source file list. I have additional macros that search the source file list for regex patterns and then I can click on the file/lines that match the pattern. Much more helpful to search a large code base than tags. – dturvene Apr 26 '19 at 19:11
  • I'm testing with the following macros in a frame with two windows. foo should be loaded in a new window in the frame and bar should be loaded into the same window - at least that's the way it used to work.... <br > (switch-to-buffer-other-window (get-buffer-create "foo")) (switch-to-buffer-other-window (get-buffer-create "bar")) – dturvene Apr 26 '19 at 19:52

1 Answers1

1

As with all my emacs work, I take it for granted until something doesn't work and then I need to dig into it. It's a tool but you need to sharpen it to cut bait...

Not the best solution but here's what works for me. I took it from:

How to force completions buffer to appear in a side window?

(defun display-on-side (buffer &optional not-this-window frame)
  (let* ((window (or (minibuffer-selected-window)
                     (selected-window)))
         (display-buffer-function nil)
         (pop-up-windows nil))
    (with-selected-window (or window (error "display-on-side"))
      (when (one-window-p t)
        (split-window-horizontally))
      (display-buffer buffer not-this-window frame))))

(setq display-buffer-function 'display-on-side)

;; unit test, should open in the same side window.
(display-buffer (get-buffer-create "*foo*"))
(display-buffer (get-buffer-create "*bar*"))
dturvene
  • 121
  • 4