How to clone current document, language included?
-
@PeterJones said in How to clone current document, language included?:
shortcuts.xml, I have annotated the macro
Annotations are good, but I’ve found that if you do it this way, Notepad++ won’t keep the “comments” when it next needs to write out
shortcuts.xml
.(Side Note: I don’t think @PeterJones intended these comments to be permanent, he’s just showing the OP what-does-what for this posting)
So, you could spend a lot of time making nice “comments”, only to have them inconsiderately blown away. :-(
If you want to put a comment in a macro, adding a line like this is a viable technique:
<Action type="0" message="2172" wParam="0" lParam="0" sParam="I am a comment that won't be destroyed" />
Message 2172 is a Scintilla “null” action, so when the macro is run, this line will be noted as such by the macro interpreter, and nothing more happens.
So, while you can’t put “comments” right on the same line of a command like @PeterJones did, you can put a null action message in, with a nice comment, ABOVE the line you want it to apply to.
Sometimes I do this when I see a nice macro on this site; I’ll put in a comment with the link back to it, so I can find it again in the future if I need to refer to it myself, or a future poster has a similar need…I can quickly provide it.
-
Hello, @dario-de-judicibus-0, @alan-kilborn, @peterjones and All,
Why not use a complete comment line ?
For instance, this line comment in the native
Trim Trailing Space and Save
macro of N++ remains across sessions and start/close N++ actions, whatever I’ve previously used this macro or not ;-))<Macro name="Trim Trailing Space and Save" Ctrl="no" Alt="yes" Shift="yes" Key="83"> <Action type="2" message="0" wParam="42024" lParam="0" sParam="" /> <!-- The line BELOW will save the CURRENT file ---> <Action type="2" message="0" wParam="41006" lParam="0" sParam="" /> </Macro>
I don’t think that it depends on your Windows system, as I’m ( still ) with
Windows XP
! But, may be it’s related to the fact that I’ve got a local configuration. So, theshortcuts.xml
file is along with the other configuration files and notepad++.exe in a same folderD:\@@\791
Cheers,
guy038
-
@guy038 said in How to clone current document, language included?:
<!-- The line BELOW will save the CURRENT file —>
For me, if I insert such a standalone line, or indeed, as I mentioned earlier, an xml comment on a non-comment line, Notepad++ removes it the next time something happens that causes it to write out
shortcuts.xml
.Examples of that include: recording a macro, deleting a macro, assigning/removing a shortcut key to anything, changing/deleting a Run menu entry, etc.
Technically, I don’t think it “removes” it, I think it just starts from scratch in writing the file with what it thinks should be there. Since it knows nothing about my comment – gone!
This is different from, say
english_customizable.xml
(or whatever language file you use), which Notepad++ only reads, and never writes to. There, any comments you place, remain. -
Hi, @alan-kilborn,
Weird ! For me, I just tried with N++
v7.8.5
and the last7.9.1
version and the comment remains !?
Of course, my two releases are local ones !Here’s is my
debug-info
information :Notepad++ v7.9.1 (32-bit) Build time : Oct 27 2020 - 16:07:12 Path : D:\@@\791\notepad++.exe Admin mode : OFF Local Conf mode : ON OS Name : Microsoft Windows XP (32-bit) OS Build : 2600.0 Current ANSI codepage : 1252 Plugins : mimeTools.dll NppConverter.dll NppExport.dll
BR
guy038
-
Can anyone else replicate either my behavior, or Guy’s ?
Here’s what I’m using:
Notepad++ v7.9.1 (32-bit)
Build time : Nov 2 2020 - 01:03:56
Path : C:\…\npp.portable\notepad++.exe
Admin mode : OFF
Local Conf mode : ON
OS Name : Windows 10 Enterprise (64-bit)
OS Version : 1809
OS Build : 17763.1577
Current ANSI codepage : 1252 -
I’m with Alan on this one: if I add a comment, save/exit/reload, it’s still there. But if I then record/save a macro, exit and reload, the comment from the existing macro is gone.
Notepad++ v7.9.1 (64-bit) Build time : Nov 2 2020 - 01:07:46 Path : C:\usr\local\apps\notepad++\notepad++.exe Admin mode : OFF Local Conf mode : ON OS Name : Windows 10 Enterprise (64-bit) OS Version : 1903 OS Build : 18362.1198 Current ANSI codepage : 1252 Plugins : ComparePlugin.dll ExtSettings.dll HexEditor.dll LuaScript.dll MarkdownViewerPlusPlus.dll mimeTools.dll NppConsole.dll NppConverter.dll NppEditorConfig.dll NppExec.dll NppExport.dll NppFTP.dll NppUISpy.dll PreviewHTML.dll PythonScript.dll QuickText.dll RestApiToText.dll TagLEET.dll XMLTools.dll
-
@PeterJones said in How to clone current document, language included?:
I’m with Alan on this one: if I add a comment, save/exit/reload, it’s still there. But if I then record/save a macro, exit and reload, the comment from the existing macro is gone.
Me too !
Notepad++ v7.9.1 (64-bit)
Build time : Nov 2 2020 - 01:07:46
Path : D:\Aplicaciones\npp.7.9.1.portable.x64\notepad++.exe
Admin mode : ON
Local Conf mode : ON
OS Name : Windows 7 Professional (64-bit)
OS Build : 7601.24546
Current ANSI codepage : 1252
Plugins : BetterMultiSelection.dll mimeTools.dll NppConverter.dll NppExport.dll PythonScript.dll -
I’m wondering if Guy did the correct kind of change during his testing… or if his really works differently.
-
Hello, @dario-de-judicibus-0, @alan-kilborn, @peterjones, @astrosofista and All,
As I kept the habit, most of the time, to modify configuration files from outside N++, with Microsoft Notepad, I chose the other method:
-
I started Notepad++
-
I opened
shortcut.xml
, from within N++, -
I added this new macro, below, without any associated shortcut
<Macro name="TEST COMMENT" Ctrl="no" Alt="yes" Shift="yes" Key="0"> <Action type="2" message="0" wParam="42024" lParam="0" sParam="" /> <!-- The line BELOW will save the CURRENT file ---> <Action type="2" message="0" wParam="41006" lParam="0" sParam="" /> </Macro>
-
I closed the
shortcuts.xml
tab (Ctrl + W
) -
I closed Notepad++ (
ALT + F4
) -
I opened
shortcuts.xml
with Microsoft Notepad => The different comments were still here -
I re-started N++
-
I processed the macro (
Macro > TEST COMMENT
menu option ), after adding some blank chars at end of some lines ofchange.log
file => it did trim the trailing spaces and savechange.log
file ! -
Again, I closed N++
-
Viewing again
shortcuts.xml
with Microsoft Notepad => The different comments were still here -
I re-started N++
-
I opened
Shortcuts.xml
, from within N++ => All was fine : the comment is still present !
So… I do not understand at all !
Thus, unlike I said before, it could be related to the operating software itself !? I’ll try this assumption later, on my wife’s W8 laptop… when she’s at work! I know her password but shhh ;-))
I’ll just paste all my
791
folder on her laptop’s desktop. Really curious of the result !Best regards,
guy038
-
-
@guy038 said in How to clone current document, language included?:
I do not understand at all !
From your description, your “workflow” for this doesn’t include anything which will cause Notepad++ itself to need to update
shortcuts.xml
.After you have your nice comments (manually) added to shortcuts.xml, use the macro recorder to record a simple macro, then save the macro with a name. Then restart Notepad++ and examine shortcuts.xml. You should see your new named macro present but any xml comments you put in the file are now eliminated.
-
I tried further experiments, with extra pseudo-attributes (like
<Action type="2" message="0" wParam="42024" lParam="0" sParam="" commentAttribute="value" />
) and after saving or deleting a different macro in Notepad++, it still got rid of it – I was hoping it would keep unknown attributes, but it didn’t. :-( -
Hello, @dario-de-judicibus-0, @alan-kilborn, @peterjones, @astrosofista and All,
Oh…, I just forgot one line in my previous post, right after the black window text :
- I saved the new
TEST COMMENT
macro (Ctrl + S
) from within N++
I really saved this macro ! Otherwise, I would not have been able to see it in the Macro menu and to execute it, later. !!
On the other hand, how you explain that, by default, these comments in the
UserDefinedCommands
node are kept overs sessions ?<!-- The following shortcuts are dangerous if your computer is compromised. (But if your computer is compromised, EVERYTHING IS DANGEROUS!) Remove the comment and use them at your own risk!!! <Command name="Launch in Firefox" Ctrl="yes" Alt="yes" Shift="yes" Key="88">firefox "$(FULL_CURRENT_PATH)"</Command> <Command name="Launch in IE" Ctrl="yes" Alt="yes" Shift="yes" Key="73">iexplore "$(FULL_CURRENT_PATH)"</Command> <Command name="Launch in Chrome" Ctrl="yes" Alt="yes" Shift="yes" Key="82">chrome "$(FULL_CURRENT_PATH)"</Command> <Command name="Launch in Safari" Ctrl="yes" Alt="yes" Shift="yes" Key="65">safari "$(FULL_CURRENT_PATH)"</Command> <Command name="Send via Outlook" Ctrl="yes" Alt="yes" Shift="yes" Key="79">outlook /a "$(FULL_CURRENT_PATH)"</Command> -->
Now, all this story becomes crazy ! I did not have any problem with my wife’s
W8
laptop, too !I mean the comments are well preserved in the
shortcuts.xml
configuration file, no matter what operations I did !As I said before, I simply copied a folder
791
, containing the last portable version of N++, on the desktopAnd I copied/pasted the original
Trim Trailing Space and Save
macro, located at beginning of the<Macros>
node, with the new nameTEST COMMENT
, right before the line</Macros>
and then saved the modifiedshortcuts.xml
from within N++I have no idea what’s going on ! I also verified the attributes of
shortcuts.xml
: just the normalA
rchived attributeNote that my
shortcuts.xml
files areUTF-8
encoded files. BTW, do not save theshortcuts.xml
with theUTF-8-BOM
encoding, by mistake. In this case, all the recorded macros are greyed in theMacro
menu !Does anyone have an other suggestion ?
Cheers,
guy038
P.S.* : It’s past lunchtime here, but I’m going to have a bite to eat ;-))
- I saved the new
-
@PeterJones said in How to clone current document, language included?:
I was hoping it would keep unknown attributes…
Well, if you know it isn’t being used by a particular action, you can put some “comment text” in the
sParam=""
area of a non-2172 action, and it will be retained. This keeps the “same line” comment idea alive.But I truly think the “2172” type of comment is probably best/safest, even if it isn’t on the same line that it discusses.
I supposed it would be nice to have direct support for a
comment="blah blah blah"
type attribute. But, the whole idea of hand-editingshortcuts.xml
is an advanced concept, rather “hackish”, and a bit dangerous (potential data loss, as discussed), so I’m okay with it the way it is. -
@guy038 said in How to clone current document, language included?:
Now, all this story becomes crazy
Does anyone have an other suggestion ?
I’m out of ideas for you. :-)
-
-
Fresh NPP Portable:
-
Duplicate macro, add a variety of comment styles:
-
Exit/Reload Notepad++: no change to screenshot #2
-
Start recording macro, type
blah
, backspace outblah
, save, stop recording, save macro asblah
. -
Exit /Reload Notepad++. All comments, including the default original comments, are gone.
I don’t know how it works for you, because no matter what I do, any sequence like I just showed, which saves or deletes a macro from the macro-recording panel, gets rid of all comments from the XML.
While doing the experiment, I noticed that the default comments from the unedited shortcuts.xml had tabs, whereas in my previous experiment, I had used spaces, so I tried with both styles of comments; the unedited used multi-line comments with only the start/start on a line, and the text of the comment between, so I tried that too. But all of those comments, no matter what style, disappeared.
I wish I knew how you got it to keep the comments.
-
-
Hello, @dario-de-judicibus-0, @alan-kilborn, @peterjones, @astrosofista and All,
Aaaah ! I’m sorry and apologize for making, all of you, searching hard ! It’s all my fault !
Indeed, when @alan-kilborn said :
From your description, your “workflow” for this doesn’t include anything which will cause Notepad++ itself to need to update shortcuts.xml
I just thought that he was speaking about the fact of saving the
shortcuts.xml
file with Microsoft Notepad and not from within Notepad++ !But I understood, at once, all the story then @peterjones said :
- Start recording macro, type blah, backspace out blah, save, stop recording, save macro as
blah
Like you, when I decided to record a new macro and give it a name, and, after closing and restarting N++, all comments were gone away in
shortcuts.xml
, even those located outside the<Macros>
node and, also, the default comments of the initialshortcuts.xml
file, located in theUserDefinedCommands
section, below :<!-- The following shortcuts are dangerous if your computer is compromised. (But if your computer is compromised, EVERYTHING IS DANGEROUS!) Remove the comment and use them at your own risk!!! <Command name="Launch in Firefox" Ctrl="yes" Alt="yes" Shift="yes" Key="88">firefox "$(FULL_CURRENT_PATH)"</Command> <Command name="Launch in IE" Ctrl="yes" Alt="yes" Shift="yes" Key="73">iexplore "$(FULL_CURRENT_PATH)"</Command> <Command name="Launch in Chrome" Ctrl="yes" Alt="yes" Shift="yes" Key="82">chrome "$(FULL_CURRENT_PATH)"</Command> <Command name="Launch in Safari" Ctrl="yes" Alt="yes" Shift="yes" Key="65">safari "$(FULL_CURRENT_PATH)"</Command> <Command name="Send via Outlook" Ctrl="yes" Alt="yes" Shift="yes" Key="79">outlook /a "$(FULL_CURRENT_PATH)"</Command> -->
Wooooh, everything is, again, logic between all our configurations ;-))
So, as any macro recording deletes all comments, a simple work-around would be to :
-
Copy your present
shortcuts.xml
file as, say,shortcuts_comments.xml
-
Comment all your macros already created, in the
shortcuts_comments.xml
, as you like to -
Record your new macro, in Notepad++
-
Close and re-start Notepad++
-
Open, both, the
shortcuts.xml
andshortcuts_comments.xml
files, in N++ -
Copy your new macro from the
shortcuts.xml
file -
Paste it in the
shortcuts_comments.xml
file -
Add the wanted comments in the
shortcuts_comments.xml
file, relative to this new macro -
Save the
shortcuts_comments.xml
file
With this method, in addition to having a nice version with comments, that we may post in our site, we also benefit from a backup of the
shortcuts.xml
file. Indeed, if, by mistake, theshortcuts.xml
is deleted, simply copyshortcuts_comments.xml
asshortcuts.xml
and your comments will even remain inshortcuts.xml
until your next macro recording ;-))Best Regards,
guy038
- Start recording macro, type blah, backspace out blah, save, stop recording, save macro as