Feature Request: Show only line-final whitespace.



  • Hi.

    I know you can show the spaces and tabs in Notepad++. But I only want to be able to see the whitespaces at the end of lines.

    Can this be done?

    Currently, I have to highlight the stuff to look for them manually, and I know I can trim all the line final whitespace from notepad++, but I also want to be able to see them.



  • @SalviaSage

    You could turn on the line-ending visibility and infer the trailing whitespace locations from that, but that has its own, ugh…heaviness.

    Also, that wouldn’t allow you to differentiate trailing spaces versus tabs…



  • Can this be done?

    Almost. Notepad++ does not expose any option to enable this but you can do it via a plugin such as LuaScript or PythonScript. Using LuaScript you can add the following to the startup script and restart Notepad++.

    npp.AddEventHandler("OnReady", function()
    	editor1.ViewWS = SCWS_VISIBLEAFTERINDENT
    	editor2.ViewWS = SCWS_VISIBLEAFTERINDENT   
    end)
    

    It won’t show whitespace used for indentation, but it still shows it for whitespace between characters and at the end of lines. This is as close as Notepad++ can do for now.



  • dail, I copied the LuaScript.dll into the plugins folder and then edited the startup.lua to look like this

    – Startup script
    – Changes will take effect once Notepad++ is restarted

    npp.AddEventHandler(“OnReady”, function()
    editor1.ViewWS = SCWS_VISIBLEAFTERINDENT
    editor2.ViewWS = SCWS_VISIBLEAFTERINDENT
    end)

    But, I see all whitespace, and not just the line end.



  • That’s odd. Try opening the LuaScript console and running this:

    editor.ViewWS = SCWS_VISIBLEAFTERINDENT
    

    You should see an immediate change. If that works then there is something odd going on with the startup script. Try changing it too this (to see if it prints anything to the console during startup):

    npp.AddEventHandler("OnReady", function()
        print("whitespace")
        editor1.ViewWS = SCWS_VISIBLEAFTERINDENT
        editor2.ViewWS = SCWS_VISIBLEAFTERINDENT   
    end)
    


  • This code is just enabling the show whitespace characters that notepad++ already has. Does it only show the line-final whitespace for you?



  • @SalviaSage It shows the whitespace as the image I posted above.



  • I don’t see anything there, I can only see the whitespace by highlighting the text. I don’t see any kind of marker for them.



  • @SalviaSage No clue then because it works fine for me.



  • Hi, to highlight all whitespaces at the end of lines you can do this:
    1- Open “Mark” part of the search tools. (Search > Mark…)
    2- In “Find what :” type " $" (a whitespace then a $ sign)(without qouting)
    3- Select “Wrap around”
    4- On “Search Mode” part select “Regular expression”
    5- Now push “Mark All” button
    Notepad++ will highlight that whitespaces. You can clear all the highlighting by “Clear all marks” button.

    But if you like to exam thoes whitespaces one by one and then remove them, do this:
    1- Open “Replace” by “Search > Replace…” or by Ctrl+H shortcut.
    2- In “Find what :” type " $" (a whitespace then a $ sign)(without qouting)
    3- “Replace with:” has to be empty
    4- Select “Wrap around”
    5- On “Search Mode” part select “Regular expression”
    Now you can use “Find Next” button to find them one by one and remove them by “Replace” button.



  • @vtech7

    I think the OP’s desire was to see the whitespace continuallyMarking it is fine, but you’d have to keep refreshing that over and over. Doing something one time ever (e.g. @dail 's solution) is a whole lot different than doing something constantly to see a desired effect.



  • @SalviaSage

    FWIW, @dail 's solution works perfectly fine when I try it:

    Imgur



  • Yes, you are right, I also no longer have the initial whitespace being displayed with @dail’s script. However, the whitespace between characters are still shown. I am only interested in showing the final whitespaces instead.

    What else can you think of? thx.



  • I can already easily see the spaces between characters because there is space between them, so I don’t need those marked. I just can’t see the line final spaces unless highlighting them. So, maybe there is a command like 'SCWS_VISIBLEAFTERLASTCHARACTER" I mean, there is already one for ‘visibleafterindent’.

    @dail



  • @SalviaSage said:

    So, maybe there is a command like 'SCWS_VISIBLEAFTERLASTCHARACTER"

    Nope. Would have suggested it it if there was. :)



  • Hello @salviasage, @scott-sumner, @dail, @vtech7 and All,

    Sorry, @salviasage, but Scintilla does not handle a function call, named SCWS_VISIBLEAFTERLASTCHARACTER :-((. Just look at that link, below :

    http://www.scintilla.org/ScintillaDoc.html#SCI_SETVIEWWS

    But don’t be sad ! It’s quite possible to build two macros, with a specific shortcut, for each of them, which will be able to highlight / un-highlight all the trailing blank characters ( Tabulation or Space characters ) of the current file !

    Note that I’m currently using the last 7.5.6 version of N++


    So :

    • Open Notepad++

    • Open your active configuration file, named shortcuts.xml

    Select the text, below, and place it in the clipboard with Ctrl + C

            <Macro name="Visible Ending Blanks" Ctrl="no" Alt="yes" Shift="no" Key="32">
                <Action type="3" message="1700" wParam="0" lParam="0" sParam="" />
                <Action type="3" message="1601" wParam="0" lParam="0" sParam="\h+$" />
                <Action type="3" message="1625" wParam="0" lParam="2" sParam="" />
                <Action type="3" message="1702" wParam="0" lParam="772" sParam="" />
                <Action type="3" message="1701" wParam="0" lParam="1615" sParam="" />
            </Macro>
            <Macro name="Invisible Ending Blanks" Ctrl="no" Alt="yes" Shift="yes" Key="32">
                <Action type="3" message="1700" wParam="0" lParam="0" sParam="" />
                <Action type="3" message="1601" wParam="0" lParam="0" sParam="^" />
                <Action type="3" message="1625" wParam="0" lParam="2" sParam="" />
                <Action type="3" message="1702" wParam="0" lParam="772" sParam="" />
                <Action type="3" message="1701" wParam="0" lParam="1615" sParam="" />
            </Macro>
    
    • Now, place your cursor at the very beginning of the </macros> line, in the shortcut.xml file

    • Then paste the clipboard contents, with Ctrl + V

    • Save the changes done, in shortcut.xml, with Ctrl + S

    • Close and Restart Notepad++ ( IMPORTANT )

    • From now on, every time you want :

      • To visualize the ending blank characters, use the Alt + Spacebar shortcut

      • To suppress the previous Find highlighting, use the Alt + Shift + Spacebar shortcut

    Of course, you may, also, choose the appropriate macro, in the Macro menu of N++


    Notes :

    • I use the \h+$ regex, in order to see the ending blank characters

    • I use the ^ regex, which does not match anything, because it’s a zero-length assertion. ( Instead, you may use, as well, the $ assertion or, even, the zero-length string .{0} ) So, the previous highlighting is simply suppressed :-))

    Cheers,

    guy038

    P.S. :

    In the definition of these two macros :

    • The sParam string, of message 1601, is the regex to search ( \h+$ or ^ )

    • The value 2, of message 1625, refers to the Regular expression search mode

    • The value 772 ( 512 + 256 + 4 ) of message 1702, means :

      • Search in Down direction

      • Option Wrap around ticked

      • Option Purge for each search ticked

    • The value 1615, of message 1701, refers to the Mark all button



  • I wonder what is the Original Poster’s need? Why would you need to find a better way to view the trailing spaces?
    If you need to trim the trailing spaces, you can do it by Find/Replace, with Find what: set to \h+$ or \s+$, and Regular expression chosen.
    If you need to trim the trailing spaces in a lot of files, you can go to the Find in Files… window.
    If you just want to view it, you may just use Edit -> Mask…, which you may be already doing, since you said you can mark it manually.



  • @guy038

    Thanks for your wonderful input.

    I copy pasted your text into the macros subsection, and it looks correct to me. But, it is not being recognized.
    What am I doing wrong?



  • Hi, @salviasage and All,

    You probably didn’t modify the right configuration file. First, you must know where your active configuration files are located :

    • Depending on your initial N++ installation ( with the installer OR from a ZIP or 7Z archive ), the active configuration files can be found :

      • In the same folder as Notepad++ .exe, as well as the zero-length file doLocalConf.xml, in case of a local installation of N++

      • And, in case of an usual installation of N++, with the installer :

        • In the folder %AppData%\Roaming\Notepad++, for a W7, W8 or W10 configuration

        • In the folder %AppData%\Notepad++, for a XP or Vista configuration

    Notes :

    • The environment variable %AppData% represents, generally, the path <Drive Letter>:\Documents and Settings\<User Name>\Application Data

    • BEWARE, the Application Data folder is, usually, an hidden folder. So, you’ll need to enable the visualization of hidden folders in Explorer, first !

    • I also advice you to BACKUP your active shortcuts.xml configuration file, before any change !

    Everything should be OK :-))

    Cheers,

    guy038



  • @guy038

    You are right. I modified the shortcut.xml in the notepad++ installation directory, turns out this is not where you are supposed to add your own macros. (I discovered this just now)

    And as for your macro, I just ran it and it is doing exactly what I want it to do, It marks only the line final spaces and tabs as a pink square.

    The only downfault here is, it has to be ran each time and doesn’t update itself realtime. Can this be made so it works in real time as you are typing?

    Also, how do you start a macro on startup of notepad++?


Log in to reply