editortext-editorgeany

Shortcut, set filetype Geany


Every time I create a new file I have to select the file type manually via Document->Set Filetype->.....

Is there a shortcut or a custom command I can use to select programming language to pascal fast?


Solution

  • I'm glad you asked. The same annoyance bugs me every I create a new file to write a Bash script. So, I worked out a solution.

    If you're using a Linux system, you can set up a custom command to call xdotool to do the job. If you don't have it installed, it should be available in your distro's repo. With xdotool, you can simulate a sequence of keypresses to do the work of selecting Pascal for you.

    1. Go to Edit > Format > Send Selection to > Set Custom Commands
    2. Click the Add button
    3. Enter the appropriate xdotool command in the Command edit box (see below)
    4. Hit the Enter key (Important! If you don't hit Enter, Geany won't save what's in the box.)
    5. Click the OK button

    The exact command to select Pascal on my Geany installation is...

    xdotool key alt+d t p Page_Down Up Up Up Up Up Up Up Return
    

    ...but make adjustments if needed.

    You'll also want to set a keyboard shortcut to run the custom command. (Important! The new document needs to have focus for the custom command to work.) You can try Ctrl+1, which is supposed to be the default keyboard shortcut for Custom Command 1, but it wouldn't work on my Geany installation for some reason. If you have the same issue, then...

    1. Go to Edit > Preferences > Keybindings
    2. Scroll down to "Send to Custom Command 1"
    3. Click the Change button
    4. Press the combination of keys you want for the shortcut
    5. Click the OK button
    6. Test the shortcut (Geany seems weirdly strict about what key combinations will work, so you may have to try a few. I got it working by choosing Alt+1.)

    If you're using Windows, where xdotool isn't available, I'd probably try out xdotool-for-windows first, and if it didn't work out I'd see if something listed at AlternativeTo would serve the purpose.