Mercurial > emacs
annotate lisp/eshell/em-prompt.el @ 30220:e4628d420030
(Info-mode-menu): Fix use of :help, :enable.
author | Dave Love <fx@gnu.org> |
---|---|
date | Fri, 14 Jul 2000 14:38:55 +0000 |
parents | 34b1ab9d583d |
children | 8e57189d61b4 |
rev | line source |
---|---|
29876 | 1 ;;; em-prompt --- command prompts |
2 | |
29934
34b1ab9d583d
Change spelling of the Free Software Foundation.
Gerd Moellmann <gerd@gnu.org>
parents:
29876
diff
changeset
|
3 ;; Copyright (C) 1999, 2000 Free Software Foundation |
29876 | 4 |
5 ;; This file is part of GNU Emacs. | |
6 | |
7 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
8 ;; it under the terms of the GNU General Public License as published by | |
9 ;; the Free Software Foundation; either version 2, or (at your option) | |
10 ;; any later version. | |
11 | |
12 ;; GNU Emacs is distributed in the hope that it will be useful, | |
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 ;; GNU General Public License for more details. | |
16 | |
17 ;; You should have received a copy of the GNU General Public License | |
18 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
19 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
20 ;; Boston, MA 02111-1307, USA. | |
21 | |
22 (provide 'em-prompt) | |
23 | |
24 (eval-when-compile (require 'esh-maint)) | |
25 | |
26 (defgroup eshell-prompt nil | |
27 "This module provides command prompts, and navigation between them, | |
28 as is common with most shells." | |
29 :tag "Command prompts" | |
30 :group 'eshell-module) | |
31 | |
32 ;;; Commentary: | |
33 | |
34 ;; Most of the prompt navigation commands of `comint-mode' are | |
35 ;; supported, such as C-c C-n, C-c C-p, etc. | |
36 | |
37 ;;; User Variables: | |
38 | |
39 (defcustom eshell-prompt-load-hook '(eshell-prompt-initialize) | |
40 "*A list of functions to call when loading `eshell-prompt'." | |
41 :type 'hook | |
42 :group 'eshell-prompt) | |
43 | |
44 (defcustom eshell-prompt-function | |
45 (function | |
46 (lambda () | |
47 (concat (eshell/pwd) | |
48 (if (= (user-uid) 0) " # " " $ ")))) | |
49 "*A function that returns the Eshell prompt string. | |
50 Make sure to update `eshell-prompt-regexp' so that it will match your | |
51 prompt." | |
52 :type 'function | |
53 :group 'eshell-prompt) | |
54 | |
55 (defcustom eshell-prompt-regexp "^[^#$\n]* [#$] " | |
56 "*A regexp which fully matches your eshell prompt. | |
57 This setting is important, since it affects how eshell will interpret | |
58 the lines that are passed to it. | |
59 If this variable is changed, all Eshell buffers must be exited and | |
60 re-entered for it to take effect." | |
61 :type 'regexp | |
62 :group 'eshell-prompt) | |
63 | |
64 (defcustom eshell-highlight-prompt t | |
65 "*If non-nil, Eshell should highlight the prompt." | |
66 :type 'boolean | |
67 :group 'eshell-prompt) | |
68 | |
69 (defface eshell-prompt-face | |
70 '((((class color) (background light)) (:foreground "Red" :bold t)) | |
71 (((class color) (background dark)) (:foreground "Pink" :bold t)) | |
72 (t (:bold t))) | |
73 "*The face used to highlight prompt strings. | |
74 For highlighting other kinds of strings -- similar to shell mode's | |
75 behavior -- simply use an output filer which changes text properties." | |
76 :group 'eshell-prompt) | |
77 | |
78 (defcustom eshell-before-prompt-hook nil | |
79 "*A list of functions to call before outputting the prompt." | |
80 :type 'hook | |
81 :options '(eshell-begin-on-new-line) | |
82 :group 'eshell-prompt) | |
83 | |
84 (defcustom eshell-after-prompt-hook nil | |
85 "*A list of functions to call after outputting the prompt. | |
86 Note that if `eshell-scroll-show-maximum-output' is non-nil, then | |
87 setting `eshell-show-maximum-output' here won't do much. It depends | |
88 on whether the user wants the resizing to happen while output is | |
89 arriving, or after." | |
90 :type 'hook | |
91 :options '(eshell-show-maximum-output) | |
92 :group 'eshell-prompt) | |
93 | |
94 ;;; Functions: | |
95 | |
96 (defun eshell-prompt-initialize () | |
97 "Initialize the prompting code." | |
98 (unless eshell-non-interactive-p | |
99 (make-local-hook 'eshell-post-command-hook) | |
100 (add-hook 'eshell-post-command-hook 'eshell-emit-prompt nil t) | |
101 | |
102 (make-local-variable 'eshell-prompt-regexp) | |
103 (if eshell-prompt-regexp | |
104 (set (make-local-variable 'paragraph-start) eshell-prompt-regexp)) | |
105 | |
106 (set (make-local-variable 'eshell-skip-prompt-function) | |
107 'eshell-skip-prompt) | |
108 | |
109 (define-key eshell-command-map [(control ?n)] 'eshell-next-prompt) | |
110 (define-key eshell-command-map [(control ?p)] 'eshell-previous-prompt))) | |
111 | |
112 (defun eshell-emit-prompt () | |
113 "Emit a prompt if eshell is being used interactively." | |
114 (run-hooks 'eshell-before-prompt-hook) | |
115 (if (not eshell-prompt-function) | |
116 (set-marker eshell-last-output-end (point)) | |
117 (let ((prompt (funcall eshell-prompt-function))) | |
118 (and eshell-highlight-prompt | |
119 (add-text-properties 0 (length prompt) | |
120 '(read-only t | |
121 face eshell-prompt-face | |
122 rear-nonsticky (face read-only)) | |
123 prompt)) | |
124 (eshell-interactive-print prompt))) | |
125 (run-hooks 'eshell-after-prompt-hook)) | |
126 | |
127 (defun eshell-backward-matching-input (regexp arg) | |
128 "Search backward through buffer for match for REGEXP. | |
129 Matches are searched for on lines that match `eshell-prompt-regexp'. | |
130 With prefix argument N, search for Nth previous match. | |
131 If N is negative, find the next or Nth next match." | |
132 (interactive (eshell-regexp-arg "Backward input matching (regexp): ")) | |
133 (let* ((re (concat eshell-prompt-regexp ".*" regexp)) | |
134 (pos (save-excursion (end-of-line (if (> arg 0) 0 1)) | |
135 (if (re-search-backward re nil t arg) | |
136 (point))))) | |
137 (if (null pos) | |
138 (progn (message "Not found") | |
139 (ding)) | |
140 (goto-char pos) | |
141 (eshell-bol)))) | |
142 | |
143 (defun eshell-forward-matching-input (regexp arg) | |
144 "Search forward through buffer for match for REGEXP. | |
145 Matches are searched for on lines that match `eshell-prompt-regexp'. | |
146 With prefix argument N, search for Nth following match. | |
147 If N is negative, find the previous or Nth previous match." | |
148 (interactive (eshell-regexp-arg "Forward input matching (regexp): ")) | |
149 (eshell-backward-matching-input regexp (- arg))) | |
150 | |
151 (defun eshell-next-prompt (n) | |
152 "Move to end of Nth next prompt in the buffer. | |
153 See `eshell-prompt-regexp'." | |
154 (interactive "p") | |
155 (forward-paragraph n) | |
156 (eshell-skip-prompt)) | |
157 | |
158 (defun eshell-previous-prompt (n) | |
159 "Move to end of Nth previous prompt in the buffer. | |
160 See `eshell-prompt-regexp'." | |
161 (interactive "p") | |
162 (eshell-next-prompt (- (1+ n)))) | |
163 | |
164 (defun eshell-skip-prompt () | |
165 "Skip past the text matching regexp `eshell-prompt-regexp'. | |
166 If this takes us past the end of the current line, don't skip at all." | |
167 (let ((eol (line-end-position))) | |
168 (if (and (looking-at eshell-prompt-regexp) | |
169 (<= (match-end 0) eol)) | |
170 (goto-char (match-end 0))))) | |
171 | |
172 ;;; Code: | |
173 | |
174 ;;; em-prompt.el ends here |