Community
    • Login

    Adding a shortcut to a language....

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    7 Posts 6 Posters 3.6k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Charles BuegeC
      Charles Buege
      last edited by

      Hey all!

      Is there an easy way to add a ‘shortcut’ mapping to change to a particular language? I use Notepad++ to past in SQL or PowerShell code periodically and I’ve love to setup CTRL-ALT-S or CTRL-ALT-P to toggle to those languages directly for a quick visual inspection. Is this doable already or do I need to upvote a feature enhancement somewhere?

      Thanks!
      Charles

      1 Reply Last reply Reply Quote 1
      • PeterJonesP
        PeterJones
        last edited by

        Interesting question.

        The languages don’t show up in Settings > Shortcut Mapper, so the easiest possibility isn’t there.

        The language change doesn’t seem to get recorded in a macro.

        I think the issue is that they don’t have a static menu command ID (ie, aren’t listed in menuCmdID.h), so there isn’t a direct way to call them.

        However, some of the scripting plugins, like PythonScript (install instructions here), do have a way to search the menus for an existing command, even if they don’t have a static command ID.

        PythonScript’s notepad.runMenuCommand("Language", "YAML") will change the language to YAML; any languages at the same level will have the same syntax. If you have Preferences > Languages > ☑ Make language menu compact enabled, then the languages under a letter submenu will require a trick: for example Languages > N > Normal Text would be accessed via notepad.runMenuCommand("N", "Normal Text").

        So, if you install PythonScript, then Plugins > Python Script > New Script, and create these two scripts:
        SetLanguageSQL.py

        from Npp import *
        notepad.runMenuCommand("S", "SQL")
        

        SetLanguagePowerShell.py

        from Npp import *
        notepad.runMenuCommand("P", "PowerShell")
        

        Then Plugins > Python Script > Configuration,

        • click on SetLanguageSQL.py and ADD to the Menu Items list
        • click on SetLanguagePowerShell.py and ADD to the Menu Items list

        Once there, restart Notepad++.

        Now Settings > Shortcut Mapper > Plugin Commands will list those two scripts, and you can associate them with keyboard shortcut of your choice.

        BenHastingsFDSUB Riyas Aboobaker Abdul RahmanR Paweł AdamP 3 Replies Last reply Reply Quote 3
        • BenHastingsFDSUB
          BenHastingsFDSU @PeterJones
          last edited by

          @PeterJones Thanks!! This really quite the perfect write-up. Top results off Google and 20 min later, I have icons for “Set Language to SQL” and “Set Language to XML.”

          The PytonScript was a little wonky with allowing me to set the icon. It seemed committed to .bmp or .ico files rather than .png. Ok – found those alternatives. But each time I tried to load them, it just didn’t work. But hey – that’s more the plug-in…

          Your solution worked like a charm! Thank you!

          1 Reply Last reply Reply Quote 1
          • Riyas Aboobaker Abdul RahmanR
            Riyas Aboobaker Abdul Rahman @PeterJones
            last edited by

            @PeterJones Thanks!!

            1 Reply Last reply Reply Quote 0
            • dr ramaanandD dr ramaanand referenced this topic on
            • Paweł AdamP
              Paweł Adam @PeterJones
              last edited by

              This post is deleted!
              1 Reply Last reply Reply Quote 0
              • PeterJonesP
                PeterJones
                last edited by PeterJones

                I had started to reply to a recent post here, but that post was deleted while I was working on my answer.

                But there was part of my response that I think might be useful to future readers of this topic, as it’s not as commonly understood:

                When using notepad.runMenuCommand(...) in the PythonScript plugin, it is using the actual text from the menu names. Thus, it is affected by Settings > Preferences > General > Localization – thus, using the XML example above, in the default English localization, it would be notepad.runMenuCommand("Language", "XML"). But if you were in Pig Latin (for example), it would have to be notepad.runMenuCommand("Anguagelay", "XML"); or if you were in Greek, it would have to be notepad.runMenuCommand("Γλώσσα", "XML")

                (Aside: there’s actually a quirk, though: if you have switched from, for example, Pig Latin to Greek, then until you restart Notepad++, you can use either the Pig Latin or the Greek menu-name-strings in your runMenuCommand calls. Once you restart Notepad++, you can only use the active Localization for those strings.)

                (I don’t know if Localization was actually the problem in the now-deleted post, but it might have been, and it could easily be a problem for other users as well; This actually came up recently, and since it has bearing on this discussion, I thought I would share that main idea here, too: if you are using Localization other than English, you will have to adapt any runMenuCommand calls in your PythonScript scripts to use the actual name of the menu in your GUI, not the English names – whether or not it would have solved the deleted problem, it’s important enough to share.)

                Lycan ThropeL 1 Reply Last reply Reply Quote 2
                • Lycan ThropeL
                  Lycan Thrope @PeterJones
                  last edited by

                  @PeterJones ,
                  I just use the Context menu to create an entry that I can right click on the page and switch to the language I want using the contextMenu.xml file with the following entries.

                          <Item id="0"/>
                          <Item MenuEntryName="Language" subMenuId="language-userDefinedLanguage" name="User Defined Language" MenuItemName="dBASEPlus_Dark"/> 
                          <Item MenuEntryName="Language" subMenuId="language-userDefinedLanguage" name="User Defined Language" MenuItemName="dBASEPlus_Light"/>
                  

                  This seems to me to be the quickest easiest way to do this kind of thing and it’s always available with a right mouse click and selection.

                  1 Reply Last reply Reply Quote 1
                  • First post
                    Last post
                  The Community of users of the Notepad++ text editor.
                  Powered by NodeBB | Contributors