Button to toggle Tabs/Spaces?
-
Is there a way to have a button that toggles between Tabs/Spaces so I can easily configure while editing?
-
Sorry, no, there is a checkbox in the Settings > Preferences > Language > Tab Settings > Replace by space. But I don’t think that can be toggled easily without going into that dialog. (Unfortunately, I don’t even think that it is exposed to the API, so I don’t think you could toggle that using PythonScript or similar scripting/plugin interface… but one of the other PythonScript gurus can feel free to prove me wrong.)
-
@peterjones said in Button to toggle Tabs/Spaces?:
Settings > Preferences > Language > Tab Settings > Replace by space
Yeah, that’s why I was looking for a button option. For me, it’s an issue when I’m dealing with different configuration files since I don’t do any development work, but the files end up looking really weird, I have to spend time reformatting, I have to go through those menus, or I have to use a second different editor.
I do see there is an automatic detection tool, but most of my editing is copying from terminal into blank document, but maybe I should play around with that more.
You wouldn’t happen to know how I might get Tab into a Find or Replace field?
-
If you spend most of your time copying into blank documents, then changing between two languages (which you choose to have different tab/space settings) might be enough. You might even just keep two tabs open, renamed (but not saved) as
tab config
andspace config
, with the language on each tab selected so that each has the right tab setting.To find a tab, you can use Extended Mode or Regular Expression Mode and use
\t
in the FIND WHAT field. -
@myfirstnameispaul said in Button to toggle Tabs/Spaces?:
You wouldn’t happen to know how I might get Tab into a Find or Replace field?
@peterjones said in Button to toggle Tabs/Spaces?:
To find a tab, you can use Extended Mode or Regular Expression Mode and use \t in the FIND WHAT field.
If you want to stick to Normal search mode you can get a tab into the FW box by selecting it first in the editing window and then pressing Ctrl+f. In the FW box it will just look like a really wide space.
-
Using SCI_SETUSETABS could do this for the current buffer, but must be reapplied each time the buffer is activated.
-
But it’s not that easy, is it?
If we load a file and it looks strange, how do we know what to do?
I mean, if a tab is used, how does the script know that it has to be replaced by 2 or 4 or 8 spaces? -
@ekopalypse said in Button to toggle Tabs/Spaces?:
Using SCI_SETUSETABS could do this for the current buffer, but must be reapplied each time the buffer is activated.
Yep, I have a little NppExec script that does this for me on the rare occasion I need to deal with tabs in files (other than Makefile which has “use tabs” set in my Notepad++ preferences); I use convert tabs to 4 spaces by default everywhere else:
::tab NPP_CONSOLE keep IF "$(ARGC)"<="1" THEN // SCI_SENDMSG SCI_GETCURRENTPOS // SCI_SENDMSG SCI_INSERTTEXT $(MSG_RESULT) "$(TAB)" SCI_SENDMSG SCI_ADDTEXT 1 "$(TAB)" ELSE IF "$(ARGV[1])"~="$(ON)" THEN SCI_SENDMSG SCI_SETUSETABS 1 IF "$(ARGC)">"2" THEN SCI_SENDMSG SCI_SETTABWIDTH $(ARGV[2]) ENDIF ELSE IF "$(ARGV[1])"~="$(OFF)" THEN SCI_SENDMSG SCI_SETUSETABS 0 ELSE IF "$(ARGV[1])"~="bs" THEN IF "$(ARGC)">"2" THEN IF "$(ARGV[2])"~="$(FALSE)" THEN SCI_SENDMSG SCI_SETBACKSPACEUNINDENTS $(FALSE) ELSE SCI_SENDMSG SCI_SETBACKSPACEUNINDENTS $(TRUE) ENDIF ELSE SCI_SENDMSG SCI_GETBACKSPACEUNINDENTS ECHO Backspace Unindents = $(MSG_RESULT) ENDIF GOTO END ELSE IF "$(ARGV[1])"~="status" THEN SCI_SENDMSG SCI_GETUSETABS SET LOCAL TABON = $(MSG_RESULT) SCI_SENDMSG SCI_GETTABWIDTH SET LOCAL WIDTH = $(MSG_RESULT) ECHO TABS = $(TABON) ($(WIDTH)) SCI_SENDMSG SCI_GETBACKSPACEUNINDENTS ECHO BS Unindents = $(MSG_RESULT) ELSE GOTO USAGE ENDIF GOTO END :USAGE ECHO Usage: ECHO \$(ARGV[0]) = insert a tab (non-expanded regardless of setting) at current position ECHO \$(ARGV[0]) status = current tab setting ECHO \$(ARGV[0]) $(ON) [W] | $(OFF) = enable tabs (no space convert) using optional W tab width | disable (convert to spaces) ECHO \$(ARGV[0]) bs $(ON) | $(OFF) = enable | disable backspace unindents :END
Note the
$(ON)
and$(OFF)
are set in my NppExec startup:... SET TRUE=1 SET FALSE=0 SET ON=$(TRUE) SET OFF=$(FALSE) ...
Cheers.
-
I get the mental image of the OP playing a version of WHACKAMOLE with tab characters.