em-banner.el 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. ;;; em-banner.el --- sample module that displays a login banner
  2. ;; Copyright (C) 1999-2012 Free Software Foundation, Inc.
  3. ;; Author: John Wiegley <johnw@gnu.org>
  4. ;; This file is part of GNU Emacs.
  5. ;; GNU Emacs is free software: you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation, either version 3 of the License, or
  8. ;; (at your option) any later version.
  9. ;; GNU Emacs is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  15. ;;; Commentary:
  16. ;; There is nothing to be done or configured in order to use this
  17. ;; module, other than to select it by customizing the variable
  18. ;; `eshell-modules-list'. It will then display a version information
  19. ;; message whenever Eshell is loaded.
  20. ;;
  21. ;; This code is only an example of a how to write a well-formed
  22. ;; extension module for Eshell. The better way to display login text
  23. ;; is to use the `eshell-script' module, and to echo the desired
  24. ;; strings from the user's `eshell-login-script' file.
  25. ;;
  26. ;; There is one configuration variable, which demonstrates how to
  27. ;; properly define a customization variable in an extension module.
  28. ;; In this case, it allows the user to change the string which
  29. ;; displays at login time.
  30. ;;; Code:
  31. (eval-when-compile
  32. (require 'cl)
  33. (require 'esh-mode)
  34. (require 'eshell))
  35. (require 'esh-util)
  36. ;;;###autoload
  37. (eshell-defgroup eshell-banner nil
  38. "This sample module displays a welcome banner at login.
  39. It exists so that others wishing to create their own Eshell extension
  40. modules may have a simple template to begin with."
  41. :tag "Login banner"
  42. ;; :link '(info-link "(eshell)Login banner")
  43. :group 'eshell-module)
  44. ;;; User Variables:
  45. (defcustom eshell-banner-message "Welcome to the Emacs shell\n\n"
  46. "The banner message to be displayed when Eshell is loaded.
  47. This can be any sexp, and should end with at least two newlines."
  48. :type 'sexp
  49. :group 'eshell-banner)
  50. (put 'eshell-banner-message 'risky-local-variable t)
  51. (defcustom eshell-banner-load-hook nil
  52. "A list of functions to run when `eshell-banner' is loaded."
  53. :version "24.1" ; removed eshell-banner-initialize
  54. :type 'hook
  55. :group 'eshell-banner)
  56. (defun eshell-banner-initialize ()
  57. "Output a welcome banner on initialization."
  58. ;; it's important to use `eshell-interactive-print' rather than
  59. ;; `insert', because `insert' doesn't know how to interact with the
  60. ;; I/O code used by Eshell
  61. (unless eshell-non-interactive-p
  62. (assert eshell-mode)
  63. (assert eshell-banner-message)
  64. (let ((msg (eval eshell-banner-message)))
  65. (assert msg)
  66. (eshell-interactive-print msg))))
  67. (provide 'em-banner)
  68. ;; Local Variables:
  69. ;; generated-autoload-file: "esh-groups.el"
  70. ;; End:
  71. ;;; em-banner.el ends here