{"id":10376,"date":"2022-03-07T15:58:13","date_gmt":"2022-03-07T20:58:13","guid":{"rendered":"https:\/\/irreal.org\/blog\/?p=10376"},"modified":"2022-03-07T15:58:13","modified_gmt":"2022-03-07T20:58:13","slug":"understanding-hi-line-mode","status":"publish","type":"post","link":"https:\/\/irreal.org\/blog\/?p=10376","title":{"rendered":"Understanding Hi-line-mode"},"content":{"rendered":"<p>Tony Aldon wondered how <code>hi-line-mode<\/code> worked so he looked into it. He was so enchanted with what he found that he decided to <a href=\"https:\/\/www.reddit.com\/r\/emacs\/comments\/t7doal\/i_bet_you_use_hllinemode_do_you_know_how_it_works\/\">share it on reddit<\/a>. That might not sound too interesting but <code>hi-line-mode<\/code> depends on two Emacs features, <code>post-command-hook<\/code> and overlays, that are interesting in their own right. Once you understand them, understanding <code>hi-line-mode<\/code> is trivial.<\/p>\n<p>The <code>post-command-hook<\/code> variable, as its name suggests, contains a list of functions to run after every command. Since virtually everything Emacs does\u2014including inserting characters into a buffer\u2014is through a command, the hook gets run every time Emacs does something. In particular, <code>hi-line-mode<\/code> can be called after every command to update the current line\u2019s highlighting.<\/p>\n<p>The other important aspect of <code>hi-line-mode<\/code> is the overlay. This is pretty simple and allows you to, among other things, change the text face of a region in the buffer. In the case of <code>hi-line-mode<\/code>, it changes the background color of the current line to whatever color you\u2019ve chosen.<\/p>\n<p>Once you grok hooks and overlays, it\u2019s easy to understand how <code>hi-line-mode<\/code> works. Aldon\u2019s post is useful not because it explains how <code>hi-line-mode<\/code> works but because it explains <code>post-command-hook<\/code> and overlays. Those are things you can use in your own Elisp code.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Tony Aldon wondered how hi-line-mode worked so he looked into it. He was so enchanted with what he found that he decided to share it on reddit. That might not sound too interesting but hi-line-mode depends on two Emacs features, &hellip; <a href=\"https:\/\/irreal.org\/blog\/?p=10376\">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":[18],"class_list":["post-10376","post","type-post","status-publish","format-standard","hentry","category-general","tag-emacs"],"_links":{"self":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/10376","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=10376"}],"version-history":[{"count":1,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/10376\/revisions"}],"predecessor-version":[{"id":10377,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/10376\/revisions\/10377"}],"wp:attachment":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10376"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10376"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10376"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}