1 ;;; zenirc-history.el --- keep a history of commands in ZenIRC
3 ;; Copyright (C) 1996, 1998 Per Persson
5 ;; Author: Per Persson <pp@sno.pp.se>
6 ;; Maintainer: pp@sno.pp.se
7 ;; Keywords: zenirc, history
10 ;; This program is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; This program is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with this program; if not, you can either send email to this
22 ;; program's maintainer or write to: The Free Software Foundation,
23 ;; Inc.; 675 Massachusetts Avenue; Cambridge, MA 02139, USA.
33 ;; default is "/server" because that's probably the first thing you want to do
34 (defvar zenirc-history-list '("/server")
35 "A list of commands run by the user.")
36 (make-variable-buffer-local 'zenirc-history-list)
38 ;; hairy variables to keep track of commands
39 (defvar zenirc-history-list-backward nil)
40 (make-variable-buffer-local 'zenirc-history-list-backward)
41 (defvar zenirc-history-list-forward nil)
42 (make-variable-buffer-local 'zenirc-history-list-forward)
43 (defvar zenirc-history-list-current nil)
44 (make-variable-buffer-local 'zenirc-history-list-current)
46 ;; reset hairy variables when a new command is sent to the server
47 (defun zenirc-history-command (foo bar command)
48 (setq zenirc-history-list-backward nil
49 zenirc-history-list-forward nil
50 zenirc-history-list-current nil
51 zenirc-history-list (cons command zenirc-history-list)))
53 ;; step up one entry in the history list
54 (defun zenirc-history-backward ()
56 (if (not zenirc-history-list-backward)
57 ; initialize variables if their reset
58 (setq zenirc-history-list-backward zenirc-history-list
59 zenirc-history-list-current
60 (buffer-substring zenirc-process-mark (point-max))
61 zenirc-history-list-forward zenirc-history-list-forward))
62 ; remove contents of line
64 (if (not (= (point) (point-max)))
65 (delete-backward-char (- (point) (point-max))))
66 ; insert previous command
67 (insert (car zenirc-history-list-backward))
68 ; update hairy variabels
69 (setq zenirc-history-list-forward (cons
70 zenirc-history-list-current
71 zenirc-history-list-forward)
72 zenirc-history-list-current (car zenirc-history-list-backward)
73 zenirc-history-list-backward (cdr zenirc-history-list-backward)))
75 ;; step down one entry in the history list
76 (defun zenirc-history-forward ()
78 (if (not zenirc-history-list-forward)
80 (setq zenirc-history-list-backward nil
81 zenirc-history-list-forward nil)
82 ; remove contents of line
84 (if (not (= (point) (point-max)))
85 (delete-backward-char (- (point) (point-max))))
87 (insert (car zenirc-history-list-forward))
88 ; update hairy variables
89 (setq zenirc-history-list-backward (cons
90 zenirc-history-list-current
91 zenirc-history-list-backward)
92 zenirc-history-list-current (car zenirc-history-list-forward)
93 zenirc-history-list-forward (cdr zenirc-history-list-forward))))
95 (provide 'zenirc-history)
97 (zenirc-add-hook 'zenirc-send-line-hook 'zenirc-history-command)
99 (define-key zenirc-mode-map "\M-p" 'zenirc-history-backward)
100 (define-key zenirc-mode-map "\M-n" 'zenirc-history-forward)
102 ;; zenirc-history.el ends here