[Due to objections of Bruno Le Floch I saw the need for a major edit of my answer:]
You can use two scratch token registers. One for \edefing and another one for resetting both itself and the one that was used for \edefing:
\documentclass{article}
\makeatletter
%
% \Addtohook{<control sequence>}{<tokens to prepend>}{<tokens to append>}
% =======================================================================
%
% <control sequence> is a control sequence that does not take any arguments.
% \Addtohook _within_the_current_scope_ prepends to the definition of that
% control sequence the <tokens to prepend> and appends the definition of
% that control sequence the <tokens to append>.
\newcommand\Addtohook[3]{%
\@temptokena\expandafter{%
\expandafter\@temptokena
\expandafter{%
\the\expandafter\@temptokena
\expandafter}%
\expandafter\toks@
\expandafter{%
\the\toks@}%
}%
\toks@{#2}%
\toks@\expandafter{\the\expandafter\toks@#1#3}%
\edef#1{\the\toks@}%
\the\@temptokena
}%
%\makeatother
\newcommand\myhook{\def\Middlepiece##1{Argument Middlepiece:##1}}%
\begin{document}
\ttfamily
\@temptokena{tEST tEST}%
\toks@{Test Test}%
\string\the\string\@temptokena=\the\@temptokena
\string\the\string\toks@=\the\toks@
\string\myhook=\meaning\myhook
\begingroup
\Addtohook{\myhook}%
{\def\Frontpiece#1{Argument Frontpiece:#1}}%
{\def\Tailpiece#1{Argument Tailpiece:#1}}%
\string\myhook=\meaning\myhook
\string\the\string\@temptokena=\the\@temptokena
\string\the\string\toks@=\the\toks@
\endgroup
\string\myhook=\meaning\myhook
\end{document}
My favorite way (proposed by Bruno Le Floch) is using \edef and only one scratch token register.
\documentclass{article}
\makeatletter
%
% Paraphernalia:
% ==============
\newcommand\UD@exchange[2]{#2#1}%
%
% \Addtohook{<control sequence>}{<tokens to prepend>}{<tokens to append>}
% =======================================================================
%
% <control sequence> is a control sequence that does not take any arguments.
% \Addtohook _within_the_current_scope_ prepends to the definition of that
% control sequence the <tokens to prepend> and appends the definition of
% that control sequence the <tokens to append>.
\newcommand\Addtohook[3]{%
\expandafter\UD@exchange
\expandafter{%
\expandafter\toks@
\expandafter{%
\the\toks@}}{%
\toks@\expandafter\expandafter
\expandafter{%
\expandafter\UD@exchange
\expandafter{#1#3}{#2}}\edef#1{\the\toks@}}%
}%
%\makeatother
\newcommand\myhook{\def\Middlepiece##1{Argument Middlepiece:##1}}%
\begin{document}
\ttfamily
\@temptokena{tEST tEST}%
\toks@{Test Test}%
\string\the\string\@temptokena=\the\@temptokena
\string\the\string\toks@=\the\toks@
\string\myhook=\meaning\myhook
\begingroup
\Addtohook{\myhook}%
{\def\Frontpiece#1{Argument Frontpiece:#1}}%
{\def\Tailpiece#1{Argument Tailpiece:#1}}%
\string\myhook=\meaning\myhook
\string\the\string\@temptokena=\the\@temptokena
\string\the\string\toks@=\the\toks@
\endgroup
\string\myhook=\meaning\myhook
\end{document}
The methods shown so far don't preserve the \long-status of macros defined in terms of \long.
This can be implemented by checking whether the \meaning contains the phrase \long in the right place:
\documentclass{article}
\makeatletter
%
% Paraphernalia:
% ==============
\newcommand\UD@exchange[2]{#2#1}%
\newcommand\UD@firstoftwo[2]{#1}%
\newcommand\UD@secondoftwo[2]{#2}%
%
%------------------------------------------------------------------------------
% Check whether argument is empty:
%..............................................................................
% \UD@CheckWhetherNull{<Argument which is to be checked>}%
% {<Tokens to be delivered in case that argument which is
% to be checked is empty>}%
% {<Tokens to be delivered in case that argument which is
% to be checked is not empty>}%
%
% The gist of this macro comes from Robert R. Schneck's \ifempty-macro:
% <https://groups.google.com/forum/#!original/comp.text.tex/kuOEIQIrElc/lUg37FmhA74J>
%
% (\romannumeral expansion was introduced by me in order to overcome the
% concerns and worries about improperly balanced \if..\else..\fi constructs.)
\newcommand\UD@CheckWhetherNull[1]{%
\romannumeral0\expandafter\UD@secondoftwo\string{\expandafter
\UD@secondoftwo\expandafter{\expandafter{\string#1}\expandafter
\UD@secondoftwo\string}\expandafter\UD@firstoftwo\expandafter{\expandafter
\UD@secondoftwo\string}\expandafter\expandafter\UD@firstoftwo{ }{}%
\UD@secondoftwo}{\expandafter\expandafter\UD@firstoftwo{ }{}\UD@firstoftwo}%
}%
%-----------------------------------------------------------------------------
% Check whether argument's first token is a catcode-1-character:
%.............................................................................
% \UD@CheckWhetherBrace{<Argument which is to be checked>}%
% {<Tokens to be delivered in case that argument which is
% to be checked has leading catcode-1-token>}%
% {<Tokens to be delivered in case that argument which is
% to be checked has no leading catcode-1-token>}%
\newcommand\UD@CheckWhetherBrace[1]{%
\romannumeral0\expandafter\UD@secondoftwo\expandafter{\expandafter{%
\string#1.}\expandafter\UD@firstoftwo\expandafter{\expandafter
\UD@secondoftwo\string}\expandafter\expandafter\UD@firstoftwo{ }{}%
\UD@firstoftwo}{\expandafter\expandafter\UD@firstoftwo{ }{}\UD@secondoftwo}%
}%
%-----------------------------------------------------------------------------
% Check whether argument has a first token whose meaning starts with the
% phrase \long macro:-> :
%.............................................................................
% \UD@CheckWhetherLeadingLong{<argument which is to be checked>}%
% {<Tokens to be delivered in case <argument which
% is to be checked> has 1st token whose meaning
% has leading phrase \long macro:-> >}%
% {<Tokens to be delivered in case <argument which
% is to be checked> has no 1st token whose
% meaning has leading phrase \long macro:-> >}%
\begingroup
\def\UDtempa#1{%
\endgroup
\newcommand\UD@CheckWhetherLeadingLong[1]{%
\romannumeral0\UD@CheckWhetherBrace{##1}%
{\expandafter\expandafter\UD@firstoftwo{ }{}\UD@secondoftwo}%
{\expandafter\expandafter\expandafter\UD@secondoftwo
\expandafter\string\expandafter{%
\expandafter\UD@CheckWhetherLeadingLongB\meaning##1.#1}{}}%
}%
\newcommand\UD@CheckWhetherLeadingLongB{}%
\long\def\UD@CheckWhetherLeadingLongB##1#1{%
\UD@CheckWhetherNull{##1}%
{\UD@exchange{\UD@firstoftwo}}{\UD@exchange{\UD@secondoftwo}}%
{\UD@exchange{ }{\expandafter\expandafter\expandafter\expandafter
\expandafter\expandafter\expandafter}\expandafter\expandafter
\expandafter}\expandafter\UD@secondoftwo\expandafter{\string}%
}%
}%
\begingroup
\edef\UDtempa{%
\string\long\UD@firstoftwo{ }{}%
\string m\string a\string c\string r\string o\string:\string-\string>%
}%
\expandafter\endgroup\expandafter\UDtempa\expandafter{\UDtempa}%
%-----------------------------------------------------------------------------
% Within the current scope prepend and append some tokens to the definition
% of a control sequence that does not take arguments:
%.............................................................................
% \Addtohook{<control sequence>}{<tokens to prepend>}{<tokens to append>}
\newcommand\Addtohook[3]{%
\expandafter\UD@exchange\expandafter{%
\expandafter\toks@\expandafter{\the\toks@}%
}{%
\toks@\expandafter\expandafter\expandafter{%
\expandafter\UD@exchange\expandafter{#1#3}{#2}}%
\UD@CheckWhetherLeadingLong{#1}{\long}{}\edef#1{\the\toks@}%
}%
}%
%\makeatother
\newcommand\myhook{\def\Middlepiece##1{Argument Middlepiece:##1}}%
\newcommand*\myhookB{\def\Middlepiece##1{Argument Middlepiece:##1}}%
\begin{document}
\ttfamily
\@temptokena{tEST tEST}%
\toks@{Test Test}%
Appending to \string\long-macro:
\string\the\string\@temptokena=\the\@temptokena
\string\the\string\toks@=\the\toks@
\string\myhook=\meaning\myhook
\begingroup
\Addtohook{\myhook}%
{\def\Frontpiece#1{Argument Frontpiece:#1}}%
{\def\Tailpiece#1{Argument Tailpiece:#1}}%
\string\myhook=\meaning\myhook
\string\the\string\@temptokena=\the\@temptokena
\string\the\string\toks@=\the\toks@
\endgroup
\string\myhook=\meaning\myhook
\hrulefill
Appending to non-\string\long-macro:
\string\the\string\@temptokena=\the\@temptokena
\string\the\string\toks@=\the\toks@
\string\myhookB=\meaning\myhookB
\begingroup
\Addtohook{\myhookB}%
{\def\Frontpiece#1{Argument Frontpiece:#1}}%
{\def\Tailpiece#1{Argument Tailpiece:#1}}%
\string\myhookB=\meaning\myhookB
\string\the\string\@temptokena=\the\@temptokena
\string\the\string\toks@=\the\toks@
\endgroup
\string\myhookB=\meaning\myhookB
\end{document}
Question: Is there a method for appending to the definition of a macro that does not take arguments in case in the meantime some tokens of the definition of that macro have been redefined in terms of \outer? (I did not find an answer by now.)
I.e.
\newcommand\myhook{\def\Middlepiece##1{Argument Middlepiece:##1}}%
\outer\def\Middlepiece{This is outer now!}%
...
\Addtohook{\myhook}%
{\def\Frontpiece#1{Argument Frontpiece:#1}}%
{\def\Tailpiece#1{Argument Tailpiece:#1}}%
\pretoand\apptofrometoolboxthat obey scoping rules. – egreg Dec 05 '16 at 16:46