So, I'm trying to answer this question: Extended draft mode which includes source information for manual print-out to source synchronisation and I've run into a weird problem. Check out this example:
\documentclass{article}
\usepackage{everyhook,marginnote}
\newif\ifnotmarginhook
\notmarginhooktrue
\PushPreHook{par}{%
\ifnotmarginhook
\notmarginhookfalse
\smash{\marginnote{\small\ttfamily\the\inputlineno}}
\notmarginhooktrue
\fi
}
\makeatletter
% \renewcommand\paragraph{\@startsection{paragraph}{4}{\z@}%
% {3.25ex \@plus1ex \@minus.2ex}%
% {1em}%
% {\normalfont\normalsize\bfseries}}
\makeatother
\begin{document}
\section{This works}
Here is some text and it will go on and on
Here is some text and it will go on and on
Here is some text and it will go on and on
\subsection{This too}
Here is some text and it will go on and on
Here is some text and it will go on and on
Here is some text and it will go on and on
\paragraph{Broken!}
Here is some text and it will go on and on
Here is some text and it will go on and on
Here is some text and it will go on and on
\end{document}

If you change the definition of \paragraph to have a positive value for afterskip (as in the commented out redefinition) then everything is fine. What is going on and how do I fix it? It looks like something is messing with boxes, but I don't understand what...
It looks like there's some funny business going on: my guess is that the negative skip means that TeX does \rlap of the paragraph name, measures the text of the paragraph title, then puts that much space at the start of a noindent paragraph plus the afterskip amount. Is something like that going on? How can I stop it overlapping?

\paragraphcommand uses\everyparto typeset its title at the start of the next paragraph, so there's nothing really surprising that a conflict can exist. In your example, the problem seems to disappear by using\PushPostHookinstead of\PushPreHookand recompiling twice. – Philippe Goutet Aug 08 '11 at 18:10everyhookdocumentation has a remark along the lines of "careful if you use\PushPreHook{par}: you should\setbox0\lastboxand put\box0after your tokens, to propagate the indentation box". Indeed, indentation removal (by\@doendpeand friends) is done with\lastbox. – Bruno Le Floch Aug 08 '11 at 19:47