Skip to content

Commit 85e5275

Browse files
eshelyaronyyonchoaclonegeek
authored
Add support for SWI-Prolog (#514)
* Add support for SWI-Prolog * Update docs/page/configuration.md Co-authored-by: Randy Taylor <[email protected]> Co-authored-by: Ivan Yonchovski <[email protected]> Co-authored-by: Randy Taylor <[email protected]>
1 parent 5e33684 commit 85e5275

File tree

5 files changed

+75
-1
lines changed

5 files changed

+75
-1
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ DAP-CLIENTS := dap-chrome.el dap-cpptools.el dap-edge.el \
1212
dap-elixir.el dap-firefox.el dap-gdb-lldb.el \
1313
dap-go.el dap-lldb.el dap-netcore.el dap-node.el \
1414
dap-php.el dap-pwsh.el dap-python.el dap-ruby.el \
15-
dap-codelldb.el dap-erlang.el
15+
dap-codelldb.el dap-erlang.el dap-swi-prolog.el
1616

1717
TEST-FILES := test/windows-bootstrap.el $(shell ls test/dap-*.el)
1818
LOAD-FILE = -l $(test-file)

dap-swi-prolog.el

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
;;; dap-swi-prolog.el --- Debug Adapter Protocol mode for SWI-Prolog -*- lexical-binding: t; -*-
2+
3+
;; Copyright (C) 2021 Eshel Yaron
4+
5+
;; Author: Eshel Yaron <[email protected]>
6+
;; Keywords: languages
7+
8+
;; This program is free software; you can redistribute it and/or modify
9+
;; it under the terms of the GNU General Public License as published by
10+
;; the Free Software Foundation, either version 3 of the License, or
11+
;; (at your option) any later version.
12+
13+
;; This program is distributed in the hope that it will be useful,
14+
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
;; GNU General Public License for more details.
17+
18+
;; You should have received a copy of the GNU General Public License
19+
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
20+
21+
;; URL: https://github.com/yyoncho/dap-mode
22+
;; Package-Requires: ((emacs "25.1") (dash "2.14.1") (lsp-mode "4.0"))
23+
;; Version: 0.2
24+
25+
;;; Commentary:
26+
;; Adapter for https://www.swi-prolog.org
27+
28+
;;; Code:
29+
30+
(require 'dap-mode)
31+
32+
(defcustom dap-swi-prolog-debug-program
33+
`(,(locate-file "swipl_debug_adapter" exec-path))
34+
"The path to the SWI-Prolog debug adapter."
35+
:group 'dap-swi-prolog
36+
:type '(repeat string))
37+
38+
(defun dap-swi-prolog--populate-start-file-args (conf)
39+
"Populate CONF with the required arguments."
40+
(let ((conf (-> conf
41+
(dap--put-if-absent :dap-server-path dap-swi-prolog-debug-program)
42+
(dap--put-if-absent :type "swi-prolog")
43+
(dap--put-if-absent :cwd default-directory)
44+
(dap--put-if-absent :module (buffer-file-name))
45+
(dap--put-if-absent :goal (read-string "Goal: " nil nil "true"))
46+
(dap--put-if-absent :name "SWI-Prolog Debug"))))
47+
conf))
48+
49+
(dap-register-debug-provider "swi-prolog" #'dap-swi-prolog--populate-start-file-args)
50+
51+
(dap-register-debug-template "SWI-Prolog Run Configuration"
52+
(list :type "swi-prolog"
53+
:request "launch"
54+
:name "SWI-Prolog::Run"))
55+
56+
(provide 'dap-swi-prolog)
57+
;;; dap-swi-prolog.el ends here

docs/page/configuration.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,19 @@ Start debugging by selecting "PHP Run Configuration" from the
233233
`dap-debug` menu, issue the debug request in your browser by choosing
234234
the running thread (`dap-switch-thread`) and then `dap-step-in`.
235235

236+
## SWI-Prolog
237+
238+
1. With SWI-Prolog [installed](https://www.swi-prolog.org/Download.html),
239+
run the following command to build and install the debug adapter executable `swipl_debug_adapter`:
240+
```shell
241+
swipl -g "pack_install(debug_adapter)" -t halt
242+
```
243+
2. Add the following line to your Emacs setup:
244+
``` elisp
245+
(require 'dap-swi-prolog)
246+
```
247+
3. Run `dap-debug` in a Prolog buffer and start debugging.
248+
236249
## Native Debug (GDB/LLDB)
237250

238251
Using <https://github.com/WebFreak001/code-debug>

docs/page/gallery.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,7 @@ Gallery
2828
## Erlang
2929

3030
![Erlang via Erlang LS](../screenshots/erlang.png)
31+
32+
## SWI-Prolog
33+
34+
![SWI-Prolog](../screenshots/swi-prolog.png)

screenshots/swi-prolog.png

227 KB
Loading

0 commit comments

Comments
 (0)