Controlling Emacs Behaviors

I would like to customize the behavior when I split windows in Emacs:

I always split because I want to see a separate buffer side by side with the one I'm editing right now.

I use electric-buffer-list(attached to C-x C-b) to navigate buffers.

As a result, I do all of the following separately:

  • C-x 3 for horizontal separation.

  • C-x oto go to another window.

  • C-x C-bto call electric-buffer-list, so I can select the buffer that I want to view.

It looks like I should have written an Elisp function that will do all this when I click C-x 3.

I found this post that describes the part of the focus switch that I want, but I don’t understand how to extend this answer in order to achieve all that I am trying to do.


Edit : after looking at the @lawlist message and debugging my syntax, I think I want to do something like this:

(defun split-right-and-buffer-list ()
  (interactive)
  (split-window-horizontally)
  (other-window 0)
  (electric-buffer-list 0))

(global-set-key (kbd "C-x 3") 'split-right-and-buffer-list)

This does everything I want, except that only the current buffer is displayed in the buffer list, and not the usual list of all buffers that I get when I call electric-buffer-listfrom its key binding.

+4
source share
2 answers

With some very minor changes, the function you come across will do what you want:

(defun split-right-and-buffer-list ()
  (interactive)
  (split-window-horizontally)
  (other-window 1)
  (electric-buffer-list nil))

(global-set-key (kbd "C-x 3") 'split-right-and-buffer-list)
  • Passing 1instead 0as an argument other-windowcauses Emacs to select the new window created by the call split-window-horizontally.

  • nil 0 electric-buffer-list Emacs , , .

    , , , electric-buffer-list ( ARG, ). , , list-buffers-noselect ( ). , .

+2

, , , .

(require 'ido)

(defun my-split-window-open-buffer-right (buffer)
  (interactive (list (ido-read-buffer "Please select a buffer: ")))
  (select-window (split-window-right))
  (switch-to-buffer buffer))

(defun my-split-window-open-buffer-below (buffer)
  (interactive (list (ido-read-buffer "Please select a buffer: ")))
  (select-window (split-window-below))
  (switch-to-buffer buffer))

, . /, .

+1

Source: https://habr.com/ru/post/1529687/


All Articles