Menu

BUG: Notepad++ plugin can't work without UNIX line endings + UniversalIndentGUI.exe can't work with Mac line endings

2016-07-10
2016-07-10
  • Tanzinul Islam

    Tanzinul Islam - 2016-07-10

    I've got the following minified 3-line piece of C++ (note the last line may show up wrapped in this post):

    #include<map>
    #include<iostream>
    int main(){std::map<int,char>myMap;for(std::map<int,char>::iterator it=myMap.begin();it!=myMap.end();++it){std::cout<<it->first<<"\t"<<it->second<<std::endl;}}
    

    Inside Notepad++, if I have the Edit -> EOL Conversion mode set to Windows Format (CR-LF), then running any indenter on this text results in unnecessary blank lines between the above lines. This is happening inside the UniversalIndentGUI plugin, before the indenter gets to see the text.

    This problem does not happen if my EOL Conversion mode is set to UNIX/OSX Format (LF) inside Notepad++. This also does not happen if I opened the file (containing Windows-style line endings) directly in UniversalIndentGUI.exe and applied the indenter -- probably it knows how to interpret both formats for its workings. However, if my file was saved with Macintosh-style line endings (CR), then neither the Notepad++ plugin nor the UniversalIndentGUI.exe program can recognize the 3 lines in the file distinctly.

    I am running:

    • Notepad++ version 6.9.2 + UniversalIndentGUI plugin version 1.0.2
    • Full UniversalIndentGUI.exe download version 1.2.0
     

    Last edit: Tanzinul Islam 2018-05-26
  • Tanzinul Islam

    Tanzinul Islam - 2016-07-10

    For anyone else who encountered this problem, my workaround is to not use the UniversalIndentGUI.exe program at all (due to its inability to work with Mac-style line endings and other unrelated limitations in the UI). Instead, I use a NppExec wrapper script to temporarily convert the file to UNIX-style line endings and invoke the Plugins -> UniversalIndentGUI -> Indent text menu command of Notepad++ (all as a single undoable action):

    NPP_CONSOLE ?
    SCI_SENDMSG SCI_GETEOLMODE
    SET LOCAL endOfLineMode = $(MSG_RESULT)
    SCI_SENDMSG SCI_BEGINUNDOACTION
    SCI_SENDMSG SCI_CONVERTEOLS 2
    NPP_MENUCOMMAND Plugins|UniversalIndentGUI|Indent text
    SCI_SENDMSG SCI_CONVERTEOLS $(endOfLineMode)
    SCI_SENDMSG SCI_ENDUNDOACTION
    

    For ease-of-use, I add this script as a NppExec submenu item in Plugins -> NppExec -> Advanced Options, and then bind to that menu item in Settings -> Edit Popup ContextMenu:

    <Item FolderName="Plugin commands" PluginEntryName="NppExec" PluginCommandItemName="Workaround IndentText EOL Bug" ItemNameAs="Indent Text" />
    

    Afterwards I can easily launch this in Notepad++ (with or without any text selected) via the right-click menu -> Plugin commands -> Indent Text.

     

    Last edit: Tanzinul Islam 2016-07-10

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.