Where is the mate to the Sock?

December 30, 2024

Setting up Emacs (日本語)

Recently, I had been using Vim and VSCode, but I realized that Emacs is actually the best editor for me. So, I decided to set it up again and document the process.

Building Emacs

The elisp language used for configuring Emacs often changes in ways that break backward To avoid potential issues, it is better to fix the version by building Emacs from source.

This time, I'll build version 29.4. Here's how you can do it on Debian 12. (The process should be quite similar for Ubuntu 24.04)

# Install the necessary packages to build
$ sudo apt update
$ sudo apt install build-essential pkg-config libgnutls28-dev libtinfo-dev texinfo

# Get the source code
# Choose a nearby mirror site from `nearby GNU mirror` on https://www.gnu.org/software/emacs/download.html
$ wget https://ftp.gnu.org/gnu/emacs/emacs-29.4.tar.xz
$ tar xvf emacs-29.4.tar.xz
$ cd emacs-29.4
$ ./configure --without-x
$ make
$ sudo make install

Setting up straight

To manage Emacs packages, I decided to use straight, a package management system.

Add the following to ~/.emacs.d/init.el .

(defvar bootstrap-version)
(let ((bootstrap-file
       (expand-file-name
        "straight/repos/straight.el/bootstrap.el"
        (or (bound-and-true-p straight-base-dir)
            user-emacs-directory)))
      (bootstrap-version 7))
  (unless (file-exists-p bootstrap-file)
    (with-current-buffer
        (url-retrieve-synchronously
         "https://raw.githubusercontent.com/radian-software/straight.el/develop/install.el"
         'silent 'inhibit-cookies)
      (goto-char (point-max))
      (eval-print-last-sexp)))
  (load bootstrap-file nil 'nomessage))
(setq package-enable-at-startup nil)

For more details, refer to Official Document .

Setting up Copilot

Next, I set up the copilot package for coding assistance. While most Emacs packages can be managed with straight, copilot requires nodejs and some additional setup for the initial configuration. Next, I will introduce the package copilot for coding. Most emacs packages are sufficient to manage with straight, but copilot requires nodejs and needs to do various things for the initial execution.

Install nodejs and npm

Although nvm is often recommended for installing nodejs due to Debian's lack of security updates for it, I opted to use apt for simplicity.

$ sudo apt install nodejs npm

Configure copilot

Add the following lines to ~/.emacs.d/init.el .

(use-package copilot
  :straight (:host github :repo "copilot-emacs/copilot.el" :files ("*.el"))
  :ensure t)
(require 'copilot)

(add-hook 'prog-mode-hook 'copilot-mode)

(define-key copilot-completion-map (kbd "<tab>") 'copilot-accept-completion)
(define-key copilot-completion-map (kbd "TAB") 'copilot-accept-completion)

; (add-to-list 'copilot-major-mode-alist '("enh-ruby" . "ruby"))

The last line shows an example of enabling copilot for enh-ruby-mode. However, since we have already added copilot to prog-mode-hook, it should work with most languages without additional configuration.

Final Setups

Start Emacs and install copilot-server, then login as follows:

  1. Run M-x copilot-install-server in Emacs.

  2. Execute M-x copilot-login in Emacs.

During login, you will see a message in Emacs's minibuffer like this:

First copy your one-time code: ABCD-1234. Press Enter to continue.

Copy the one-time code, press Enter, and you'll see another message:

Please open https://github.com/login/device in your browser. Press ENTER if you finish authorizing.

Open the provided URL in your browser, enter the one-time code, and complete the authorization process. Note that you don't have to use the browser on the same machine running Emacs; it wosks even on headless development machines.

The latest articles

Setting up Emacs (日本語)

Emacs セットアップ (English)

Setting Up Haskell (日本語)

Haskell セットアップ (English)

WSL のログインユーザー、ホスト名、systemd 起動

久しぶりに Python のセットアップした

Debian Bullseye の GUI をセットアップ (Japanese)

Setup GUI for Debian Bullseye (English)

"The Rust Programming Language" を読む (日本語)

Reading "The Rust Programming Language" (English)

Rust の Crate で Features を使う (日本語)

Adding Features to a Rust Crate (English)