This is an extension of the question posed in Automatically Display the First Word of Every Quotation in Small Caps
Consider the code
\documentclass[14pt]{memoir}
\usepackage[T1]{fontenc}
\usepackage[sfdefault]{cabin}
%\usepackage{showframe}
\newcommand{\longemdash}{\makebox[1em][s]{---\hss---}}
\makeatletter
\newcommand{\fancyquote}[2]{%
\fancyquote@#1@nil{#2}%
}
\def\fancyquote@#1 #2@nil#3{%
\par\noindent\textsc{#1} #2\\hspace{\fill}\longemdash{\itshape\bfseries#3}%
}
\makeatother
\begin{document}
\thispagestyle{empty}
\fancyquote{There is nothing so absurd that some philosopher has not already said it.}{Cicero}
\vspace*{20pt}
\fancyquote{Faithfulness and truth are the most sacred excellences and endowments of the human mind.}{Cicero}
\vspace*{20pt}
\fancyquote{Any man can make mistakes, but only an idiot persists in his error.}{Cicero}
\end{document}
which produces
QUESTION: Is it possible, when there is room (such as quotes 2 and 3 in the MWE), to automatically right-justify the emdash and name on the last line of the quote; else, skip a line and right justify the emdash and name (as is the case for quote 1)?
I am trying to automatically avoid displaying a large vertical space, such as is seen in quote 2.
Thank you.

\qedfor a proof byamsthm:\unskip\penalty9999 \hbox{}\nobreak\hfill\quad \hbox{--- <name>}– barbara beeton Apr 26 '23 at 03:06