In the solution to Making more easy the itemized of item with tabulation system, I am counting up the number of spaces in order to determine the type of leading character to insert. However, if the I replace the leading spaces with a tab character, the solution does not work.
If I could detect the tab character in the literate, then I could have \ProcessSpace increment the counter NumOfContigousSpaces appropriately, but I don't know how to test for it?
I thought adding tabsize=4, keepspaces=true would do the job but this is not quite enough. So I attempted to use lstag@tabulator from How to automatically skip leading white spaces in listings, but was not able to get that to work.
The code below has a 4 leading spaces before the W in the first line and a tab as the leading character before the W in the second line. This produces no bullet for the line with a tab:

The correct output can be seen by using 4 spaces before the W in both lines:

Note:
- It appears the posting a code snippet here replaces a tab with 4 spaces. So to use the MWE below you will need to replace the four leading spaces before the
Wxxxwith atabcharacter.
Code:
\documentclass{article}
\usepackage{pgf}
\usepackage{xstring}
\usepackage{listings}
\newcounter{NumOfContigousSpaces}%
\setcounter{NumOfContigousSpaces}{0}%
\newcommand{\Width}{1}%
\newcommand{\AddApproriateBulletIfFirstChar}[1]{%
\pgfmathtruncatemacro{\BulletType}{\arabic{NumOfContigousSpaces}/4}%
\IfEqCase{\BulletType}{%
{0}{\gdef\Width{1}}
{1}{\gdef\Width{3}$\bullet$ }
{2}{\gdef\Width{3}$\circ$ }
{3}{\gdef\Width{3}$\times$ }
{4}{\gdef\Width{3}$\star$ }
{5}{\gdef\Width{3}$-$ }
}[\gdef\Width{3}$\bullet$ ]%
#1%
\setcounter{NumOfContigousSpaces}{0}%
}%
\newcommand{\ProcessSpace}{%
\addtocounter{NumOfContigousSpaces}{1}%
\space%
}%
\newcommand*{\ProcessTab}{%
\addtocounter{NumOfContigousSpaces}{4}%
\space\space\space\space%
}%
\makeatletter
\lstdefinestyle{MyItemize}{%
basicstyle=\ttfamily,
columns=flexible,
tabsize=4, keepspaces=true,
literate=%
{\ }{{{\ProcessSpace}}}1% Count contigous spaces
{lstag@tabulator}{{{\ProcessTab}}}4% ??? how detect a tab?
%
%--- much code removed here (See https://tex.stackexchange.com/questions/57939/making-more-easy-the-itemized-of-item-with-tabulation-system for full code)
{W}{{{\AddApproriateBulletIfFirstChar{W}}}}\Width
{x}{{{\AddApproriateBulletIfFirstChar{x}}}}\Width
}%
\makeatother
\begin{document}
\begin{lstlisting}[style=MyItemize]
Wxxx xxx
Wxxx xx xx
\end{lstlisting}
\end{document}

\^^Iis the 'safe' way to type in a tab, and will letlistingsdo the conversion. Unfortunately, there seems to be something up with the width of characters used whencolumns = flexibleis set, as the space used for the 'tab' bullet is different from that for the 'four space' bullet. – Joseph Wright Jun 01 '12 at 06:32\ProcessSpace{4}with a call to\ProcessTabwhich is defined as\newcommand*{\ProcessTab}{\addtocounter{NumOfContigousSpaces}{4}\space\space\space\space}– Peter Grill Jun 01 '12 at 19:34