Ubuntu 22.04 で Emacs 29.1 をpgtk ビルドでインストール

概要

手順

ソースコードの取得

$ git clone --depth 1 --branch emacs-29.1 git://git.savannah.gnu.org/emacs.git emacs-29.1

ビルドに必要なツールとライブラリの取得

$ sudo apt install autoconf make texinfo gnutls-bin libgccjit-10-dev gcc
$ sudo apt install zlib1g-dev \
                   libncurses-dev \
                   libgtk-3-dev \
                   xorg-dev \
                   libjpeg-dev \
                   libgif-dev \
                   libtiff-dev \
                   libgnutls28-dev \
                   librsvg2-dev \
                   libcairo-5c-dev \
                   liblcms2-dev \
                   libgpm-dev \
                   libacl1-dev \
                   libxml2-dev \
                   libm17n-dev \
                   libotf-dev \
                   libsystemd-dev \
                   libjansson-dev \
                   libsqlite3-dev

Makefileの生成

cd emacs-29.1
./autogen.sh
CFLAGS='-I/usr/lib/gcc/x86_64-linux-gnu/10/include -L/usr/lib/gcc/x86_64-linux-gnu/10' ./configure --with-pgtk --with-native-compilation --without-pop --with-mailutils

(追記) 最初、下記のようにconfigureしていたのですが、–with-mailutils を使うようお勧めされたので、上記に変更しました。

CFLAGS='-I/usr/lib/gcc/x86_64-linux-gnu/10/include -L/usr/lib/gcc/x86_64-linux-gnu/10' ./configure --with-pgtk --with-native-compilation --without-pop

configure: You might want to install GNU Mailutils
<https://mailutils.org> and use './configure --with-mailutils'.


Configured for 'x86_64-pc-linux-gnu'.

  Where should the build process find the source code?    .
  What compiler should emacs be built with?               gcc -I/usr/lib/gcc/x86_64-linux-gnu/10/include -L/usr/lib/gcc/x86_64-linux-gnu/10 -O
  Should Emacs use the GNU version of malloc?             no
    (The GNU allocators don't work with this system configuration.)
  Should Emacs use a relocating allocator for buffers?    no
  Should Emacs use mmap(2) for buffer allocation?         no
  What window system should Emacs use?                    pgtk
  What toolkit should Emacs use?                          GTK3
  Where do we find X Windows header files?                Standard dirs
  Where do we find X Windows libraries?                   Standard dirs
  Does Emacs use -lXaw3d?                                 no
  Does Emacs use -lXpm?                                   no
  Does Emacs use -ljpeg?                                  yes
  Does Emacs use -ltiff?                                  yes
  Does Emacs use a gif library?                           yes -lgif
  Does Emacs use a png library?                           yes -lpng16 -lz
  Does Emacs use -lrsvg-2?                                yes
  Does Emacs use -lwebp?                                  no
  Does Emacs use -lsqlite3?                               yes
  Does Emacs use cairo?                                   yes
  Does Emacs use -llcms2?                                 yes
  Does Emacs use imagemagick?                             no
  Does Emacs use native APIs for images?                  no
  Does Emacs support sound?                               yes
  Does Emacs use -lgpm?                                   yes
  Does Emacs use -ldbus?                                  yes
  Does Emacs use -lgconf?                                 no
  Does Emacs use GSettings?                               yes
  Does Emacs use a file notification library?             yes -lglibc (inotify)
  Does Emacs use access control lists?                    yes -lacl
  Does Emacs use -lselinux?                               yes
  Does Emacs use -lgnutls?                                yes
  Does Emacs use -lxml2?                                  yes
  Does Emacs use -lfreetype?                              yes
  Does Emacs use HarfBuzz?                                yes
  Does Emacs use -lm17n-flt?                              
  Does Emacs use -lotf?                                   yes
  Does Emacs use -lxft?                                   
  Does Emacs use -lsystemd?                               yes
  Does Emacs use -ljansson?                               yes
  Does Emacs use -ltree-sitter?                           no
  Does Emacs use the GMP library?                         yes
  Does Emacs directly use zlib?                           yes
  Does Emacs have dynamic modules support?                yes
  Does Emacs use toolkit scroll bars?                     yes
  Does Emacs support Xwidgets?                            no
  Does Emacs have threading support in lisp?              yes
  Does Emacs support the portable dumper?                 yes
  Does Emacs support legacy unexec dumping?               no
  Which dumping strategy does Emacs use?                  pdumper
  Does Emacs have native lisp compiler?                   yes
  Does Emacs use version 2 of the X Input Extension?      no
  Does Emacs generate a smaller-size Japanese dictionary? no

pgtkを有効にしない場合は “What window system should Emacs use?” が “x11” でしたが、これが “pgtk” になります。 また、その他いくつかの項目が”no”または空欄となりました。

What window system should Emacs use?                    pgtk
Does Emacs use -lXpm?                                   no
Does Emacs use -lm17n-flt?                              
Does Emacs use -lxft?                                   
Does Emacs use version 2 of the X Input Extension?      no

make

make -j8

make install

sudo make install

表示

pgtkが無効(x11)の場合には、下記のようなウィンドウ(フレーム)でした。

925_01.jpg

pgtkバージョンでは少し違っており、最小化、最大化のボタンがなく、クローズボタンのみ左側にあります。

925_02.jpg

pgtkバージョンでは少し違っており、最小化、最大化のボタンがなく、クローズボタンのみ左側にあります。

これが、Gnome(Wayland)の機能でウィンドウを表示している証拠であり、gnome-tweaks (apt install gnome-tweaks でインストールできます)の設定によって下記のように変更することができました。

925_03.jpg

925_04.jpg

設定

WSL上のEmacsからWindowsへコピー&ペーストができるようにする

しばらく快適に使っていたのですが、WSL上のEmacsからWindowsへコピー&ペーストができなくなっていることに気づきました。

WSLg(Wayland) の Emacs(--with-pgtk) でのクリップボード

上記ページを参考に下記のように設定し、コピー&ペーストができるようになりました。

wl-clipboardをインストールします。

$ sudo apt install wl-clipboard

ここでは、featurep で pgtk が有効であることを確認し、wl-copy 及び wl-paste が実行可能であることを確認してから設定するようにしています。

(if (featurep 'pgtk)
    ; you need to install "wl-clipboard" first
    (if (and (zerop (call-process "which" nil nil nil "wl-copy"))
             (zerop (call-process "which" nil nil nil "wl-paste")))
        ;; credit: yorickvP on Github
        (progn
          (setq wl-copy-process nil)
          (defun wl-copy (text)
            (setq wl-copy-process (make-process :name "wl-copy"
                                                :buffe*r nil
                                                :command '("wl-copy" "-f" "-n")
                                                :connection-type 'pipe))
            (process-send-string wl-copy-process text)
            (process-send-eof wl-copy-process))
          (defun wl-paste ()
            (if (and wl-copy-process (process-live-p wl-copy-process))
                nil ; should return nil if we're the current paste owner
              (shell-command-to-string "wl-paste -n | tr -d \r")))
          (setq interprogram-cut-function 'wl-copy)
          (setq interprogram-paste-function 'wl-paste)
          )
      ))

Emacs起動時のWarning

こちらも上記引用ページからですが、確かに起動時に下記のWarningが出ていました。

Gdk-Message: 21:53:00.644: Unable to load sb_v_double_arrow from the cursor theme
Gdk-Message: 21:53:00.644: Unable to load sb_h_double_arrow from the cursor theme
Gdk-Message: 21:53:00.670: Unable to load hand2 from the cursor theme
Gdk-Message: 21:53:00.670: Unable to load sb_h_double_arrow from the cursor theme
Gdk-Message: 21:53:00.670: Unable to load sb_v_double_arrow from the cursor theme

adwaita-icon-theme-full をインストールし、dark テーマを設定しました。

$ sudo apt install adwaita-icon-theme-full

export GTK_THEME=Adwaita:dark

カッコいい!!

925_05.jpg

タスクバーやスタートメニューのアイコンがペンギンのまま

$ sudo vi /usr/local/share/applications/emacs.desktop

下記のようになっています。

Desktop Entry]
Name=Emacs
GenericName=Text Editor
Comment=Edit text
MimeType=text/english;text/plain;text/x-makefile;text/x-c++hdr;text/x-c++src;text/x-chdr;text/x-csrc;text/x-java;text/x-moc;text/x-pascal;text/x-tcl;text/x-tex;application/x-shellscript;text/x-c;text/x-c++;
Exec=emacs %F
Icon=emacs
Type=Application
Terminal=false
Categories=Development;TextEditor;
StartupNotify=true
StartupWMClass=Emacs

下記のように書き換えます。

変更前

Icon=emacs

変更後

Icon=emacs29

各種サイズのアイコンが格納されているソースディレクトリに移動します。

$ cd ~/source/emacs-29.1/etc/images/icons/hicolor/

drwxr-xr-x 3 wurly wurly 4096 Dec  2 16:21 128x128
drwxr-xr-x 3 wurly wurly 4096 Dec  2 16:21 16x16
drwxr-xr-x 3 wurly wurly 4096 Dec  2 16:21 24x24
drwxr-xr-x 3 wurly wurly 4096 Dec  2 16:21 32x32
drwxr-xr-x 3 wurly wurly 4096 Dec  2 16:21 48x48
drwxr-xr-x 4 wurly wurly 4096 Dec  2 16:21 scalable

スクリプトを作成します。

cat << 'EOS' > copy_emacs_icons.sh
#!/bin/bash

for d in *
do
    sudo cp "$d/apps/emacs.png" "/usr/share/icons/hicolor/$d/apps/emacs29.png"
done
EOS

スクリプトを実行します。

$ chmod +x copy_emacs_icons.sh
$ ./copy_emacs_icons.sh

下記メッセージが表示されてしまうのはご愛嬌ということで・・・

cp: cannot stat 'copy_emacs_icons.sh/apps/emacs.png': Not a directory
cp: cannot stat 'scalable/apps/emacs.png': No such file or directory

wslを再起動 (PowerShell から wsl –shutdown)すると反映されます。

Copied title and URL