• FAQ: Feature Request or Bug Report

    Pinned Locked
    1
    10 Votes
    1 Posts
    19k Views
    No one has replied
  • FAQ: Formatting Forum Posts

    Pinned
    1
    4 Votes
    1 Posts
    16k Views
    No one has replied
  • FAQ: Template for Search/Replace Questions

    Pinned
    1
    4 Votes
    1 Posts
    6k Views
    No one has replied
  • FAQ: Logging in to this Forum

    Pinned
    1
    4 Votes
    1 Posts
    2k Views
    No one has replied
  • FAQ: Automating Notepad++

    2
    6 Votes
    2 Posts
    3k Views
    PeterJonesP
    SubFAQ: Using Plugin Commands in Macros

    Plugin commands (even for the default plugins, like MIME Tools) are not macro-recordable. However, with a bit of effort on your part, they can be macro-playable (with some limitations).

    The reason that they aren’t macro-recordable is that macros make use of the menu command ID for storing which command to use. For built-in menu commands, those commands all have a fixed ID, so from one run of Notepad++ to the next, they will always keep the same menu command ID. Since the plugins available and taking up menu space can be different from run-to-run in Notepad++, the application actually assigns the menu command IDs for each plugin dynamically. Thus, if you install or upgrade a plugin such that the number of plugin menu commands change, the next time you run Notepad++, other plugins will possibly get different command IDs compared to the previous run (depending on what order Notepad++ processes each of the plugins).

    Due to this dynamic menu command ID, Notepad++ would not be able to guarantee that a command ID it records for the macro would work for the same command the next time Notepad++ is run, and thus does not record macro commands.

    There are two workarounds:

    Use a scripting plugin (like PythonScript) instead of Macros to do your automation (because scripting plugins usually have helper commands that can search through the menu to be able to run even plugin menu commands). This adds overhead, and you might have to learn a new programming language, but it gives you a lot more power.

    Cheat the macro system. This will be described below, but has the downside that you have to manually edit the macro XML, and you might have to tweak it if you install or upgrade plugins.

    How to Cheat the Macro System

    As I said earlier, the macros are dynamic, depending on the order that Notepad++ processes the plugins and how many menu commands each plugin uses. However, for any stretch of time where you don’t install any new plugins or upgrade existing plugins, Notepad++ will process your plugins in the same order, so they will get the menu command IDs for each run.

    So to cheat the macro, you can snoop to find the current menu command ID for each action, then manually edit the macro’s XML, then restart Notepad++, and the macro should work until the next time you install or update a plugin.

    Let’s assume that you want to have a macro that will Select All, then Plugins > MIME Tools > Base64 Encode with Padding, then Select All, then Copy the results to the clipboard. (inspired by this discussion). Record this sequence and save it as RecordedMacro with no assigned keyboard shortcut. (Just for this example; the names and shortcuts are obviously up to you for your real task.)

    To snoop the menu command ID, I recommend the NppUISpy plugin. So install that plugin, then run it’s Spy! command (either from its menu or toolbar icon).

    For example, with my current plugins, Spy! tells me that Base64 Encode with Padding is Command Id = 22064

    Open %AppData%\Notepad++\shortcuts.xml and edit your recorded macro.

    It would start out as something like this:<Macro name="RecordedMacro" Ctrl="no" Alt="no" Shift="no" Key="0"> <Action type="0" message="2013" wParam="0" lParam="0" sParam="" /> <Action type="0" message="2013" wParam="0" lParam="0" sParam="" /> <Action type="0" message="2178" wParam="0" lParam="0" sParam="" /> </Macro> That is the Select All command twice and the copy (skipping the plugin command between the two Select All. You would need to edit it to be like:<Macro name="RecordedMacro" Ctrl="no" Alt="no" Shift="no" Key="0"> <Action type="0" message="2013" wParam="0" lParam="0" sParam="" /> <Action type="2" message="0" wParam="22064" lParam="0" sParam="0" /> <Action type="0" message="2013" wParam="0" lParam="0" sParam="" /> <Action type="0" message="2178" wParam="0" lParam="0" sParam="" /> </Macro> which puts the 22064 that I found with NppUISpy in between the two Select All instances. Please note that many recorded editor commands (like copy, paste, home, etc) will be type="0" with the scintilla command in the message="..." field; whereas menu commands like the plugin command will be type="2" and put the menuCommandID into the wParam="###" field. See the user manual’s <Macro><Action> details for more. Save the shortcuts.xml and restart Notepad++.

    At this point, running your macro should do the select all, the conversion, the select all, and the copy.

    The next time you installed or upgraded a plugin, you would need to re-run Spy!, and check whether the command ID has changed; if it has, edit shortcuts.xml again, and replace the example 22064 with the new number.

  • 2 Votes
    8 Posts
    10k Views
    guy038G

    Hello, @peterjones,

    Peter, now that the new v8.7.6 release candidate can be used with your improvements regarding the Shortcut Mapper... feature :

    Add ShortcutMapper Multilingual ability, allowing the use of specific keys for non en-US keyboards

    Do you think it would still be useful to create a post listing all the different keyboard configurations that I’ve already e-mailed to you, as documentation ?

    Best Regards,

    guuy038

  • FAQ: Why Can't I Just Say "Most Recent Version"

    1
    5 Votes
    1 Posts
    2k Views
    No one has replied
  • FAQ: How do I create a Poll in the Forum?

    Moved
    3
    1 Votes
    3 Posts
    478 Views
    PeterJonesP

    @Mark-Olson ,

    Moved.

  • FAQ: Parsing and Editing JSON with regex is a bad idea

    2
    3 Votes
    2 Posts
    3k Views
    PeterJonesP
    Corollary: Parsing and Editing XML or HTML with regex is also a bad idea

    For essentially the same reasons.

    More on the horrors of HTML and regex can be found in this Stack Overflow answer.

    For working with XML and similar markups in Notepad++, the plugin XMLTools is an excellent choice as the first line of attack, and using one of the scripting plugins (like PythonScript, LuaScript, or jN) and the XML libraries that are appropriate to that programming language will allow you to tackle the more complicated problems.

  • FAQ: Can I Do a Mathematical Replacement?

    4
    4 Votes
    4 Posts
    5k Views
    PeterJonesP
    MultiReplace Plugin

    The MultiReplace Plugin is another plugin that will allow replacements to use mathematical forumula.

    Starting in Notepad++ v8.5.8, you can install the plugin through Plugins Admin. For older versions of Notepad++, you may be able to install it manually.

    As explained in this post, this is in a nutshell how MultiReplace is working for Math.

    Activating ‘Use Variables’:

    This option facilitates math functions and dynamic string substitutions within a Replace String. It can work with all search settings combined and is not exclusively dependent on regex.

    Commands Overview:

    Either set or cond command is mandatory to set in ‘Replace with’ to wrap the math functions.

    set(strOrCalc) - simple push of math results to Replace cond(condition, trueVal, [falseVal]) - if-then or if-then-else condition for push of results

    Examples of Commands Usage:

    set("replaceString"..CNT) - results in “replaceString3” (assuming CNT = 3). set(LINE+5) - results in “10” (assuming LINE = 5). cond(LINE<=5 or LINE>=9, "edge", "center") - results in “edge” (assuming LINE = 5). cond(LINE<3, "Modify this line") - Keeps original text if condition is false (assuming LINE >= 3). Variables Overview:

    (will be enhanced in future by User requests):

    CNT: Count of the detected string. LINE: Line number where the string is found. APOS: Absolute character position in the document. LPOS: Relative line position. LCNT: Count of the detected string within the line. COL: Column number where the string was found (CSV-Scope option selected). MATCH: Contains the text of the detected string. Special Variables:

    CAP1, CAP2, …: Correspond to regex capture groups $1, $2. CAP variables are usable for calculations or as strings.

    Format Handling: If the CAP variable is a number it can interpret both dot and comma as decimal separators, making international usage more straightforward. Thousand separators are not supported.

    Note: $1 and $2 can be used in ReplaceString but content will only be resolved in CAP Variables for conditions and math functions

    Example of special Variables:
    Find: (\d+.\d+)
    Replace with: set(CAP1 * 1.2) - multiplies decimal number with 1.2

    Basic rules: Strings have to be quoted by ' or " Concatenation is by .. Arithmetic: +, -, *, /, ^, % Relational: ==, ~=, <, >, <=, >= Logical: and, or, not

    Example of combining:
    Find: Price: (\d+(\.\d+)?)
    Replace with: cond(CAP1~=0, "Price per unit: " ..(CAP1/10), "Price cannot be zero") - Calculates Price per Unit if not Zero.

    Further functionality:

    As the engine is LUA driven all LUA math and string functions can be used in set or either cond

    Example with advanced math Function:
    Find: Radius: (\d+)
    Replace with: set("Circumference: "..(2 * math.pi * CAP1)) - Calculates the circumference of a circle given its radius.

    Example with a string function for alignment:
    Find: ;
    Replace with: cond(LCNT == 1, string.rep(" ", 20 - (LPOS))..";") - aligns first occurrence of semicolon in Line to the 20th character position.

  • FAQ: I Cannot Find My Panel!

    1
    6 Votes
    1 Posts
    2k Views
    No one has replied
  • 4 Votes
    1 Posts
    4k Views
    No one has replied
  • FAQ: Periodic Backup vs AutoSave Plugin

    2
    3 Votes
    2 Posts
    14k Views
    PeterJonesP
    AutoSave Plugin v1.61 (For Historical Reference)

    AutoSave Plugin v1.61 has been replaced by v2.00 since September 2022. It is not listed in Plugins Admin. However, you might still be able to go to the repo and download the older version, and manually install it. Unless you desperately need the “Unnamed/new Files” features, it is highly recommended that you use v2.00 or newer, obtained from Plugins Admin.

    When you first installed the AutoSave Plugin v1.61 manually (or years ago), the default configuration is to not have AutoSave providing any automatic saving, so it is doing nothing and you are still relying on Notepad++'s periodic backup (if enabled).

    You will have to configure this plugin if it is going to do any automatic saving for you. You do this by going to the Plugins menu, selecting Auto Save, and picking Options. The following screenshot shows Auto Save v1.61’s default Options dialog:

    e7286d9d-88ed-49d2-82b5-c275180b3440-image.png

    AutoSave When

    These options control when AutoSave is triggered.

    WARNING: If both options remain unchecked, there is no AutoSave occurring and the plugin is doing nothing.

    ☐ Notepad++ loses focus: If this option is checkmarked on ☑, then every time you move from Notepad++ to another window (a Windows explorer, or your browser window, or any other application, or even change focus to the Desktop or clicking on the Windows Start Menu), AutoSave plugin will trigger a save event.

    ☐ At timed intervals every _N_ minutes: If this option is checkmarked on ☑, then every N minutes, AutoSave plugin will trigger save event, even if you have never clicked outside of Notepad++.

    If both of the options are checkmarked on ☑, then AutoSave will trigger a save event every N minutes and everytime Notepad++ loses focus. This saves the most often.

    AutoSave What

    ○ Current file only: If this option is active ⦿, only the “current” file in Notepad++ (the active tab) will have AutoSave events. If you have multiple files open, the other tabs will not be AutoSaved.

    ○ All Open Files: If this option is active ⦿, all files currently opened in Notepad++ will be protected by AutoSave.

    Only one of those two options can be active ⦿.

    Ignore files larger than N KB: If this is set to 0 KB, all files will be AutoSaved. If this is set to a non-zero numbewr, files that are larger than that threshold will not be AutoSaved.

    Named Files

    ○ Ignore/do nothing: If this option is active ⦿, nothing will happen for named files when AutoSave is triggered. This means that named files will not be protected by the AutoSave plugin in this configuration.

    ○ Overwrite existing file: If this option is active ⦿, when AutoSave is triggered, the plugin will send a “Save” command to the Notepad++ application, and the file will be written in the same location where you last manually saved the file (the same place it was when it was first named). Note: This has the side effect of telling Notepad++ that the file is properly saved, so Notepad++ will remove its periodic-backup file for this named file. This feature is basically equivalent to the Plugin hitting the SAVE button for you every time the AutoSave is triggered.

    ○ Save autorecover in the same directory: If this option is active ⦿, when AutoSave is triggered for the named file namedfile.txt, the plugin will create a file with ~ after the extension (namedfile.txt~) in the same directory as the original namedfile.txt. Note: This time, since the state of the main file in Notepad++ is still “unsaved changes”, the Notepad++ periodic-backup for namedfile.txt still exists; Notepad++ and AutoSave plugin will both treat this file as “unsaved”.

    Unnamed/new Files

    ○ Ignore/do nothing: If this option is active ⦿, nothing will happen for unnamed/new files when AutoSave is triggered. This means that unnamed/new files will not be protected by the AutoSave plugin in this configuration.

    ○ Ask for filename: If this option is active ⦿, when AutoSave is triggered, the Plugin will prompt you for a name for the file. Once you enter the filename, AutoSave will tell Notepad++ to do a SaveAs to that location, and the file will now be a named file, and treated according to the Notepad++ and AutoSave rules for named files.

    ○ Save (overwrite) silently here: If this option is active ⦿, you need to choose a directory when you enable this option; the default $CDIR$\autorecover doesn’t seem to carry any meaning; choose a real directory. When AutoSave is triggered, the plugin will create a file called new # (matching Notepad++'s naming scheme) in that folder; from then on, Notepad++ and the AutoSave plugin will treat that file as a named file. Warning: This has the side effect of resetting Notepad++ new # numbering… so be careful, because creating another new file at this point might be given a number that’s already been used but saved by AutoSave, so AutoSave will try to put two files with the same name in the directory you specify.

    ○ Save autorecover here: If this option is active ⦿, you need to choose a directory when you enable this option; the default $CDIR$\autorecover doesn’t seem to carry any meaning; choose a real directory. When AutoSave is triggered, the plugin will create a file called new # (matching Notepad++'s naming scheme) in that folder; however, it still keeps the file that’s shown in Notepad++ as a new/unsaved/unnamed file, so Notead++ and AutoSave Plugin both treat the file as “unsaved” and “unnamed”. This configuration doesn’t reset Notepad++'s new # numbering, so new files created won’t generally collide with the existing autorecover files. When you close a new # tab without saving, the AutoSave plugin’s autorecover file will still exist; however, the next time you create a new tab, if Notepad++ re-uses that number, then the new autorecover file will overwrite the old autorecover file of the same name.

  • 6 Votes
    1 Posts
    4k Views
    No one has replied
  • FAQ: Validating Config-File XML

    1
    3 Votes
    1 Posts
    10k Views
    No one has replied
  • FAQ: New Change History feature

    1
    4 Votes
    1 Posts
    26k Views
    No one has replied
  • FAQ: How do I Replicate the Features of TextFX?

    1
    3 Votes
    1 Posts
    10k Views
    No one has replied
  • 5 Votes
    1 Posts
    8k Views
    No one has replied
  • FAQ: How to install and run a script in PythonScript

    1
    6 Votes
    1 Posts
    11k Views
    No one has replied
  • FAQ: Generic Regular Expression (regex) Formulas

    1
    2 Votes
    1 Posts
    2k Views
    No one has replied