Skip to the content.

Setting up Emacs for Prolog

06 Oct 2024 - João Porto

How to set up Emacs for Prolog

Set up

First of all, I installed the GNU Prolog via sudo apt install gprolog. Prolog per se worked well, but I was struggling to make .pl files be recognized by Emacs, because it was considering .pl as Perl files, not Prolog files.

Then I thought that I could install a major mode package for Prolog, just like I did for Go, Elixir and PHP (via, e.g., M-x package-install RET go-mode). But apparently there was no ELPA package prolog-mode or something like that available, at least no one that I would find throught the M-x list-packages. The list just shown the packages ediprolog and sweeprolog. Both of these two enable query Prolog directly from Emacs's buffer, but the last one specifically for the SWI-Prolog.

Then I thought "Well, maybe installing the sweeprolog I can get Prolog syntax hightlight as a side effect.". Therefore, I asked to Gemini what is the difference between GNU Prolog and SWI-Prolog. In short, both are implementations of Prolog, being the first one faster and the second one popular.

Thereafter, I uninstalled GNU Prolog, because I was going to install SWI-Prolog, but first I read the description of ediprolog, and I found this video that demonstrate its features. Watching the video I noticed that a Prolog mode was in use on the presenter's Emacs and I thought "Hmm, there is a Prolog mode, but it is not listed in the packages list.".

Then I asked to Gemini what is the name for Prolog's major mode in Emacs, and its answer was prolog-mode. Also, I asked how to check the available modes in Emacs and Gemini suggested M-x list-modes, a command that, at least in my Emacs, does not exists. I did the same question to ChatGPT, and it answered M-x apropos-command RET -mode, that indeed lists the available mode, including that one I was seeking for.

I read the description provided for prolog-mode, trying to find the way to set the mode, but the description was not helpful. Finally, I asked to ChatGPT how to change the current buffer to a specific mode, and it suggested simply M-x prolog-mode, what makes complete sense. If I had noticed before that M-x apropos-command is used exactly to provide information about commands, I maybe would understand early that prolog-mode was listed because it is a command per se, and then, can be executed via M-x.

Anyway, the command worked and then I successfully changed to Prolog mode, with the correct syntax hightlight. Also, for Emacs recognize .pl as a file to be opened with Prolog mode, ChatGPT suggested to put (add-to-list 'auto-mode-alist '("\\.pl\\'" . prolog-mode)) into ~/.emacs.

About this last point, a interesting thing is that I asked to Gemini how to do that a few days ago, and it suggested to put (setq auto-mode-alist (append '(("\\.pl$", . prolog-mode)) auto-mode-alist)) into ~/.emacs, which did not work, otherwise, I would to skip all these process.

But the process was not useless, because I found ediprolog and sweeprolog, that I may use, since Org-mode seems not offer support for Prolog.

References

“GNU ELPA - Ediprologes.” Gnu.org, 2024, elpa.gnu.org/packages/ediprolog.html. Accessed 6 Oct. 2024.

“GNU ELPA Packages.” Gnu.org, 2020, elpa.gnu.org/packages/. Accessed 6 Oct. 2024.

Google. “Gemini.” Gemini.google.com, 2024, gemini.google.com/app. Accessed 6 Oct. 2024.

“NonGNU ELPA - Sweeprolog.” Nongnu.org, 2024, elpa.nongnu.org/nongnu/sweeprolog.html. Accessed 6 Oct. 2024.

“NonGNU ELPA Packages.” Nongnu.org, 2015, elpa.nongnu.org/nongnu/. Accessed 6 Oct. 2024.

OpenAI. “ChatGPT.” Openai.com, 2024, openai.com/chatgpt/. Accessed 6 Oct. 2024.

Schulte, Eric. “Babel: Languages.” Orgmode.org, 2014, orgmode.org/worg/org-contrib/babel/languages/index.html. Accessed 6 Oct. 2024.

The Power of Prolog. “Ediprolog: Emacs Does Interactive Prolog.” YouTube, 14 July 2019, youtube.com/watch?v=jMg8sY2R930. Accessed 6 Oct. 2024.