]> code.delx.au - gnu-emacs/blob - lisp/eshell/em-banner.el
Switch to recommended form of GPLv3 permissions notice.
[gnu-emacs] / lisp / eshell / em-banner.el
1 ;;; em-banner.el --- sample module that displays a login banner
2
3 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
5
6 ;; Author: John Wiegley <johnw@gnu.org>
7
8 ;; This file is part of GNU Emacs.
9
10 ;; GNU Emacs 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 3 of the License, or
13 ;; (at your option) any later version.
14
15 ;; GNU Emacs 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.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
22
23 ;;; Commentary:
24
25 ;; There is nothing to be done or configured in order to use this
26 ;; module, other than to select it by customizing the variable
27 ;; `eshell-modules-list'. It will then display a version information
28 ;; message whenever Eshell is loaded.
29 ;;
30 ;; This code is only an example of a how to write a well-formed
31 ;; extension module for Eshell. The better way to display login text
32 ;; is to use the `eshell-script' module, and to echo the desired
33 ;; strings from the user's `eshell-login-script' file.
34 ;;
35 ;; There is one configuration variable, which demonstrates how to
36 ;; properly define a customization variable in an extension module.
37 ;; In this case, it allows the user to change the string which
38 ;; displays at login time.
39
40 ;;; Code:
41
42 (eval-when-compile
43 (require 'cl)
44 (require 'esh-mode)
45 (require 'eshell))
46
47 (require 'esh-util)
48
49 (defgroup eshell-banner nil
50 "This sample module displays a welcome banner at login.
51 It exists so that others wishing to create their own Eshell extension
52 modules may have a simple template to begin with."
53 :tag "Login banner"
54 ;; :link '(info-link "(eshell)Login banner")
55 :group 'eshell-module)
56
57 ;;; User Variables:
58
59 (defcustom eshell-banner-message "Welcome to the Emacs shell\n\n"
60 "*The banner message to be displayed when Eshell is loaded.
61 This can be any sexp, and should end with at least two newlines."
62 :type 'sexp
63 :group 'eshell-banner)
64
65 (put 'eshell-banner-message 'risky-local-variable t)
66
67 (defcustom eshell-banner-load-hook '(eshell-banner-initialize)
68 "*A list of functions to run when `eshell-banner' is loaded."
69 :type 'hook
70 :group 'eshell-banner)
71
72 (defun eshell-banner-initialize ()
73 "Output a welcome banner on initialization."
74 ;; it's important to use `eshell-interactive-print' rather than
75 ;; `insert', because `insert' doesn't know how to interact with the
76 ;; I/O code used by Eshell
77 (unless eshell-non-interactive-p
78 (assert eshell-mode)
79 (assert eshell-banner-message)
80 (let ((msg (eval eshell-banner-message)))
81 (assert msg)
82 (eshell-interactive-print msg))))
83
84 (eshell-deftest banner banner-displayed
85 "Startup banner is displayed at point-min"
86 (assert eshell-banner-message)
87 (let ((msg (eval eshell-banner-message)))
88 (assert msg)
89 (goto-char (point-min))
90 (looking-at msg)))
91
92 (provide 'em-banner)
93
94 ;; arch-tag: e738b4ef-8671-42ae-a757-291779b92491
95 ;;; em-banner.el ends here