{"id":5099,"date":"2018-09-04T08:29:08","date_gmt":"2018-09-04T08:29:08","guid":{"rendered":"https:\/\/www.dyalog.com\/blog\/?p=5099"},"modified":"2018-09-04T14:08:21","modified_gmt":"2018-09-04T14:08:21","slug":"enhanced-debugging-with-function-keys","status":"publish","type":"post","link":"https:\/\/www.dyalog.com\/blog\/2018\/09\/enhanced-debugging-with-function-keys\/","title":{"rendered":"Enhanced Debugging with Function Keys"},"content":{"rendered":"<p>Sometimes I want an additional functionality in the IDE. (Are you a RIDE user? We&#8217;ll cover that too!) For example, the other day, I was tracing through some very long functions to find an error which was being caught by a trap. Since the error was being caught, I couldn&#8217;t just let the function run until it would suspend. Again and again, I would press <button>Enter<\/button> too many times, causing the error to happen and be trapped, and thus having to start all over again.<\/p>\n<p><em>I wish I could select a line and run until there<\/em>, I thought. Sure, I could set a break-point there and then continue execution, but that would drop me into the session upon hitting the break-point, and then I&#8217;d have to trace back into the function, and remember to clear the break-point. A repetitive work-flow indeed.<\/p>\n<h2>Make it so!<\/h2>\n<p>Luckily, I know someone who loves doing repetitive tasks: <code class=\"language-apl\">\u2395PFKEY<\/code>. This is what I needed done:<\/p>\n<ol>\n<li>Toggle break-point (to set it)<\/li>\n<li>Resume execution<\/li>\n<li>Trace<\/li>\n<li>Toggle break point (to clear it)<\/li>\n<\/ol>\n<p>A quick look in <strong>Options &gt; Configure\u2026 &gt; Keyboard Shortcuts &gt; Code<\/strong> revealed that the command codes for these are <code>BP<\/code>, <code>RM<\/code>, <code>TC<\/code>, and <code>BP<\/code> again, so I tried:<\/p>\n<pre><code class=\"language-apl\">      'BP' 'RM' 'TC' 'BP' \u2395PFKEY 10\r\n BP  RM  TC  BP <\/code><\/pre>\n<p>I defined a simple function to test it with, and traced into that:<\/p>\n<pre><code class=\"language-apl\">      \u2395FX 'f',\u2395D\r\n      \u2395VR 'f'\r\n     \u2207f\r\n[1]   0\r\n[2]   1\r\n[3]   2\r\n[4]   3\r\n[5]   4\r\n[6]   5\r\n[7]   6\r\n[8]   7\r\n[9]   8\r\n[10]  9\r\n     \u2207 \r\n      f<\/code><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-5219 size-full\" src=\"https:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2018\/08\/TraceIn.png\" alt=\"Tracing into f\" width=\"677\" height=\"304\" srcset=\"https:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2018\/08\/TraceIn.png 677w, https:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2018\/08\/TraceIn-300x135.png 300w, https:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2018\/08\/TraceIn-500x225.png 500w\" sizes=\"auto, (max-width: 677px) 100vw, 677px\" \/><\/p>\n<p>Then I clicked on the line with a <code>7<\/code> on it, pressed <button>F10<\/button>, and lo:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-5221 size-full\" src=\"https:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2018\/08\/Line7.png\" alt=\"Suspended on line 7\" width=\"679\" height=\"305\" srcset=\"https:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2018\/08\/Line7.png 679w, https:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2018\/08\/Line7-300x135.png 300w, https:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2018\/08\/Line7-500x225.png 500w\" sizes=\"auto, (max-width: 679px) 100vw, 679px\" \/><\/p>\n<h2>Keep it so!<\/h2>\n<p>Of course, I wouldn&#8217;t want to be bothered with setting this up in every session. So here&#8217;s a trick to set up F-keys (or anything else for that matter). When Dyalog APL starts up, it will look for <strong>MyUCMDs\\setup.dyalog<\/strong> in your <strong>Documents<\/strong> folder (<strong>$HOME\/MyUCMDs\/setup.dyalog<\/strong> on non-Windows). If this file contains a function named <code>Setup<\/code>, it will be run whenever APL starts:<\/p>\n<pre><code class=\"language-apl\">      \u2207Setup\r\n[1]  '&lt;F10&gt; is: ','BP' 'RM' 'TC' 'BP' \u2395PFKEY 10\r\n[2]  \u2207\r\n      (\u2282\u2395NR'Setup')\u2395NPUT'C:\\Users\\Adam.DYALOG\\Documents\\MyUCMDs\\setup.dyalog'\r\n<\/code><\/pre>\n<p>And now, when I start APL:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-5222 size-full\" src=\"https:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2018\/08\/NewSession.png\" alt=\"New Session\" width=\"714\" height=\"372\" srcset=\"https:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2018\/08\/NewSession.png 714w, https:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2018\/08\/NewSession-300x156.png 300w, https:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2018\/08\/NewSession-500x261.png 500w\" sizes=\"auto, (max-width: 714px) 100vw, 714px\" \/><\/p>\n<h2>Cool, but how about the RIDE?<\/h2>\n<p>Right, the RIDE doesn&#8217;t support <code class=\"language-apl\">\u2395PFKEY<\/code>. However, <strong>Edit &gt; Preferences &gt; Shortcuts<\/strong> lets you both find the relevant command codes and assign them to F-keys. Just put <code>&lt;BP&gt;&lt;RM&gt;&lt;TC&gt;&lt;BP&gt;<\/code> (type or paste those sixteen characters, with angle brackets and everything \u2014 don&#8217;t press the keys they symbolise!) in the <code>PF10<\/code> input field:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-5223 size-full\" src=\"https:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2018\/08\/SettingRIDE.png\" alt=\"Setting F10\" width=\"641\" height=\"593\" srcset=\"https:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2018\/08\/SettingRIDE.png 641w, https:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2018\/08\/SettingRIDE-300x278.png 300w, https:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2018\/08\/SettingRIDE-324x300.png 324w\" sizes=\"auto, (max-width: 641px) 100vw, 641px\" \/><\/p>\n<p>The RIDE saves these preferences for you. Note that you can&#8217;t assign F-keys in <strong>$HOME\/MyUCMDs\/setup.dyalog<\/strong> because <code class=\"language-apl\">\u2395PFKEY<\/code> has no effect in the RIDE, but you can still use that file to initialise other things.<\/p>\n<h2>Taking it one step further\u2026<\/h2>\n<p>After using this for a while, I realised that I often want to &#8220;step into&#8221; a specific line . That is, I found myself pressing <button>F10<\/button> and then <button>Ctrl<\/button>&#8211;<button>Enter<\/button> (the default keystroke for tracing). So I&#8217;ve assigned <button>Ctrl<\/button>&#8211;<button>F10<\/button> the same sequence, but with an additional trailing <code class=\"language-apl\">TC<\/code> action:<\/p>\n<pre><code class=\"language-apl\">      \u2207Setup\r\n[1]  '&lt;F10&gt; is: ','BP' 'RM' 'TC' 'BP' \u2395PFKEY 10\r\n[2]  '&lt;Ctrl&gt;+&lt;F10&gt; is: ','BP' 'RM' 'TC' 'BP' 'TC' \u2395PFKEY 34\r\n[3]  \u2207\r\n      (\u2282\u2395NR'Setup')\u2395NPUT'C:\\Users\\Adam.DYALOG\\Documents\\MyUCMDs\\setup.dyalog'\r\n<\/code><\/pre>\n<p>And for the RIDE, I set <code>PF34<\/code> (which by default is invoked with <button>Ctrl<\/button>&#8211;<button>F10<\/button>) to <code>&lt;BP&gt;&lt;RM&gt;&lt;TC&gt;&lt;BP&gt;&lt;TC&gt;<\/code>:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-5225 size-full\" src=\"https:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2018\/08\/SettingRIDE2.png\" alt=\"Setting Ctrl-F10\" width=\"641\" height=\"593\" srcset=\"https:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2018\/08\/SettingRIDE2.png 641w, https:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2018\/08\/SettingRIDE2-300x278.png 300w, https:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2018\/08\/SettingRIDE2-324x300.png 324w\" sizes=\"auto, (max-width: 641px) 100vw, 641px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes I want an additional functionality in the IDE. (Are you a RIDE user? We&#8217;ll cover that too!) For example, the other day, I was tracing through some very long functions to find an error which was being caught by &hellip; <a href=\"https:\/\/www.dyalog.com\/blog\/2018\/09\/enhanced-debugging-with-function-keys\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":25,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":["post-5099","post","type-post","status-publish","format-standard","hentry","category-tips-tricks"],"_links":{"self":[{"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/posts\/5099","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/users\/25"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/comments?post=5099"}],"version-history":[{"count":55,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/posts\/5099\/revisions"}],"predecessor-version":[{"id":5275,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/posts\/5099\/revisions\/5275"}],"wp:attachment":[{"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/media?parent=5099"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/categories?post=5099"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/tags?post=5099"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}