From b63422050df2e6b1227d2679b39a7ec63428ffa3 Mon Sep 17 00:00:00 2001 From: Jeremy Dormitzer Date: Mon, 29 Apr 2024 16:24:06 -0400 Subject: [PATCH] Add some console roguelikes --- emacs/.emacs.d/config/init-games.el | 41 +++++++++++++++++++++++++++++ emacs/.emacs.d/init.el | 1 + 2 files changed, 42 insertions(+) create mode 100644 emacs/.emacs.d/config/init-games.el diff --git a/emacs/.emacs.d/config/init-games.el b/emacs/.emacs.d/config/init-games.el new file mode 100644 index 0000000..fb861f5 --- /dev/null +++ b/emacs/.emacs.d/config/init-games.el @@ -0,0 +1,41 @@ +;; -*- lexical-binding: t; -*- + +(defun roguelike-evil-insert () + (interactive) + (vterm-reset-cursor-point) + (call-interactively #'evil-insert)) + +(defun roguelike-buffer-setup () + (setq-local cursor-type 'box + blink-cursor-mode nil + evil-insert-state-cursor 'box + evil-normal-state-cursor 'hollow + evil-motion-state-cursor 'hollow + left-fringe-width 0 + right-fringe-width 0) + (evil-local-set-key 'normal (kbd "i") #'roguelike-evil-insert)) + +(defun play-roguelike (exe) + (unless (executable-find exe) + (user-error "%s is not installed" exe)) + (let ((buffer (format "*%s*" exe))) + (when (get-buffer buffer) + (kill-buffer buffer)) + (vterm buffer) + (with-current-buffer buffer + (roguelike-buffer-setup) + (vterm-send-string (format "%s; exit" exe)) + (vterm-send-return)) + (switch-to-buffer buffer))) + +(defun nethack () + (interactive) + (play-roguelike "nethack")) + +(defvar crawl-executable (expand-file-name "~/crawl/crawl-ref/source/crawl")) + +(defun crawl () + (interactive) + (play-roguelike crawl-executable)) + +(provide 'init-games) diff --git a/emacs/.emacs.d/init.el b/emacs/.emacs.d/init.el index 5e5e007..7bc3cf8 100644 --- a/emacs/.emacs.d/init.el +++ b/emacs/.emacs.d/init.el @@ -121,6 +121,7 @@ (require 'init-wallabag) (require 'init-plantuml) (require 'init-mermaid) +(require 'init-games) (require 'handwriting) (when (string-equal system-type "darwin") (require 'init-mac))