Bump right-aligned text to next line iff no room
You can encourage TeX not to break the lines with \linepenalty
\newcommand*{\FillLine}[2]{%
\noindent\parbox{\linewidth}{%
\rightskip\fill\parfillskip-\rightskip
\linepenalty100
\exhyphenpenalty0
File:~#2\linebreak[0] % <-- Need space here
%Space before \hspace* allows for a break before it
\hspace*{\fill}\texttt{\small CONFIDENTIAL}%
}%
}
This is known in some inner circles as the Bourbaki problem. Here's an adaptation to your needs:
\documentclass{article}
\usepackage[paperwidth=7.0cm,showframe]{geometry}
\newcommand*{\FillLine}[2]{%
\noindent\parbox{\linewidth}{%
\raggedright
File:~#2%
{\nobreak\hfill\penalty50\hskip1em\null\nobreak
\hfill\texttt{\small CONFIDENTIAL}%
\parfillskip=0pt \finalhyphendemerits=0 \par}
}% End of \parbox
}
\begin{document}
\FillLine{Name}{Value}
\bigskip
\FillLine{Name}{A-Long-Value}
\bigskip
\FillLine{Name}{A-Long-Valu}
\bigskip
\FillLine{Name}{A-Long-Val}
\bigskip
\FillLine{Name}{A-Long-Va}
\bigskip
\FillLine{Name}{A-Long-V}
\bigskip
\FillLine{Name}{iiiiiii-iiiii-iiiiiii}
\bigskip
\FillLine{Name}{Some-Really-Really-Long-Value}
\end{document}
How does this work? Look for "Bourbaki" in the source file of the TeXbook.
I guess your friend is \looseness=-1
: http://www.tug.org/utilities/plain/cseq.html#looseness-rp
It doesn't provide ideal result (the break in the last example gets modified), but it seems to work quite well.
\documentclass{article}
\usepackage[paperwidth=7.0cm,showframe]{geometry}
\usepackage{xcolor}
\usepackage{xparse}
\newcommand*{\FillLine}[2]{%
\noindent\parbox{\linewidth}{%
\raggedright
\parfillskip-\rightskip
\looseness=-1
File:~#2\ % <-- Need space here
%Space before \hspace* allows for a break before it
\hspace*{0pt plus 1fil}%
\texttt{\small CONFIDENTIAL}%
}%
}
%\newcommand*{\EnableHyphenationInTexttt}{\hyphenchar\font=45\relax}
%
%\newcommand*{\FillLine}[2]{%
% \noindent\parbox{\linewidth}{%
% \raggedright
% File:~\texttt{\EnableHyphenationInTexttt#2} % <-- Need space here
% %Space before \hspace* allows for a break before it
% \hspace*{\fill}\texttt{\small CONFIDENTIAL}%
% }%
%}
\begin{document}
\FillLine{Name}{Value}
\bigskip
\FillLine{Name}{A-Long-Value}
\bigskip
\FillLine{Name}{iiiiiii-iiiii-iiiiiii}
\bigskip
\FillLine{Name}{Some-Really-Really-Long-Value}
\end{document}