-
Notifications
You must be signed in to change notification settings - Fork 0
/
nethack-example.el
84 lines (69 loc) · 2.86 KB
/
nethack-example.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
;;; nethack-example.el --- Sample configurations for nethack-el
;; Copyright (C) 2002,2003,2005 Shawn Betts and Ryan Yeske
;; Author: Shawn Betts <[email protected]>
;; Version: $Id: nethack-example.el,v 1.6 2005/05/07 20:20:10 sabetts Exp $
;; Keywords: games
;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; This file is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;; Commentary:
;; Here are some hacks that illustrate the power of nethack and emacs
;; combined.
;;; Code:
;;;;;;;;;;;;;;;;;;;
(defun nethack-x-timestamp-message ()
"Add a time-stamp to every message.
Add the following to your ~/.emacs
(add-hook 'nethack-before-print-message-hook
'nethack-x-timestamp-message)"
(insert (format "(%d) " (elt nh-status-attribute-T 0))))
;;;;;;;;;;;;;;;;;;;
(defun nethack-x-gdb ()
"Debug running nethack process with gdb."
(interactive)
(gdb (format "gdb %s/nethack %d"
nh-directory
(process-id nh-proc))))
;;;;;;;;;;;;;;
;; Add the following to your ~/.emacs
;; (add-hook 'nethack-status-attribute-change-functions 'nethack-x-warn-low-hp)
(defun nethack-x-warn-low-hp (attr new old)
"Print a message in `nh-message-buffer' when hitpoints get low."
(if (and (string-equal attr "HP")
(< new old)
(< (/ new (float (car nh-status-attribute-HPmax))) 0.20))
(nhapi-message 'atr-blink "Hitpoints below 20%")))
;;;;;;;;;;;;;;
;; add the following to your ~/.emacs
;; (add-hook 'nethack-add-menu-hook 'nethack-x-highlight-option)
(defvar nethack-x-highlights '((" blessed " . nethack-green-face)
(" holy " . nethack-green-face)
(" cursed " . nethack-red-face)
(" unholy " . nethack-green-face)
(" cursed .* (being worn)" . nethack-orange-face))
"An assoc of regexps and font colors")
(defun nethack-x-highlight-option ()
"Highlight a nethack menu option based on a regexp."
;; Move to the beginning of the option just added
(save-excursion
(let (start
(end (point)))
(forward-line -1)
(forward-line 0)
;; A mini-hack so the option accelerator doesn't get highlighted
(setq start (+ (point) 4))
(mapc (lambda (x)
(if (re-search-forward (car x) nil t)
(put-text-property start end 'face (cdr x))))
nethack-x-highlights))))
(provide 'nethack-example)
;;; nethack-example.el ends here