{"id":13320,"date":"2025-10-07T10:53:06","date_gmt":"2025-10-07T14:53:06","guid":{"rendered":"https:\/\/irreal.org\/blog\/?p=13320"},"modified":"2025-10-07T10:53:06","modified_gmt":"2025-10-07T14:53:06","slug":"printf-style-debugging-of-elisp","status":"publish","type":"post","link":"https:\/\/irreal.org\/blog\/?p=13320","title":{"rendered":"Printf Style Debugging Of Elisp"},"content":{"rendered":"<p>\nAll the cool kids use debuggers for debugging their code. In most situations that&rsquo;s the right answer. After all, you can set breakpoints, step through your code, and examine values at each step. If you want a detailed view into what your code is doing, debuggers are the best solution.\n<\/p>\n<p>\nSometimes, though, they&rsquo;re a bit heavy weight and way more than you need. Often all you need is a few strategically placed <code>printf<\/code>\u200bs to get the necessary information to solve the problem. Sometimes, for various reasons, you can&rsquo;t use a debugger so you&rsquo;re forced to fall back on <code>printf<\/code>.\n<\/p>\n<p>\nMarcin Borkowski (mbork) has a <a href=\"https:\/\/mbork.pl\/2025-10-06_A_debug_helper_in_Elisp\">nice example of the latter<\/a>. He was debugging an Elisp function that messed with windows and that interfered with <a href=\"https:\/\/www.gnu.org\/software\/emacs\/manual\/html_node\/elisp\/Edebug.html\">Edebug<\/a>&rsquo;s use of those windows. The answer, of course, was to fall back to the <code>printf<\/code> method. The natural solution was to use the Elisp <code>message<\/code> function but there were some problems. The first problem was easy. The messages appeared in the minibuffer and disappeared before he could read them. He fixed that by wrapping <code>message<\/code> in a function that waited for a key press before continuing.\n<\/p>\n<p>\nThen he noticed that virtually all his invocations were of the form <code>(message \"var1: %s, var2: %s\" var1 var2)<\/code>, and that it made sense to abstract that a bit into a new function. That brought a couple of new problems but they were also easily dealt with.\n<\/p>\n<p>\nMbork&rsquo;s post is well worth reading and his code is worth a bit of study too. I like the way he just digs in and solves the problems without too much worry about whether or not it&rsquo;s the best way. At the end of the day, he solved his problem and that&rsquo;s what matters.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>All the cool kids use debuggers for debugging their code. In most situations that&rsquo;s the right answer. After all, you can set breakpoints, step through your code, and examine values at each step. If you want a detailed view into &hellip; <a href=\"https:\/\/irreal.org\/blog\/?p=13320\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[26,18],"class_list":["post-13320","post","type-post","status-publish","format-standard","hentry","category-general","tag-elisp","tag-emacs"],"_links":{"self":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/13320","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=13320"}],"version-history":[{"count":1,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/13320\/revisions"}],"predecessor-version":[{"id":13321,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/13320\/revisions\/13321"}],"wp:attachment":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=13320"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=13320"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=13320"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}