I need a macro that aligns an object against the right margin, on the current line if this leaves a space between the text and the object, and on the next line otherwise. No other material should appear on the same line as the object in the latter case.

My first attempt (\tmarksi) seems to work, but it causes underfull hbox warnings if it occurs at the end of a paragraph (I don't understand why). The second attempt (\tmarksii) seems to insert an unwanted paragraph break. Therefore I tried locally setting \parskip to zero in the third attempt, but this doesn't work either.
Surely this should not be difficult; what am I missing?
\documentclass{article}
\setlength\parindent{0pt}
\setlength\parskip{2cm} %For illustration purposes
%
\newcommand\tmarksi[1]{\hspace*{\fill}~\mbox{[#1]}\newline}
\newcommand\tmarksii[1]{\hspace*{\fill}~\mbox{[#1]}\vskip0pt}
\newcommand\tmarksiii[1]{\hspace*{\fill}~\mbox{[#1]}\bgroup\parskip=0pt\parindent=0pt\par\egroup}
%
\begin{document}
The quick brown fox jumps over the lazy dog. \tmarksi{1}
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over \tmarksi{1}
the lazy dog.
\end{document}

Overfull \hbox warningswith\tmarksiand that approach seems to be working fine. – Werner Jan 13 '12 at 17:19\tmarksi. I'll edit the question later; I don't have time now. – Ian Thompson Jan 13 '12 at 17:32