]> git.eshelyaron.com Git - emacs.git/commitdiff
Make `next-buffer' order reflect command line file order
authorLars Ingebrigtsen <larsi@gnus.org>
Mon, 21 Feb 2022 14:42:59 +0000 (15:42 +0100)
committerLars Ingebrigtsen <larsi@gnus.org>
Mon, 21 Feb 2022 14:42:59 +0000 (15:42 +0100)
* lisp/startup.el (command-line-1): Make `next-buffer' order
reflect the command line file order (bug#21505).

lisp/startup.el

index 6b9b8234c7830449888515f3e93f306196d4c38f..9f0b23c904b5c35a03a1be33de607ccaf060c481 100644 (file)
@@ -2798,10 +2798,24 @@ nil default-directory" name)
           (nondisplayed-buffers-p nil))
       (when (> displayable-buffers-len 0)
         (switch-to-buffer (car displayable-buffers)))
-      (when (> displayable-buffers-len 1)
-        (switch-to-buffer-other-window (car (cdr displayable-buffers)))
+      (cond
+       ;; Two buffers; display them both.
+       ((= displayable-buffers-len 2)
+        (switch-to-buffer-other-window (cadr displayable-buffers))
         ;; Focus on the first buffer.
         (other-window -1))
+       ;; More than two buffers: Ensure that the buffer display order
+       ;; reflects the order they were given on the command line.
+       ;; (This will end up with a `next-buffer' order that's in
+       ;; reverse order -- the final file is the focused one, and then
+       ;; the rest are in `next-buffer' in descending order.
+       ((> displayable-buffers-len 2)
+        (let ((bufs (reverse (cdr displayable-buffers))))
+          (switch-to-buffer-other-window (pop bufs))
+          (dolist (buf bufs)
+            (switch-to-buffer buf nil t))
+          ;; Focus on the first buffer.
+          (other-window -1))))
       (when (> displayable-buffers-len 2)
         (setq nondisplayed-buffers-p t))