root/trunk/lisp/eshell/em-banner.el
| Revision 4220, 3.3 kB (checked in by miyoshi, 9 months ago) | |
|---|---|
| |
| Line | |
|---|---|
| 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, or (at your option) |
| 13 | ;; 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; see the file COPYING. If not, write to the |
| 22 | ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 23 | ;; Boston, MA 02110-1301, USA. |
| 24 | |
| 25 | (provide 'em-banner) |
| 26 | |
| 27 | (eval-when-compile (require 'esh-maint)) |
| 28 | |
| 29 | (defgroup eshell-banner nil |
| 30 | "This sample module displays a welcome banner at login. |
| 31 | It exists so that others wishing to create their own Eshell extension |
| 32 | modules may have a simple template to begin with." |
| 33 | :tag "Login banner" |
| 34 | ;; :link '(info-link "(eshell)Login banner") |
| 35 | :group 'eshell-module) |
| 36 | |
| 37 | ;;; Commentary: |
| 38 | |
| 39 | ;; There is nothing to be done or configured in order to use this |
| 40 | ;; module, other than to select it by customizing the variable |
| 41 | ;; `eshell-modules-list'. It will then display a version information |
| 42 | ;; message whenever Eshell is loaded. |
| 43 | ;; |
| 44 | ;; This code is only an example of a how to write a well-formed |
| 45 | ;; extension module for Eshell. The better way to display login text |
| 46 | ;; is to use the `eshell-script' module, and to echo the desired |
| 47 | ;; strings from the user's `eshell-login-script' file. |
| 48 | ;; |
| 49 | ;; There is one configuration variable, which demonstrates how to |
| 50 | ;; properly define a customization variable in an extension module. |
| 51 | ;; In this case, it allows the user to change the string which |
| 52 | ;; displays at login time. |
| 53 | |
| 54 | ;;; User Variables: |
| 55 | |
| 56 | (defcustom eshell-banner-message "Welcome to the Emacs shell\n\n" |
| 57 | "*The banner message to be displayed when Eshell is loaded. |
| 58 | This can be any sexp, and should end with at least two newlines." |
| 59 | :type 'sexp |
| 60 | :group 'eshell-banner) |
| 61 | |
| 62 | (put 'eshell-banner-message 'risky-local-variable t) |
| 63 | |
| 64 | ;;; Code: |
| 65 | |
| 66 | (require 'esh-util) |
| 67 | |
| 68 | (defcustom eshell-banner-load-hook '(eshell-banner-initialize) |
| 69 | "*A list of functions to run when `eshell-banner' is loaded." |
| 70 | :type 'hook |
| 71 | :group 'eshell-banner) |
| 72 | |
| 73 | (defun eshell-banner-initialize () |
| 74 | "Output a welcome banner on initialization." |
| 75 | ;; it's important to use `eshell-interactive-print' rather than |
| 76 | ;; `insert', because `insert' doesn't know how to interact with the |
| 77 | ;; I/O code used by Eshell |
| 78 | (unless eshell-non-interactive-p |
| 79 | (assert eshell-mode) |
| 80 | (assert eshell-banner-message) |
| 81 | (let ((msg (eval eshell-banner-message))) |
| 82 | (assert msg) |
| 83 | (eshell-interactive-print msg)))) |
| 84 | |
| 85 | (eshell-deftest banner banner-displayed |
| 86 | "Startup banner is displayed at point-min" |
| 87 | (assert eshell-banner-message) |
| 88 | (let ((msg (eval eshell-banner-message))) |
| 89 | (assert msg) |
| 90 | (goto-char (point-min)) |
| 91 | (looking-at msg))) |
| 92 | |
| 93 | ;;; arch-tag: e738b4ef-8671-42ae-a757-291779b92491 |
| 94 | ;;; em-banner.el ends here |
| 95 |
Note: See TracBrowser for help on using the browser.
