[{"content":"I build Emacs from the release branch and install it as a package, so dpkg knows about every file and apt remove cleans it all up. For years I did that with checkinstall and one rule I never questioned: always pass --fstrans=no. This year it stopped working, so I found out why and switched to a tiny debian/ directory and dpkg-buildpackage.\nWhy checkinstall stopped working checkinstall runs make install under installwatch, an LD_PRELOAD library that records every file touched, and packages whatever it saw.\nWhy --fstrans=no. By default, checkinstall redirects every write into a temporary folder (\u0026ldquo;filesystem translation\u0026rdquo;). make install puts the Lisp files in a folder named after the version, like share/emacs/31.1.90, and starts by deleting that folder with rm -rf. Under translation that delete fails:\nrm: fts_read failed: No such file or directory gzip: ../etc/publicsuffix.txt.gz already exists;\tnot overwritten **** Installation failed. Aborting package creation. When you rebuild the same branch after a git pull, the version usually hasn\u0026rsquo;t changed, so that folder is already there from your last install, and that\u0026rsquo;s exactly when the default mode fails. --fstrans=no runs a real make install straight into /usr/local instead. checkinstall then becomes make install plus a list of the files it saw, so apt remove can clean them up later. It can only clean up what made it onto that list.\nWhat broke. Debian\u0026rsquo;s checkinstall 1.8.3 (August 2026) made installwatch also log euidaccess() calls. bash makes one of those for every command it looks up in PATH. checkinstall\u0026rsquo;s filter only drops lines logged as access or unlink, so every program make install runs now lands in the package. Mine listed /usr/bin/bash, rm, sed, make and fifteen other system files, and dpkg refused it:\ntrying to overwrite \u0026#39;/usr/bin/bash\u0026#39;, which is also in package bash With --fstrans=no, everything had already been copied into /usr/local, so those files stayed there with no package owning them. --exclude=/usr/bin,/usr/share works around it.\nA second trap. When you rebuild over an installed copy, share/emacs/site-lisp/subdirs.el and share/info/dir already exist and nothing writes them again. checkinstall doesn\u0026rsquo;t record them, so the new package doesn\u0026rsquo;t contain them, and dpkg deletes them during the upgrade. You have to apt remove the old package before every build.\nIf you\u0026rsquo;d rather stay with checkinstall, this works with 1.8.3:\nsudo apt remove emacs-31 sudo checkinstall --fstrans=no --exclude=/usr/bin,/usr/share --nodoc --backup=no \\ --install=no -y --pkgname=emacs-31 --pkgversion=31.1.90 make install That was too many traps for me, so I switched to a real package.\nWhat a .deb actually needs Emacs\u0026rsquo;s Makefile supports DESTDIR, so make install DESTDIR=somewhere installs into a staging folder instead of your system. There\u0026rsquo;s nothing to trace, and the staging folder holds exactly what Emacs installs. debhelper (dh) builds the package around that: it configures, builds, installs into debian/emacs-31/, strips the binaries, and works out Depends: from the shared libraries Emacs actually links against.\nSetup You need debhelper and Emacs\u0026rsquo;s build dependencies. If you have deb-src lines enabled, apt build-dep emacs pulls in everything Debian\u0026rsquo;s own Emacs needs, which covers a pgtk build:\nsudo apt install debhelper sudo apt build-dep emacs Work in your Emacs checkout. A fresh git clone has no configure script yet, so generate it once:\n./autogen.sh Keep the packaging out of your Emacs commits:\nmkdir -p debian \u0026amp;\u0026amp; echo debian/ \u0026gt;\u0026gt; .git/info/exclude Read the version from configure.ac, and name the package after its major version, so the emacs-31 branch gives emacs-31 and a 32.x version gives emacs-32. The next steps use both variables, so stay in this shell:\nVER=$(sed -n \u0026#39;s/^AC_INIT(\\[GNU Emacs\\], \\[\\([^]]*\\)\\].*/\\1/p\u0026#39; configure.ac) PKG=emacs-${VER%%.*} The three files debian/control describes the package. The EOF isn\u0026rsquo;t quoted here, so the shell fills in $PKG. The backslashes keep ${shlibs:Depends} and ${misc:Depends} for debhelper, which fills in the library dependencies there. Change the maintainer line to yours if you like; it\u0026rsquo;s only metadata here.\ncat \u0026gt; debian/control \u0026lt;\u0026lt;EOF Source: $PKG Section: editors Priority: optional Maintainer: Your Name \u0026lt;you@example.com\u0026gt; Build-Depends: debhelper-compat (= 13) Package: $PKG Architecture: any Depends: \\${shlibs:Depends}, \\${misc:Depends} Provides: emacs-from-source Conflicts: emacs-from-source Replaces: emacs-from-source Description: GNU Emacs, local build from source EOF emacs-31 and emacs-32 install the same files, like /usr/local/bin/emacs, so only one can be installed at a time. The last three lines make apt handle that for you. Every emacs-NN package claims the same made-up name, emacs-from-source, and conflicts with anything else that claims it, so installing emacs-32 removes emacs-31 automatically. Debian uses the same pattern for mail servers.\nI didn\u0026rsquo;t add Conflicts: emacs. Debian\u0026rsquo;s emacs-pgtk and friends Provides: emacs, so that line would make apt remove them. The two can live side by side: this package goes into /usr/local, Debian\u0026rsquo;s into /usr, and /usr/local/bin comes first in the default PATH.\ndebian/changelog sets the package version. The format is strict about spacing, so let the shell write it:\nprintf \u0026#39;%s (%s-1) unstable; urgency=medium\\n\\n * Local build.\\n\\n -- Your Name \u0026lt;you@example.com\u0026gt; %s\\n\u0026#39; \u0026#34;$PKG\u0026#34; \u0026#34;$VER\u0026#34; \u0026#34;$(date -R)\u0026#34; \u0026gt; debian/changelog debian/rules is a Makefile. dh $@ runs the standard sequence, and each override_dh_* target replaces one step. An empty override skips the step. Make normally wants a literal tab before every recipe line, which breaks easily when copying from a web page, so .RECIPEPREFIX swaps it for \u0026gt;.\ncat \u0026gt; debian/rules \u0026lt;\u0026lt;\u0026#39;EOF\u0026#39; #!/usr/bin/make -f .RECIPEPREFIX = \u0026gt; %: \u0026gt; dh $@ override_dh_auto_configure: \u0026gt; dh_auto_configure -- --with-pgtk --prefix=/usr/local override_dh_autoreconf: override_dh_update_autotools_config: override_dh_shlibdeps: \u0026gt; dh_shlibdeps -- --ignore-missing-info override_dh_strip_nondeterminism: override_dh_auto_test: override_dh_usrlocal: EOF chmod +x debian/rules Why each override is there dh_auto_configure -- ...: dh passes --prefix=/usr plus Debian\u0026rsquo;s usual flags first. Anything after -- comes later, and configure uses the last --prefix it sees. Put your own configure options here. dh_autoreconf, dh_update_autotools_config: these regenerate the build system and replace config.guess and friends. In a git checkout that rewrites tracked files under build-aux/. autogen.sh already produced configure, so skip both. dh_shlibdeps --ignore-missing-info: I have a hand-built tree-sitter in /usr/local/lib. No package owns it, so dpkg-shlibdeps can\u0026rsquo;t name a dependency for it and stops the build. This flag skips libraries it can\u0026rsquo;t map and still fills in the rest. If all your libraries come from apt, you can drop this override. dh_strip_nondeterminism: this one took real debugging. It rewrites every gzip file for reproducible builds, giving each .el.gz a new timestamp. The sources then end up newer than their .elc. With load-prefer-newer set to t, which many configs do, Emacs loads the compressed source instead of the bytecode during startup and fails with Missing 'lexical-binding' cookie and a void variable. Upstream make install keeps the original timestamps, which is why a plain install never had this problem. dh_auto_test: skips make check, which takes a long time. dh_usrlocal: Debian policy forbids packages from shipping files in /usr/local and this step enforces it. A package you build yourself can ignore that. dh binary --no-act prints the steps it will run, without running them.\nBuild and install dpkg-buildpackage -b -us -uc -b builds only the binary package, and -us -uc skips signing. It starts with make distclean, so every build is a clean one, and you don\u0026rsquo;t need to run configure or make yourself. The .deb lands in the parent directory:\nsudo apt install ../${PKG}_${VER}-1_amd64.deb Check what landed outside /usr/local. This should print only the parent directories and changelog.Debian.gz under /usr/share/doc/emacs-31/, which debhelper adds to every package. Then see what it depends on:\ndpkg -c ../${PKG}_${VER}-1_amd64.deb | grep -v \u0026#39; \\./usr/local/\u0026#39; dpkg-deb -f ../${PKG}_${VER}-1_amd64.deb Depends Removing it later is one command:\nsudo apt remove emacs-31 It prints warnings like these, which used to bother me with checkinstall too:\ndpkg: warning: while removing emacs-31, directory \u0026#39;/usr/local/share\u0026#39; not empty so not removed They\u0026rsquo;re harmless, and you never see them with Debian\u0026rsquo;s own packages. dpkg only tries to delete a folder when the package being removed is the last one that lists it. Hundreds of packages list /usr/share, so removing curl says nothing. No official package lists /usr/local/share or /usr/local/lib, because Debian creates them with a script. That leaves emacs-31 as their only owner, so dpkg tries to delete them and warns when other files are still inside. After an upgrade where the version changed, you may also see unable to delete old directory '/usr/local/share/emacs/\u0026lt;old version\u0026gt;/...': Directory not empty. That means something dpkg doesn\u0026rsquo;t own is still in that folder, and you can delete it by hand.\nUpdating After pulling new commits, refresh the package name and changelog, then rebuild:\ngit pull VER=$(sed -n \u0026#39;s/^AC_INIT(\\[GNU Emacs\\], \\[\\([^]]*\\)\\].*/\\1/p\u0026#39; configure.ac) PKG=emacs-${VER%%.*} sed -i \u0026#34;s/^\\(Source\\|Package\\): .*/\\1: $PKG/\u0026#34; debian/control printf \u0026#39;%s (%s-1) unstable; urgency=medium\\n\\n * Local build.\\n\\n -- Your Name \u0026lt;you@example.com\u0026gt; %s\\n\u0026#39; \u0026#34;$PKG\u0026#34; \u0026#34;$VER\u0026#34; \u0026#34;$(date -R)\u0026#34; \u0026gt; debian/changelog dpkg-buildpackage -b -us -uc sudo apt install ../${PKG}_${VER}-1_amd64.deb If the major version changed, say from 31 to 32, apt removes emacs-31 and installs emacs-32 in one step. If the version didn\u0026rsquo;t change, apt reinstalls the package over itself. Unlike checkinstall, the package always contains the full install, so nothing goes missing. Remove old .deb files from the parent directory now and then.\nLimits This package is for the machine it was built on. It builds against whatever is installed there, /usr/local/lib included, and it skips everything Debian\u0026rsquo;s real Emacs packaging does: the split into emacs-bin-common, emacs-common and emacs-el, emacsen-common integration for elpa-* packages, and update-alternatives. To build something that works on any Debian machine, start from apt source emacs and build in a clean chroot with sbuild. For my own machine, three small files were enough.\n","permalink":"https://blog.braineo.dev/posts/emacs-deb-package/","summary":"\u003cp\u003eI build Emacs from the release branch and install it as a package, so dpkg knows about every file and \u003ccode\u003eapt remove\u003c/code\u003e cleans it all up. For years I did that with checkinstall and one rule I never questioned: always pass \u003ccode\u003e--fstrans=no\u003c/code\u003e. This year it stopped working, so I found out why and switched to a tiny \u003ccode\u003edebian/\u003c/code\u003e directory and \u003ccode\u003edpkg-buildpackage\u003c/code\u003e.\u003c/p\u003e\n\u003ch2 id=\"why-checkinstall-stopped-working\"\u003eWhy checkinstall stopped working\u003c/h2\u003e\n\u003cp\u003echeckinstall runs \u003ccode\u003emake install\u003c/code\u003e under \u003ccode\u003einstallwatch\u003c/code\u003e, an \u003ccode\u003eLD_PRELOAD\u003c/code\u003e library that records every file touched, and packages whatever it saw.\u003c/p\u003e","title":"Packaging my own Emacs build as a .deb"},{"content":"I had ligatures working in Emacs with ligature.el, and JetBrains Mono drew !== as one long bar. It looked great until I tried to tell != from !== at a glance. JetBrains Mono ships a few optional extras, and one of them, ss19, puts small gaps between the equals signs. Next to it was zero, a slashed zero instead of the dotted one. I wanted both.\nPlenty of editors expose these as a setting. In Emacs there is no place to put it. I ended up hacking Emacs and went down a rabbit hole. At the end, on my own build it looks like this:\nIn Part 1 I got to know a little bit more about font composition in Emacs. That turned out to be the first wall. Passing the features along was the easy part. Understanding when Emacs decides to shape text at all, and how to make it shape mine, was not.\n\u0026ldquo;Probably\u0026rdquo; out of luck The ligature.el README has a limitations section. Emacs doesn\u0026rsquo;t support stylistic sets, you can\u0026rsquo;t set them from Elisp, and you are \u0026ldquo;(probably) out of luck\u0026rdquo;.\nProbably. If the only thing missing is a way to pass a setting from Elisp, how hard can it be?\nHow does everyone else do it I had no idea where to start, so I looked at a program that already does this. WezTerm takes a harfbuzz_features option in its config, and you list exactly the tags I wanted: zero, ss19.\nHarfBuzz. I\u0026rsquo;d seen that word before. When I build Emacs from source, the configure summary at the end has a line Does Emacs use HarfBuzz? yes. I never knew what it was, but now there was a hint: in WezTerm it\u0026rsquo;s the thing that takes the feature tags. If my Emacs is built with it, the support should be somewhere in there already.\ngrep harfbuzz So I grepped the source for harfbuzz. I expected one file and got more than a dozen in src/: ftfont.c, ftcrfont.c, xftfont.c, a few Windows ones, and hbfont.c.\nftcrfont.c was the confusing one, so I opened it. Near the bottom, inside #ifdef HAVE_HARFBUZZ, there\u0026rsquo;s this:\nftcrhbfont_driver = ftcrfont_driver; ftcrhbfont_driver.type = Qftcrhb; ... ftcrhbfont_driver.shape = hbfont_shape; ... register_font_driver (\u0026amp;ftcrhbfont_driver, NULL); It copies a whole struct font_driver, swaps a few function pointers, and registers the copy under a new name, ftcrhb. Looking up struct font_driver in font.h explained the rest. It\u0026rsquo;s a table of functions: how to list fonts, open them, measure them, draw them. Emacs calls each of these a font backend. ftcr is FreeType plus Cairo, and ftcrhb is the same backend with HarfBuzz doing the shape step. The other files are the same idea for Xft, Windows and so on, and (frame-parameter nil 'font-backend) shows which ones a frame is using.\nSo all roads lead to hbfont_shape, which lives in src/hbfont.c. It\u0026rsquo;s a small file, and the copyright line starts at 2019, which makes it a baby by Emacs standards. Most of it is plumbing: wrap the font, fill a buffer with characters. Then, near the bottom:\nhb_bool_t success = hb_shape_full (hb_font, hb_buffer, NULL, 0, NULL); I didn\u0026rsquo;t know what hb_shape_full did, so I went to the HarfBuzz docs. HarfBuzz calls its job shaping: you give it a run of characters and a font, and it tells you which glyphs to draw and where. Characters and glyphs aren\u0026rsquo;t the same thing. With ligatures on, the three characters !== come back as one glyph. In Arabic, the same letter comes back as a different glyph depending on what\u0026rsquo;s next to it.\nThe third argument is an array of hb_feature_t, and the fourth is its length. A feature is a four-letter tag, the same zero and ss19 from the WezTerm config, plus a value and the range of the buffer it applies to. So the font carries all these optional rules, and it\u0026rsquo;s up to whoever calls the shaper to say which ones to turn on.\nEmacs passes NULL and 0. Nothing wrong with that, it\u0026rsquo;s just not wired up to anything. HarfBuzz arrived in 2019, replacing older shaping engines so that scripts like Arabic would render properly, and for that the font\u0026rsquo;s defaults are enough. So the slot for features is there, waiting for someone to fill it.\nFine. Hard-code it and see:\nstatic hb_feature_t features[] = { {HB_TAG(\u0026#39;z\u0026#39;,\u0026#39;e\u0026#39;,\u0026#39;r\u0026#39;,\u0026#39;o\u0026#39;), 1, 0, -1}, // slashed zero {HB_TAG(\u0026#39;c\u0026#39;,\u0026#39;a\u0026#39;,\u0026#39;l\u0026#39;,\u0026#39;t\u0026#39;), 1, 0, -1}, // contextual alternates {HB_TAG(\u0026#39;s\u0026#39;,\u0026#39;s\u0026#39;,\u0026#39;1\u0026#39;,\u0026#39;9\u0026#39;), 1, 0, -1}, // stylistic set 19 }; fprintf (stderr, \u0026#34;Enabling features for JetBrains Mono\\n\u0026#34;); for (int i = 0; i \u0026lt; 3; i++) { char tag_str[5]; hb_tag_to_string (features[i].tag, tag_str); tag_str[4] = \u0026#39;\\0\u0026#39;; fprintf (stderr, \u0026#34;Feature %d: %s (value=%u, start=%u, end=%d)\\n\u0026#34;, i, tag_str, features[i].value, features[i].start, features[i].end); } hb_bool_t success = hb_shape_full (hb_font, hb_buffer, features, 3, NULL); 1 means on, and 0 to -1 means the whole buffer. The print loop is there so I\u0026rsquo;d at least see it working.\nRebuild. Start Emacs from a terminal. Open a file full of zeros.\nThe zeros were still dotted. The terminal was empty.\nWhy isn\u0026rsquo;t this running An empty terminal is worse than a wrong glyph. A wrong glyph means my features are wrong. An empty terminal means the function I edited was never called.\nThat made no sense to me. Emacs was obviously drawing JetBrains Mono. Was my frame even on the ftcrhb backend? Was the binary I started even the one I built? I searched, asked on forums, and pulled my hair out for a while.\nThe useful thing that came out of it was one sentence, repeated in a few places: Emacs doesn\u0026rsquo;t call hbfont_shape unless it has to.\n\u0026ldquo;Has to\u0026rdquo; was the clue. What text does Emacs have to shape? The HarfBuzz docs kept using Arabic as the example, where a letter can\u0026rsquo;t be drawn without looking at its neighbors. So I pasted in some Arabic, العربية, and the terminal filled up with my feature list.\nSo the code worked, and HarfBuzz worked. Emacs had just decided my zeros didn\u0026rsquo;t need HarfBuzz.\nWho decides The name I needed came from an old Reddit thread where Eli Zaretskii, the Emacs maintainer, explains composition-function-table. C-h v on it says it\u0026rsquo;s defined in composite.c, so that was the next file to open.\ncomposite.c is a different kind of file. git log says it was created on 1999-12-15 by Kenichi Handa, and the copyright header still credits AIST, the Japanese national research institute, with registration numbers. Reading through the comments and docstrings, the file is about scripts like Thai, Tibetan and the Indic ones, where characters merge, stack and change shape. Normally Emacs puts one glyph per character and moves on. This file is how it says \u0026ldquo;these ones go together\u0026rdquo;.\ncomposition-function-table is how it says that. It\u0026rsquo;s a char-table, so every character has a slot. Most slots are empty. A filled slot holds rules of the form [PATTERN PREV-CHARS FUNC]. When Emacs draws a character with an empty slot, it just draws the glyph from the font. That\u0026rsquo;s the fast path my zeros were taking. When the slot has a rule, Emacs collects text into a glyph string and calls FUNC, which is usually font-shape-gstring, which ends up in hbfont_shape.\nMy first reading was that Emacs shapes one character at a time, if it shapes at all. But Arabic worked without me setting anything, so somewhere there had to be a rule for it. Grepping lisp/ for composition-function-table found it in lisp/language/misc-lang.el. The rule sits on the whole Arabic block, and its pattern is one character class covering the Arabic letters and the zero-width joiners, followed by a +. That + is the important part. The character is only the trigger. The regexp grabs the whole run of Arabic letters, and the whole run goes to HarfBuzz together. It has to, because a letter\u0026rsquo;s shape depends on its neighbors. PREV-CHARS even lets the match start a few characters before the trigger.\nSo a character with an empty slot never gets near HarfBuzz, whatever is around it. And a Latin 0 has an empty slot.\nWhy gate it like this? I only got the answer later, when I sent my patch to the bug tracker and Eli explained it: \u0026ldquo;This is an optimization: using the shaping engine slows down redisplay\u0026rdquo;. Shaping goes from C into Lisp and back into C again. Characters without a rule skip all of that and get their glyphs straight from the font.\nFilling the slot The rest was almost an anticlimax:\n(set-char-table-range composition-function-table ?0 ; character \u0026#39;0\u0026#39; \u0026#39;([\u0026#34;.\u0026#34; 0 font-shape-gstring])) Evaluate, and the zero on screen got its slash. My hard-coded features from 2019 finally reached a character, through a door from 1999.\nss19 needed one more thought. It changes the !== ligature, and a ligature is a sequence, so a rule that only grabbed the ! would hand HarfBuzz a lone ! with nothing to join. The pattern has to cover all three characters:\n(set-char-table-range composition-function-table ?! ; character \u0026#39;!\u0026#39; \u0026#39;([\u0026#34;\\\\(!==\\\\)\u0026#34; 0 font-shape-gstring])) Gaps between the equals signs. Both switches flipped, as long as you don\u0026rsquo;t mind recompiling Emacs to change your mind.\nThis is also when I understood what ligature.el actually does. Emacs can\u0026rsquo;t ask a font which sequences it has ligatures for and fill in this table by itself. ligature.el fills it in for you, one sequence at a time, using the same mechanism Handa built for Devanagari to draw -\u0026gt; as an arrow. I\u0026rsquo;d been using the package without knowing it was mostly a list of regexps.\nTwo halves that don\u0026rsquo;t line up Looking back at what it took, two separate parts of Emacs have to agree before a feature shows up. composite.c decides whether text gets shaped and how much of it goes together, and it decides by looking at characters. hbfont.c decides how it gets shaped, and the obvious place to say \u0026ldquo;slashed zero, please\u0026rdquo; is on a face, next to the font family and the height.\nA face is attached to whatever text it is on, but the gate in front of the shaper only looks at which character it is, not which face it has. Right now I\u0026rsquo;m bridging that by hand with set-char-table-range, which is fine for me and useless for anyone else. Eli wasn\u0026rsquo;t a fan of that either, but that\u0026rsquo;s for a later part.\nNext The features are still hard-coded in C. Next step is to allow user to configure in Elisp and pass it to font backend.\n","permalink":"https://blog.braineo.dev/posts/emacs-font-features-1/","summary":"\u003cp\u003eI had ligatures working in Emacs with \u003ca href=\"https://github.com/mickeynp/ligature.el\"\u003eligature.el\u003c/a\u003e, and JetBrains Mono drew \u003ccode\u003e!==\u003c/code\u003e as one long bar. It looked great until I tried to tell \u003ccode\u003e!=\u003c/code\u003e from \u003ccode\u003e!==\u003c/code\u003e at a glance. JetBrains Mono ships a few optional extras, and one of them, \u003ccode\u003ess19\u003c/code\u003e, puts small gaps between the equals signs. Next to it was \u003ccode\u003ezero\u003c/code\u003e, a slashed zero instead of the dotted one. I wanted both.\u003c/p\u003e\n\u003cp\u003ePlenty of editors expose these as a setting. In Emacs there is no place to put it. I ended up hacking Emacs and went down a rabbit hole. At the end, on my own build it looks like this:\u003c/p\u003e","title":"Font features in Emacs part 1"},{"content":"I\u0026rsquo;m Binbin Ye. This is where I keep notes worth keeping.\nFind me on GitHub.\n","permalink":"https://blog.braineo.dev/about/","summary":"\u003cp\u003eI\u0026rsquo;m Binbin Ye. This is where I keep notes worth keeping.\u003c/p\u003e\n\u003cp\u003eFind me on \u003ca href=\"https://github.com/braineo\"\u003eGitHub\u003c/a\u003e.\u003c/p\u003e","title":"About"}]