WHAT MAY WE SAY NEAR A MES? [Lo'eg la'Rash]
Gemara
"They honored him (Chizkiyahu) in his death" - they learned by his grave;
R. Noson and Rabanan argued about whether they learned for three days or for seven, or according to another version, for 30 days.
Berachos 3b (R. Zerika): In front of a Mes we say only matters of the Mes.
Version #1 (R. Aba bar Kahana): This refers only to words of Torah.
Version #2 (R. Aba bar Kahana): This refers even to words of Torah, and all the more to other things.
18a (Beraisa): One may not walk through a cemetery with Tefilin on his head, or learning from a Sefer Torah in his arm. If he did, he transgressed "Lo'eg la'Rash (one who mocks the poor, i.e. the deceased, who cannot perform Mitzvos) Cheref Osehu".
This applies only within four Amos of the Mes. The four Amos around a Mes pertain to the Mes, it is forbidden to say Shema there.
Rishonim
Rif and Rosh (Berachos 11a and 3:6): In front of a Mes we say only matters of the Mes. Some say that this refers only to words of Torah. Others say that it refers even to words of Torah, and all the more so to other things. Rav Hai Gaon rules like the first version. Divrei Torah may be said in front of the Mes only if they are of the Mes. Other matters are permitted.
Rosh: This is outside four Amos.
R. Yerucham (28:1 Daf 230, cited in Beis Yosef YD 344 DH v'Rabeinu): Rav Hai discusses outside four Amos. Within four Amos even matters of the Mes, even in Torah, are forbidden.
Beis Yosef (DH veha'Rosh): Tefilin and Torah are permitted outside four Amos. I.e. Lo'eg la'Rash does not apply, for it is like a separate place. Here, since they must bury the Mes, discussing other things is like despair from burying him. The Isur applies everywhere in front of the Mes, for the Mes knows whatever is said in front of him. This applies to Divrei Torah. Secular matters do not connote despair from burial, so they are permitted outside four Amos, and perhaps even within four Amos.
Ma'adanei Yom Tov (300): The Rif did not cite Rav Hai regarding four Amos. Tosfos says that Rav Hai Gaon discusses within four Amos. The Rosh should have said (like R. Yerucham did) 'I explain that this is outside four Amos.' It seems that he concluded so because R. Zerika taught (that in front of a Mes we say only matters of the Mes) to add to the Beraisa, which forbids Divrei Torah within four Amos. Kri'as Shema is forbidden only within four Amos, for afterwards he returns to engage in the Mes. One could engage in Divrei Torah without end! It seems that the Rif holds that R. Zerika discusses the case of the Beraisa, i.e. within four Amos, and Divrei Torah of the Mes. The Rosh disagreed, for 'we say only matters of the Mes' connotes that he teaches a stringency. Shiltei ha'Giborim (11a 2) says that the Rosh permits matters of the Mes within four Amos. The Beis Yosef was unsure about secular matters. The Tur and R. Yerucham (who always follows the Rosh) forbid both of these within four Amos.
Gra (YD 344:5): Toras ha'Adam cites the Yerushalmi, which permits Divrei Torah outside four Amos. The text of the Rosh should say 'this is inside four Amos', unlike R. Yerucham.
Tosfos ha'Rosh (Berachos 3b DH Ela): Lo'eg la'Rash applies only within four Amos, but even outside four Amos it is dishonorable to the Mes to speak Divrei Torah not of the Mes, and even more so secular matters.
Nimukei Yosef (Bava Kama 6b DH Yeshiva): The Rosh says that they learned four Amos away from Chizkiyah's grave, to avoid Lo'eg la'Rash. The Ramah says that since it was to honor him, it was permitted (even within four Amos).
Rambam (Hilchos Evel 13:9): In front of a Mes we say only matters of the Mes. One may not engage in Torah in front of it or in a cemetery.
Kesef Mishneh: The Poskim rule like the version that is stringent only about Divrei Torah. The Ramban says that matters of the Mes are laws of eulogy, carrying it to burial, and burial.
Lechem Mishneh: The Rif brought this law along with the law of saying Shema within four Amos of a Mes. It seems that he holds that the Isur is only within four Amos. However, also the Rosh brought it with the law of Shema, but he forbids Divrei Torah even outside of four Amos. Perhaps in the Rosh's text, speaking (Divrei Torah and other matters) was taught near the law of Shema. Hagahos Alfasi holds that the Rosh forbids secular matters within four Amos, but permits matters of the Mes. R. Yerucham holds that the Rosh forbids even matters of the Mes within four Amos.
Poskim
Shulchan Aruch (YD 344:16): In front of a Mes we say only matters of the Mes, e.g. needs of his burial and eulogy. Everything else is forbidden. This refers to Divrei Torah. Secular matters are permitted.
Beis Yosef (DH Kosav): The Mordechai forbids in the entire room, like the first version. If this is because the entire room is like four Amos, I do not know why this depends on the first version.
Shach (11): The Shulchan Aruch permits secular matters even inside four Amos. The Bach forbids. We permit matters of the Mes inside four Amos. The custom is to expound Agados and verses broadly, and ultimately come to the praise of the Mes.
Shulchan Aruch (17): One may say verses and a Drashah for the honor of the Mes within its four Amos or in a cemetery.
Beis Yosef (DH v'Ha): Our custom is to say verses in a cemetery and expound about the Mes. Mahari Avuhav says that we rely on the Ramah.
Taz (5): It is permitted only for honor of the Mes. One who shows off his ability to expound does improperly.
Kaf ha'Chayim (OC 23:1): Learning to elevate the soul of the Mes is permitted, for this is for his honor.
Shulchan Aruch (367:3): One may not learn Torah in a cemetery or within four Amos of a Mes or grave, unless it is for the honor of the Mes.