Writing a text editor in prolog