Commit | Line | Data |
---|---|---|
60370d40 | 1 | ;;; em-banner.el --- sample module that displays a login banner |
affbf647 | 2 | |
faadfb0a | 3 | ;; Copyright (C) 1999, 2000 Free Software Foundation |
affbf647 | 4 | |
7de5b421 GM |
5 | ;; Author: John Wiegley <johnw@gnu.org> |
6 | ||
affbf647 GM |
7 | ;; This file is part of GNU Emacs. |
8 | ||
9 | ;; GNU Emacs is free software; you can redistribute it and/or modify | |
10 | ;; it under the terms of the GNU General Public License as published by | |
11 | ;; the Free Software Foundation; either version 2, or (at your option) | |
12 | ;; any later version. | |
13 | ||
14 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
15 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | ;; GNU General Public License for more details. | |
18 | ||
19 | ;; You should have received a copy of the GNU General Public License | |
20 | ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
21 | ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
22 | ;; Boston, MA 02111-1307, USA. | |
23 | ||
24 | (provide 'em-banner) | |
25 | ||
26 | (eval-when-compile (require 'esh-maint)) | |
27 | ||
28 | (defgroup eshell-banner nil | |
29 | "This sample module displays a welcome banner at login. | |
30 | It exists so that others wishing to create their own Eshell extension | |
31 | modules may have a simple template to begin with." | |
32 | :tag "Login banner" | |
9fa8e391 | 33 | :link '(info-link "(eshell)Login banner") |
affbf647 GM |
34 | :group 'eshell-module) |
35 | ||
36 | ;;; Commentary: | |
37 | ||
38 | ;; There is nothing to be done or configured in order to use this | |
39 | ;; module, other than to select it by customizing the variable | |
40 | ;; `eshell-modules-list'. It will then display a version information | |
41 | ;; message whenever Eshell is loaded. | |
42 | ;; | |
43 | ;; This code is only an example of a how to write a well-formed | |
44 | ;; extension module for Eshell. The better way to display login text | |
45 | ;; is to use the `eshell-script' module, and to echo the desired | |
46 | ;; strings from the user's `eshell-login-script' file. | |
47 | ;; | |
48 | ;; There is one configuration variable, which demonstrates how to | |
49 | ;; properly define a customization variable in an extension module. | |
50 | ;; In this case, it allows the user to change the string which | |
51 | ;; displays at login time. | |
52 | ||
53 | ;;; User Variables: | |
54 | ||
55 | (defcustom eshell-banner-message "Welcome to the Emacs shell\n\n" | |
56 | "*The banner message to be displayed when Eshell is loaded. | |
57 | This can be any sexp, and should end with at least two newlines." | |
58 | :type 'sexp | |
59 | :group 'eshell-banner) | |
60 | ||
61 | (put 'eshell-banner-message 'risky-local-variable t) | |
62 | ||
63 | ;;; Code: | |
64 | ||
65 | (require 'esh-util) | |
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 | ||
ab5796a9 | 92 | ;;; arch-tag: e738b4ef-8671-42ae-a757-291779b92491 |
affbf647 | 93 | ;;; em-banner.el ends here |