Last active
December 16, 2023 14:04
-
-
Save ceving/5be7762abb9a3ebebc04d31fbb1ed477 to your computer and use it in GitHub Desktop.
Some keybindings for Prolog in Emacs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun inferior-prolog-proc () | |
(get-buffer-process (prolog-inferior-buffer))) | |
(defun inferior-prolog-get-clause () | |
(buffer-substring-no-properties (prolog-clause-start) | |
(prolog-clause-end))) | |
(defun inferior-prolog-send-read () | |
"Send a char read from minibufer." | |
(interactive) | |
(let* ((char (read-char-exclusive "Char to send: ")) | |
(expr (char-to-string char))) | |
(comint-send-string (inferior-prolog-proc) expr))) | |
(defun inferior-prolog-send-clause () | |
"Send current rule." | |
(interactive) | |
(let* ((clause (inferior-prolog-get-clause)) | |
(expr (concat clause "\n"))) | |
(comint-send-string (inferior-prolog-proc) expr))) | |
(defun inferior-prolog-send-assertz-clause () | |
"Send current rule as an assertion." | |
(interactive) | |
(let* ((clause (buffer-substring-no-properties (prolog-clause-start) | |
(prolog-clause-end))) | |
(expr (replace-regexp-in-string "^\\(.*\\)\\.$" "assertz(\\1).\n" | |
clause))) | |
(comint-send-string (inferior-prolog-proc) expr))) | |
(add-hook 'prolog-mode-hook | |
(lambda () | |
(local-set-key (kbd "C-c C-q") | |
#'inferior-prolog-send-read) | |
(local-set-key (kbd "C-c C-e") | |
#'inferior-prolog-send-clause) | |
(local-set-key (kbd "C-c C-a") | |
#'inferior-prolog-send-assertz-clause))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment