Skip to content

Instantly share code, notes, and snippets.

@thedward
Last active July 26, 2016 17:38
Show Gist options
  • Save thedward/dbd50d858162e89a7ef9223abadfb673 to your computer and use it in GitHub Desktop.
Save thedward/dbd50d858162e89a7ef9223abadfb673 to your computer and use it in GitHub Desktop.
This patch for Vim enables (buggy) support for the programming ligatures in fonts like HaskLig and FiraCode — via https://groups.google.com/d/msg/vim_dev/0sETSAwe5Wo/mg3vhLebImIJ
diff -r 94df797ed6b0 -r e86e08d8e7af src/gui_gtk_x11.c
--- a/src/gui_gtk_x11.c Sat Apr 12 13:12:24 2014 +0200
+++ b/src/gui_gtk_x11.c Sun Apr 20 14:50:35 2014 +0200
@@ -4311,7 +4311,7 @@ get_styled_font_variants(void)
static PangoEngineShape *default_shape_engine = NULL;
/*
- * Create a map from ASCII characters in the range [32,126] to glyphs
+ * Create a map from ASCII characters [ ,0-9,a-z,A-Z] to glyphs
* of the current font. This is used by gui_gtk2_draw_string() to skip
* the itemize and shaping process for the most common case.
*/
@@ -4334,8 +4334,13 @@ ascii_glyph_table_init(void)
/* For safety, fill in question marks for the control characters. */
for (i = 0; i < 32; ++i)
ascii_chars[i] = '?';
- for (; i < 127; ++i)
- ascii_chars[i] = i;
+ for (; i < 127; ++i) {
+ if (i == 32 || (i >= 48 && i <= 57) || (i >= 65 && i <= 90) || (i >= 97 && i <= 122)) {
+ ascii_chars[i] = i;
+ } else {
+ ascii_chars[i] = '?';
+ }
+ }
ascii_chars[i] = '?';
attr_list = pango_attr_list_new();
@@ -4961,8 +4966,9 @@ gui_gtk2_draw_string(int row, int col, c
/*
* Optimization hack: If possible, skip the itemize and shaping process
- * for pure ASCII strings. This optimization is particularly effective
- * because Vim draws space characters to clear parts of the screen.
+ * for pure alphanumeric ASCII strings.
+ * This optimization is particularly effective because Vim draws space
+ * characters to clear parts of the screen.
*/
if (!(flags & DRAW_ITALIC)
&& !((flags & DRAW_BOLD) && gui.font_can_bold)
@@ -4971,7 +4977,7 @@ gui_gtk2_draw_string(int row, int col, c
char_u *p;
for (p = s; p < s + len; ++p)
- if (*p & 0x80)
+ if (*p != 32 && (*p < 48 || *p > 57) && (*p < 65 || *p > 90) && (*p < 97 || *p > 122))
goto not_ascii;
pango_glyph_string_set_size(glyphs, len);

This is how I used this patch on Debian Jessie (8.4)

Make sure the necessary tools and dependencies are installed

sudo apt-get install build-essential curl devscripts quilt
sudo apt-get build-dep vim-gtk=2:7.4.488-7

I don't want to clutter up my home directory

mkdir ~/build
cd ~/build

Use the source!

apt-get source vim-gtk=2:7.4.488-7
cd vim-7.4.488/

Setup some variables for quilt

export QUILT_PATCHES=debian/patches
export QUILT_REFRESH_ARGS="-p ab --no-timestamps --no-index"

Add the patch to the Debian package (I made a shortened URL for convenience)

quilt import -P debian/vim_ascii-ligatures.patch  <( curl -Ls 'https://git.io/vKQZ8' ) 
quilt push

Time to make the packages

debuild -i -us -uc

Now there should be a bunch of packages

cd ~/build
ls -l vim*.deb | sed -re "/ $USER $USER/s///" 
-rw-r--r-- 1  952326 Jul 25 18:15 vim_7.4.488-7_amd64.deb
-rw-r--r-- 1 1158164 Jul 25 18:15 vim-athena_7.4.488-7_amd64.deb
-rw-r--r-- 1  184484 Jul 25 18:15 vim-common_7.4.488-7_amd64.deb
-rw-r--r-- 1 6500878 Jul 25 18:15 vim-dbg_7.4.488-7_amd64.deb
-rw-r--r-- 1 1756082 Jul 25 18:15 vim-doc_7.4.488-7_all.deb
-rw-r--r-- 1 1167676 Jul 25 18:15 vim-gnome_7.4.488-7_amd64.deb
-rw-r--r-- 1 1164584 Jul 25 18:15 vim-gtk_7.4.488-7_amd64.deb
-rw-r--r-- 1  149328 Jul 25 18:14 vim-gui-common_7.4.488-7_all.deb
-rw-r--r-- 1   90178 Jul 25 18:15 vim-lesstif_7.4.488-7_all.deb
-rw-r--r-- 1 1049398 Jul 25 18:15 vim-nox_7.4.488-7_amd64.deb
-rw-r--r-- 1 5030394 Jul 25 18:14 vim-runtime_7.4.488-7_all.deb
-rw-r--r-- 1  417538 Jul 25 18:15 vim-tiny_7.4.488-7_amd64.deb

Now you can install the packages (I prefer vim-gtk — your tastes may vary)

sudo dpkg -i vim-common_7.4.488-7_amd64.deb \ 
  vim-gtk_7.4.488-7_amd64.deb \
  vim-gui-common_7.4.488-7_all.deb vim-runtime_7.4.488-7_all.deb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment