KATMANDU, Nepal — In a visit that has transfixed this impoverished country, the Indian prime minister, Narendra Modi, told Nepal’s legislature on Sunday that its effort to write the nation’s Constitution was a sacred process. “You are writing a treatise just like the rishis in the past wrote the Vedas and Upanishads,” Mr. Modi said, referring to Hindu sages and the religious scriptures they wrote.