0

In buffer list/menu, the key "f" is supposed to open the buffer the cursor is on in the same window as the buffer list. That's what help on the mode says, anyway. In evil mode, this doesn't work, presumably because "f" has a special meaning in vi, so using it for opening a buffer is overridden.

I believe the function that opens a buffer in the current window is buffer-menu-this-window (as opposed to buffer-menu-other-window, which is bound to "o"). I don't care what key buffer-menu-this-window will be bound to, but I want to bind it to some key combination. I tried putting each of these (separately), and a few other variations in .emacs:

(evil-define-key 'normal 'global "c" 'buffer-menu-this-window)
(evil-define-key 'normal buffer-menu-mode-map "c" (lambda () (interactive (buffer-menu-this-window))))

However, when I am in a buffer list and I type "c", I get the message "c is undefined".

How can I create a binding that will open a buffer in the same window as the buffer list. (I can do this currently using the Buffer Menu, but it's something that I will do a lot, so I'd rather give it a key binding.)


Additional information in response to @Ian's question:

I'm not loading any evil-mode based packages, but I load agda mode (for the programming language Agda), and therefore whatever it loads. Is that a likely source of the problem? I'm not loading anything else as far as I know. Here are excepts from my .emacs that seem relevant:

(require 'evil)
(evil-mode 1)
; ...
(load-file (let ((coding-system-for-read 'utf-8))
                (shell-command-to-string "agda-mode locate")))

That last line generates a path to a file agda2.el, whose contents are:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Agda mode code which should run before the first Agda file is
;; loaded
;; SPDX-License-Identifier: MIT License

(defvar agda2-directory (file-name-directory load-file-name)
  "Path to the directory that contains agda2.el(c).")

(add-to-list 'load-path (or agda2-directory (car load-path)))

(autoload 'agda2-mode "agda2-mode"
  "Major mode for editing Agda files (version ≥ 2)." t)
(add-to-list 'auto-mode-alist '("\\.l?agda\\'" . agda2-mode))
(modify-coding-system-alist 'file "\\.l?agda\\'" 'utf-8)

(provide 'agda2)

I don't yet understand what files are being loaded by the code in agda2.el.

2
  • What packages related to evil did you installed up to now?
    – Ian
    Commented May 4 at 13:43
  • Thanks @Ian. I added information that maybe starts to answer the question.
    – Mars
    Commented May 4 at 19:56

1 Answer 1

1

I suggest to use use-package package for easier configuration of your init.el file. At the beginning of init.el file, after configuring package-archives, place this:


(unless (package-installed-p 'use-package)
  (package-refresh-contents)
  (package-install 'use-package))

(require 'use-package)

To get the package evil work correctly, we need to have some variables declared before loading it (evil mandatory request), so you can add/write:

(defvar evil-want-C-g-bindings t)
(defvar evil-want-C-i-jump nil)
(defvar evil-want-C-u-scroll t)
(defvar evil-want-C-u-delete t)
(defvar evil-want-C-w-scroll t)
(defvar evil-want-C-w-delete t)
(defvar evil-want-Y-yank-to-eol t)
(defvar evil-want-abbrev-expand-on-insert-exit nil)
(defvar evil-respect-visual-line-mode nil)

(use-package goto-chg) ;; mandatory; used by evil

(use-package evil) ;; add here the init and config for this package

Further you need to add:

  • the package evil-escape, which will configure a key binding such as jj or jk to revert to normal mode from other evil modes (must be typed a little bit faster, experiment).
  • evil-collection, which add more evil key binding for various other packages.
  • evil-leader, which will set up a leader key - default is , but can be changed to other key, such as SPC. At this level you can add your configuration for files/buffers/etc. A small example below.
(use-package evil-leader
  :demand t
  :hook (after-init-hook . global-evil-leader-mode)
  :init
  (global-evil-leader-mode)
  (setq evil-leader/in-all-states t)
  :config
  (setq evil-leader/leader "<SPC>")

  ;; prefix: <Leader> b, buffer
  (evil-leader/set-key
    "bb" 'switch-to-buffer
    "bB" 'switch-to-buffer-other-window
    "bn" 'next-buffer
    "bp" 'previous-buffer
    "br" 'revert-buffer
    "bx" 'kill-buffer-and-window)
    )

So, for cofiguration above, you will need to type SPC b b to choose a buffer from the list of opened buffers. Using the template above, you can add other keys, e.g. "f" for files, "g" for git, or others you need.

8
  • I am not familiar with agda package, but I think it will be easier to configure with use-package. Also useful to read the package documentation, google for GitHub agda .
    – Ian
    Commented May 5 at 7:44
  • See this: agda.readthedocs.io/en/latest/tools/emacs-mode.html
    – Ian
    Commented May 5 at 7:48
  • Thanks very much, Ian. I upvoted, and I am grateful, but ... this is a lot of work for a small thing. That's not a complaint about what you've generously explained. I'm loading agda-mode the way recommended in the Agda installation docs, so I'm reluctant to do it my own way. (Part of my problem is I'm not committed to a future with emacs--it's just that it's the best editor for Agda. After many years with emacs, I spent many more years using vi clones instead, and will continue using vims outside of Agda.)
    – Mars
    Commented May 5 at 17:33
  • Thanks for finding the Agda emacs documentation. I was familiar with it and consulted it again before posting here.
    – Mars
    Commented May 5 at 17:37
  • Experimenting with code you suggested, though.
    – Mars
    Commented May 5 at 17:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.