Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Change do file editor shortcut keys? (No key is set for Execute (do) from top)

    Hi all,
    I'm using Stata 17.0
    In the do-file editor there are a list of shortcut keys, the one I'm mainly interested in is "Execute (do) from top" but there is no assigned shortcut key for this command and I can't find how to change (or add) shortcut keys?
    Am I missing something, or is this not something that can be done?
    Cheers,
    Simon.

  • #2
    Ctrl-D ?

    Comment


    • #3
      Originally posted by George Ford View Post
      Ctrl-D ?
      Thanks, but Ctrl-D runs either the currently selected line (if selected) or the entire script (if nothing is selected) but it doesn't run the code from the top to the currently selected line. You can do this using the menu, but there's no shortcut assigned to it and I can't see a way to change any of the shortcuts.

      Comment


      • #4
        I see. Odd that this is the only option without a shortcut.

        I'd ask Stata help for guidance.

        might check autohotkey.com.

        Comment


        • #5
          I actually raised this question myself, not that long ago. The solution I was given is:

          Select the line following the desired final line to be executed.
          Then press Ctrl-Shift-Home. This extends the selection to the top of the file.
          Now press Ctrl-D. This causes the extended selection (top of file to originally selected line) to be run.

          Not as convenient as a single key-press, but quite workable.
          Last edited by Clyde Schechter; 02 Dec 2024, 16:09.

          Comment


          • #6
            I downloaded Autohotkeys (autohotkey.com).

            This does the trick.

            Once you create it, you have to click on it to activate. You can also store in Startup to automatically start it, and may be able to use winexec to start it in a profile.do (haven't tried that).

            CTRL+r selects all the code above the cursor and runs it.

            Code for autokeys. I edited in notepad.
            Code:
            #IfWinActive ahk_class do_file_editor
            ^r::  ; Cntl+r will be the trigger
            {
                SendInput, +^{Home}  ; Go to top
                Sleep 50      ; Small delay to ensure commands register
                SendInput, ^d ; Execute to cursor (Ctrl+D)
            }
            You may be able to edit in notepad and save with an .ahk extension, for a more direct approach. I haven't tried it, but that seems to be all that is required. If so, no need for autohotkeys.
            Last edited by George Ford; 02 Dec 2024, 18:38.

            Comment


            • #7
              Thanks both,
              I've been tying exit, then running, then deleting the exit.
              It's super handy to be able to run sections of code with very long do files (especially while debugging!)
              Hopefully it'll be fixed or added at some point!
              I'll have a crack at both methods and see which I like (but still would be good for this to be changed at some stage!)
              Cheers,
              Simon.

              Comment


              • #8
                It worked, and then it didn't.

                Recoded for v2

                Code:
                #HotIf WinActive("ahk_class do_file_editor")
                ^r:: { ; Cntl+r will be the trigger
                    SendInput "+^{Home}"  ; Go to top
                    Sleep 50      ; Small delay to ensure commands register
                    SendInput "^d" ; Execute to cursor (Ctrl+D)
                }

                Comment


                • #9
                  As a less than completely satisfying work around, you can type a random word below the section you're working on like BANANA then Control + D. Stata will throw an error when it hits BANANA and not continue further down the script.

                  Comment


                  • #10
                    Re #9. Yes, that also works. I used to do that myself--I just used the word stop. The problem with that approach is that after I had fixed up that section of code and was ready to move on to the next, I sometimes at first forgot to remove the stop. Just a minor annoyance, I suppose, but one that you don't have with the other methods.

                    Comment


                    • #11
                      While it took about a half hour to get working (though you now have the code), the autohotkeys software did the trick for me.

                      Comment


                      • #12
                        Originally posted by Clyde Schechter View Post
                        Re #9. Yes, that also works. I used to do that myself--I just used the word stop. The problem with that approach is that after I had fixed up that section of code and was ready to move on to the next, I sometimes at first forgot to remove the stop. Just a minor annoyance, I suppose, but one that you don't have with the other methods.
                        Stop is much more sensible than BANANA haha

                        Comment


                        • #13
                          I also have been waiting for this to be fixed. I also use "stop", especially in very long loops - it would be interesting to know if anything like the step-wise running of loops in R could be implemented in Stata. I also use control-shift-home to select upwards... but a simple shortcut would be great. Very small time improvement, but gained at very high frequency.
                          I'm using Stata/MP 17

                          Comment


                          • #14
                            Same difference, as it were, but I use

                            Code:
                            STOP
                            not
                            Code:
                            stop
                            on the grounds that it has the same effect but can be spotted more easily when I need to remove it or comment it out.

                            Comment


                            • #15
                              X

                              Comment

                              Working...
                              X