Search code examples
emacsgnome-terminal

How to apply a patch to Emacs (True Color Support)


This is NOT a duplicate.

I want to use true color in Emacs in a terminal supporting true color (in this case GNOME terminal). I have seen many links to a diff file, but they do not provide any instructions for how to apply the diff.

Simply put, how do you use this diff (https://gist.github.com/choppsv1/36aacdd696d505566088) to gain true color support?

Please excuse for my noob-ness, I have never used these diff files before.


Solution

    • Download the source code for Emacs 24.4 (that's the version that the patch says it's for). This link will redirect you to a nearby mirror, from which you can download emacs-24.4.tar.gz: http://ftpmirror.gnu.org/emacs/
    • Unpack the tarball, and change to the new directory:

      tar -xzf emacs-24.4.tar.gz
      cd emacs-24.4
      
    • Download the diff as emacs-24.4-24bit.diff.

    • Apply the diff with patch. This is the tricky bit: we have to inspect the patch to see how many path components need to be removed. The header for the first hunk says:

      *** ./lisp/term/xterm.el.orig   2014-06-20 13:28:33.000000000 -0400
      --- ./lisp/term/xterm.el    2015-02-23 07:01:48.000000000 -0500
      

      So the target path is ./lisp/term/xterm.el, which is exactly what we have in the unpacked directory. Thus we remove zero path components, and pass the argument -p0 to patch.

      If this patch were generated by git, it would look something like this instead, with the a directory referring to the old version and the b directory referring to the new version:

      *** a/lisp/term/xterm.el.orig   2014-06-20 13:28:33.000000000 -0400
      --- b/lisp/term/xterm.el    2015-02-23 07:01:48.000000000 -0500
      

      In that case, we'd need to remove one path component to be able to apply the patch (since there is no actual b subdirectory), and we'd use the argument -p1.

      Note that the most convenient way to use patch is to redirect the patch file to it with <. So we end up with this command line:

      patch -p0 < emacs-24.4-24bit.diff
      

      Check the output, to ensure that the patch was applied correctly. In this case there shouldn't be any problems, since we're applying the patch on the exact same version, but you never know.

    • Install any tools needed to compile Emacs. In Debian and Ubuntu, you can use apt-get build-dep:

      sudo apt-get build-dep emacs24
      

      Other distributions will have other ways of doing that. You need things like a C compiler, development packages for GTK+ and other libraries that Emacs depends on.

    • Configure Emacs. The default settings should be fine; they will install your new Emacs in /usr/local:

      ./configure
      
    • Compile Emacs:

      make
      
    • Install Emacs:

      sudo make install
      
    • Set an environment variable, as described in the diff, either ITERM_24BIT or KONSOLE_DBUS_SESSION.

    • Try running it:

      /usr/local/bin/emacs