We will discuss here some issues that are a problem in theory, but not in practice. Everybody would use intuitively the correct forms even without really knowing why. This is actually a little bit strange, because if we think about it, it is complicated.
We haven't talk yet about demonstrative adjectives and demonstrative pronouns. We will discuss what they are and how the fuse with the preposition de, em, a. First of all we should see the difference between a demonstrative adjective and demonstrative pronoun.
1) demonstrative adjective: This land is your land, this land is my land, from California, to the New York Island.
2) demonstrative pronoun: That's not worth doing it.
We use 1) if in a conversation there are several option and we have the possibility to point to a specific option. Woody Guthrie and Pete Seeger point to a specific land. Sometimes the demonstrative pronoun can be substituted by a definitive article, see 4.articles. However by using the definitive article in this context the meaning would change. If we say the land from California to the New York Island is your land and my land, we would exclude that there is a land of dreams, that should belong to everybody. The song is about this land and not about the land that belongs to somebody. The demonstrative adjective points to a specific element of a group, but the type of element is mentioned. 2) is different. 2) is only comprehensible, if we know to what "that" refers to.
Demonstrative adjectives and demonstrative pronouns are normally defined by one function, the function to point to something. This use is obviously only possible if in some way we can point the thing / person we refere to. If we are in a bakery, we can say "I want this bread" and point with the finger to the bread we mean. That works more or less. (I want this one. This one? No, the one on the right. This? No, the one below. This? Yes, this one.) It can be questioned whether it is a good idea to name something after one function of many functions that is not even the most important one.
This author would say that much more important than pointing to something / someone is to refere to something.
A: I lost my wallet.
B: That's bad.
This use is completely different than the previous one. In this case we just refer to something. There is no other element, it is not like "This man is rich and the other one is poor". The demonstrative pronoun can refer to whole idea, in this case to the fact that he has lost his wallet.
In grammar books of portguese it is often mentioned that depending on the position of the referred object different demonstrative adjectives / demonstrative pronouns are used. If the object is near the speaker, it is este / esta / estes / estas, if it is nearer to the person spoken to it is esse / essa / esses / essas and if it is far away from both it is aquel / aquela / aqueles / aquelas.
neutral (always pronouns)
near to the speaker
that / this
near the person talked to
that / this
big distance to both of them
was / this
If this really fits with the actual use can be questioned, but in any case it can only be true if the demonstrative adjective / demonstrative pronoun refers to a relationship in space. If it is refers to relationship in time, this definition is meaningless, because yesterday or tomorrow is as far from the speaker as from the the person he talks to. At most we can say that esse / aquele refer to more remote times.
near to the moment of speech:
This afternoon I will go the supermarket.
far away from the moment of speech:
That night I slept bad, I had nightmares.
very far away from the momentn of speech:
In those times the children of rich families went to France for their studies.
If the use of the different demonstrative adjectives / demonstrative pronouns depends on the position in space of the referrenced object can be questioned. However in exteme cases it may be true. (If someone want to verify whether this description is true or not can put the words este, essse and aquele in a search engine. He will find thousand of examples where the use, even the use of sensitive speakers, is somehow arbirtrary.)
However in the examples below it is obvious whether the objet is nearer to the speaker or to the person he talks to. In cases like that it is probable that the distinctions mentioned before are made.
este, esta, estes, estas nearerr to the speaker
The watch I am wearing belonged to my grandfather.
In the moment of speaking he has the watch on his wrist. In this case the watch is obviously nearer to the speakter than to the person he speaks with.
esse, essa, essses, essas nearer to the person he talks to
Can you give me the magazine next to you.
In this case the magazine is nearer to the person he talks to than to the speaker.
aquele, aquela, aqueles, aquelas far away from both
The houses, that has been destroyed, need to be rebuild.
If those houses doesn't exist any more, they are very far away from both, from the speaker and from the person he speaks with.
The demonstrative adjective as well as the demonstrative pronoun fuses with de and em. This is true for the demonstrative pronoun, the demonstrative adjective and the neutral form isto, isso, aquilo, who are alway pronouns. Aquele fueses as well with a.
Perhaps it is useful to see, that both the personal pronoun neutral it / o and the neutral demontrative pronoun that - this / isto - isso - aquilo can refer to an idea.
This is strange.
It is strange.
Both, this and it, can refere to an idea. (The fact that penguin with their short legs can walk such long distances, is strange. <=> It is strange. / That is strange. ) However only it can refer to a concrete object.
A: Do you see this painting?
B: Yes, it is beautiful.
Perhaps B responds with "Yes, that is beautiful", but this sentence is ambiguous. However if we refer to a specific element of several similar elements, only the demonstrative pronoun is possible.
A: Did you already take a decision which trouser you like best?
B: Yes, this one.
However there is a little difference. If the subject of the sentence is a pronoun, there is no need to mention it in Portguese. Therefore one problem is resolved automatically. Some words, to snow, to rain, to hail doesn't have a subject. Nobody is snowing, raining or hailing. In this case we have to introduce in English an artificial subject, because an English a sentence requires a subject, it is snowing, raining, hailing. In portuguese we don't have this problem, because we don't need to mention the subject. (And obviously that is not possible in English: ~ That doesn't snow.)
The inexistent subject must not be mentioned in Portuguese.
It is hot.
If the direct object is masculine and if it is referred to by a pronoun, it would be o / os, if it is feminine by a / as: "Não o / os / a / as vejo", "I don't see him / her / it / them".
However an idea, a context of meaning, is not masculine nor feminine, it is neutral and there is no neutral personal pronoun in portugues and therefore an idea can only be referred to with a demonstrative pronoun.
referring an idea, a context of meaning
I am sick of it.
Estou farto disso.
If there is a subject, but this subject is completely unknown, the indefinite pronouns something / someone is used in English, "Someone knocks at the door". This is possible as well in Portuguese, "Alguém bate à porta". However it is possible as well to use the third person plural in this context.
The subject exists, but is unknown
Someone is knocking at the door.
Tocam à porta.
It is knocking at the door.*
Isto toca à porta.
* Actually possible in a very unrealistic scenario. If we see a monster through the window and this monster starts knocking at the door, than we can say "It is knocking at the door".
What has been already said concerning the subject is more or less true as well for the direct object. The sentence "Não o entendo" is ambiguous. The personal pronoun can refer to someone, "I don't understand him" or to an idea, "I don't understand it". If we want to avoid this ambiguity we must use isto, iso, aquilo. Isto, iso, aquilo can't refere to a concrete person or a concrete noun, because a person or a noun are always either feminine or masculine. Only ideas or context meanings are neutral and therefore isto, iso, aquilo referes always to an idea, because only ideas are neutral.
o / isso pronoun
Não* o entendo.
I don't unserstand him / it.
Não entendo * isso.
I don't understand that.
The pronoun o is ambiguous and a neutral personal pronoun doesn't exist in Portuguese, therefore the only way to avoid ambiguity is the neutral demonstrative pronoun. (In case that someone wants to know it: In Spanish there is a neutral relative pronoun, lo: No lo entiendo <=> I don't understand it / No le entiendo <=> I don't understand him.)
In the case that the singularity is the main assertion, only the demonstrative pronoun is possible.
o / este as a pronoun 3rd person singular masculine direct object. Singularity is the main assertion.
Queres este ou o outro?
Do you want this one or that one?
I want this one.
wrong: I want it.
In this case a choice is to be made. Someone has to decide FOR something and AGAINST something else.
In the following scenario a choice has been made in the question, but the answer refers to a well identified element.
o / este third person singular masculine direct object. The singularity is irrelevant in the answer.
Ves este homem?
Du you see this man?
Sim, o vejo.
Yes, I see him.
wrong: Sim, este vejo. *
wrong: I see this (man). *
* Actually there are several problems. The demonstrative pronoun in Portuguese has a feminine and a masculine form and can therefore refer as well to human beings. The demonstrative pronoun in english only exists in a neutral form and can't therefore used in relationship to human beings.
If we need a combination between preposition and personal pronoun, in other words, if the pronoun refers to a human being, we use the stressed pronouns, see 6.1.1. If we need a combination a preposition and a reference to a thing or an idea we can't use o. The personal pronoun o can refere to a thing or an idea, but not together with a preposition. In this case we have to use the demonstrative pronoun.
I don't like that.
That's why you don't speak with me?
The plans for that have been worked out carefully.
Never give up the things that make you love.
We are working on it.
I think about this and that.
Examples with isto, isso, aquilo. In some of the following examples there are indications of spatial or temporal proximity. In most cases however the proximity is irrelevant concerning the use of isto, isso or aquilo.
This is for you.
What is that on the right beside you?
This helps us to understand many things..
You will do that, otherwise you will suffer the consequences.
The father is seriously ill and that worries the daughter.