em-banner.el 3.07 KB
Newer Older
1
;;; em-banner.el --- sample module that displays a login banner  -*- lexical-binding:t -*-
Gerd Moellmann's avatar
Gerd Moellmann committed
2

3
;; Copyright (C) 1999-2013 Free Software Foundation, Inc.
Gerd Moellmann's avatar
Gerd Moellmann committed
4

Gerd Moellmann's avatar
Gerd Moellmann committed
5 6
;; Author: John Wiegley <johnw@gnu.org>

Gerd Moellmann's avatar
Gerd Moellmann committed
7 8
;; This file is part of GNU Emacs.

9
;; GNU Emacs is free software: you can redistribute it and/or modify
Gerd Moellmann's avatar
Gerd Moellmann committed
10
;; it under the terms of the GNU General Public License as published by
11 12
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
Gerd Moellmann's avatar
Gerd Moellmann committed
13 14 15 16 17 18 19

;; GNU Emacs 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
20
;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
Gerd Moellmann's avatar
Gerd Moellmann committed
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38

;;; Commentary:

;; There is nothing to be done or configured in order to use this
;; module, other than to select it by customizing the variable
;; `eshell-modules-list'.  It will then display a version information
;; message whenever Eshell is loaded.
;;
;; This code is only an example of a how to write a well-formed
;; extension module for Eshell.  The better way to display login text
;; is to use the `eshell-script' module, and to echo the desired
;; strings from the user's `eshell-login-script' file.
;;
;; There is one configuration variable, which demonstrates how to
;; properly define a customization variable in an extension module.
;; In this case, it allows the user to change the string which
;; displays at login time.

39 40 41
;;; Code:

(eval-when-compile
42
  (require 'cl-lib))
43 44

(require 'esh-util)
45 46
(require 'esh-mode)
(require 'eshell)
47

48
;;;###autoload
49 50
(progn
(defgroup eshell-banner nil
51 52 53 54 55
  "This sample module displays a welcome banner at login.
It exists so that others wishing to create their own Eshell extension
modules may have a simple template to begin with."
  :tag "Login banner"
  ;; :link '(info-link "(eshell)Login banner")
56
  :group 'eshell-module))
57

Gerd Moellmann's avatar
Gerd Moellmann committed
58 59 60
;;; User Variables:

(defcustom eshell-banner-message "Welcome to the Emacs shell\n\n"
Glenn Morris's avatar
Glenn Morris committed
61
  "The banner message to be displayed when Eshell is loaded.
Gerd Moellmann's avatar
Gerd Moellmann committed
62 63 64 65 66 67
This can be any sexp, and should end with at least two newlines."
  :type 'sexp
  :group 'eshell-banner)

(put 'eshell-banner-message 'risky-local-variable t)

68
(defcustom eshell-banner-load-hook nil
Glenn Morris's avatar
Glenn Morris committed
69
  "A list of functions to run when `eshell-banner' is loaded."
70
  :version "24.1"                       ; removed eshell-banner-initialize
Gerd Moellmann's avatar
Gerd Moellmann committed
71 72 73 74 75 76 77 78 79
  :type 'hook
  :group 'eshell-banner)

(defun eshell-banner-initialize ()
  "Output a welcome banner on initialization."
  ;; it's important to use `eshell-interactive-print' rather than
  ;; `insert', because `insert' doesn't know how to interact with the
  ;; I/O code used by Eshell
  (unless eshell-non-interactive-p
80 81
    (cl-assert eshell-mode)
    (cl-assert eshell-banner-message)
Gerd Moellmann's avatar
Gerd Moellmann committed
82
    (let ((msg (eval eshell-banner-message)))
83
      (cl-assert msg)
Gerd Moellmann's avatar
Gerd Moellmann committed
84 85
      (eshell-interactive-print msg))))

86 87
(provide 'em-banner)

88 89 90 91
;; Local Variables:
;; generated-autoload-file: "esh-groups.el"
;; End:

Gerd Moellmann's avatar
Gerd Moellmann committed
92
;;; em-banner.el ends here