The idiom speak of the Devil generally refers to the sudden and presumably unexpected appearance of the object of discussion. If two co-workers are discussing the need for a meeting with their boss and the boss suddenly appears, one might utter this phrase. Other encounters with the subject of a discussion may not be quite as fortunate or welcome.
The basic premise of the idiom can be traced back to ancient folklore concerning the true identity of Satan, or the Devil. Many cultures believed the Devil's true name should never be spoken aloud, since he or one of his imps were bound to overhear and punish the speaker. Therefore, a number of nicknames and allusions to Satan appeared over the centuries, including "Old Scratch," "Prince of Darkness," and "The Evil One." Mentioning Satan's actual name in conversation was considered an invitation for evil spirits.
Some believe the entire idiom is "Speak of the Devil and he shall appear" or "Speak of the Devil and his imps shall appear." An old English proverb suggested that speaking of the Devil would make him appear at your elbow. There is some evidence which indicates the original idiom was closer to "Talk of the Devil and he shall appear," which may be a warning not to hold entire conversations about the Evil One.
Over the years, the spiritual significance of the idiom has largely faded away. The phrase is often uttered flippantly as the subject of the conversation makes his or her unexpected appearance. There is rarely any malice intended, just an acknowledgment the person really was being discussed. Sometimes both parties understand such a surprise appearance isn't out of the realm of possibility. The timing of the conversation just happened to coincide with the appearance of the person being discussed.
Sometimes, the phrase is used as social code to end a gossip session or critical discussion. If two co-workers are discussing a tyrannical boss at a company party, for instance, one might spot the employer in question and quietly utter "speak of the devil" as a signal to end the spleen venting and change the topic.
It is important to use this idiom judiciously, because it does acknowledge the fact that a third party was indeed the subject of a conversation, good or bad. When used properly, the subject of the discussion should not feel unwelcomed to the conversation. The phrase is generally used as a lighthearted acknowledgment of a coincidental appearance, nothing more.