Mercurial > emacs
annotate lisp/eshell/em-prompt.el @ 64504:6d0e9c3f9769
(widget-inactive): Inherit from `shadow'.
author | Juri Linkov <juri@jurta.org> |
---|---|
date | Tue, 19 Jul 2005 11:43:26 +0000 |
parents | 18a818a2ee7c |
children | 34bd8e434dd7 f9a65d7ebd29 |
rev | line source |
---|---|
38414
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
32526
diff
changeset
|
1 ;;; em-prompt.el --- command prompts |
29876 | 2 |
63533
b7ea6515f1ba
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-431
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
3 ;; Copyright (C) 1999, 2000, 2005 Free Software Foundation |
29876 | 4 |
32526 | 5 ;; Author: John Wiegley <johnw@gnu.org> |
6 | |
29876 | 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 | |
64085 | 21 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
22 ;; Boston, MA 02110-1301, USA. | |
29876 | 23 |
24 (provide 'em-prompt) | |
25 | |
26 (eval-when-compile (require 'esh-maint)) | |
27 | |
28 (defgroup eshell-prompt nil | |
29 "This module provides command prompts, and navigation between them, | |
30 as is common with most shells." | |
31 :tag "Command prompts" | |
32 :group 'eshell-module) | |
33 | |
34 ;;; Commentary: | |
35 | |
36 ;; Most of the prompt navigation commands of `comint-mode' are | |
37 ;; supported, such as C-c C-n, C-c C-p, etc. | |
38 | |
39 ;;; User Variables: | |
40 | |
41 (defcustom eshell-prompt-load-hook '(eshell-prompt-initialize) | |
42 "*A list of functions to call when loading `eshell-prompt'." | |
43 :type 'hook | |
44 :group 'eshell-prompt) | |
45 | |
46 (defcustom eshell-prompt-function | |
47 (function | |
48 (lambda () | |
49 (concat (eshell/pwd) | |
50 (if (= (user-uid) 0) " # " " $ ")))) | |
51 "*A function that returns the Eshell prompt string. | |
52 Make sure to update `eshell-prompt-regexp' so that it will match your | |
53 prompt." | |
54 :type 'function | |
55 :group 'eshell-prompt) | |
56 | |
57 (defcustom eshell-prompt-regexp "^[^#$\n]* [#$] " | |
58 "*A regexp which fully matches your eshell prompt. | |
59 This setting is important, since it affects how eshell will interpret | |
60 the lines that are passed to it. | |
61 If this variable is changed, all Eshell buffers must be exited and | |
62 re-entered for it to take effect." | |
63 :type 'regexp | |
64 :group 'eshell-prompt) | |
65 | |
66 (defcustom eshell-highlight-prompt t | |
67 "*If non-nil, Eshell should highlight the prompt." | |
68 :type 'boolean | |
69 :group 'eshell-prompt) | |
70 | |
63533
b7ea6515f1ba
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-431
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
71 (defface eshell-prompt |
29876 | 72 '((((class color) (background light)) (:foreground "Red" :bold t)) |
73 (((class color) (background dark)) (:foreground "Pink" :bold t)) | |
74 (t (:bold t))) | |
75 "*The face used to highlight prompt strings. | |
76 For highlighting other kinds of strings -- similar to shell mode's | |
77 behavior -- simply use an output filer which changes text properties." | |
78 :group 'eshell-prompt) | |
63533
b7ea6515f1ba
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-431
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
79 ;; backward-compatibility alias |
b7ea6515f1ba
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-431
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
80 (put 'eshell-prompt-face 'face-alias 'eshell-prompt) |
29876 | 81 |
82 (defcustom eshell-before-prompt-hook nil | |
83 "*A list of functions to call before outputting the prompt." | |
84 :type 'hook | |
85 :options '(eshell-begin-on-new-line) | |
86 :group 'eshell-prompt) | |
87 | |
88 (defcustom eshell-after-prompt-hook nil | |
89 "*A list of functions to call after outputting the prompt. | |
90 Note that if `eshell-scroll-show-maximum-output' is non-nil, then | |
91 setting `eshell-show-maximum-output' here won't do much. It depends | |
92 on whether the user wants the resizing to happen while output is | |
93 arriving, or after." | |
94 :type 'hook | |
95 :options '(eshell-show-maximum-output) | |
96 :group 'eshell-prompt) | |
97 | |
98 ;;; Functions: | |
99 | |
100 (defun eshell-prompt-initialize () | |
101 "Initialize the prompting code." | |
102 (unless eshell-non-interactive-p | |
103 (add-hook 'eshell-post-command-hook 'eshell-emit-prompt nil t) | |
104 | |
105 (make-local-variable 'eshell-prompt-regexp) | |
106 (if eshell-prompt-regexp | |
107 (set (make-local-variable 'paragraph-start) eshell-prompt-regexp)) | |
108 | |
109 (set (make-local-variable 'eshell-skip-prompt-function) | |
110 'eshell-skip-prompt) | |
111 | |
112 (define-key eshell-command-map [(control ?n)] 'eshell-next-prompt) | |
113 (define-key eshell-command-map [(control ?p)] 'eshell-previous-prompt))) | |
114 | |
115 (defun eshell-emit-prompt () | |
116 "Emit a prompt if eshell is being used interactively." | |
117 (run-hooks 'eshell-before-prompt-hook) | |
118 (if (not eshell-prompt-function) | |
119 (set-marker eshell-last-output-end (point)) | |
120 (let ((prompt (funcall eshell-prompt-function))) | |
121 (and eshell-highlight-prompt | |
122 (add-text-properties 0 (length prompt) | |
123 '(read-only t | |
63533
b7ea6515f1ba
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-431
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
124 face eshell-prompt |
29876 | 125 rear-nonsticky (face read-only)) |
126 prompt)) | |
127 (eshell-interactive-print prompt))) | |
128 (run-hooks 'eshell-after-prompt-hook)) | |
129 | |
130 (defun eshell-backward-matching-input (regexp arg) | |
131 "Search backward through buffer for match for REGEXP. | |
132 Matches are searched for on lines that match `eshell-prompt-regexp'. | |
133 With prefix argument N, search for Nth previous match. | |
134 If N is negative, find the next or Nth next match." | |
135 (interactive (eshell-regexp-arg "Backward input matching (regexp): ")) | |
136 (let* ((re (concat eshell-prompt-regexp ".*" regexp)) | |
137 (pos (save-excursion (end-of-line (if (> arg 0) 0 1)) | |
138 (if (re-search-backward re nil t arg) | |
139 (point))))) | |
140 (if (null pos) | |
141 (progn (message "Not found") | |
142 (ding)) | |
143 (goto-char pos) | |
144 (eshell-bol)))) | |
145 | |
146 (defun eshell-forward-matching-input (regexp arg) | |
147 "Search forward through buffer for match for REGEXP. | |
148 Matches are searched for on lines that match `eshell-prompt-regexp'. | |
149 With prefix argument N, search for Nth following match. | |
150 If N is negative, find the previous or Nth previous match." | |
151 (interactive (eshell-regexp-arg "Forward input matching (regexp): ")) | |
152 (eshell-backward-matching-input regexp (- arg))) | |
153 | |
154 (defun eshell-next-prompt (n) | |
155 "Move to end of Nth next prompt in the buffer. | |
156 See `eshell-prompt-regexp'." | |
157 (interactive "p") | |
158 (forward-paragraph n) | |
159 (eshell-skip-prompt)) | |
160 | |
161 (defun eshell-previous-prompt (n) | |
162 "Move to end of Nth previous prompt in the buffer. | |
163 See `eshell-prompt-regexp'." | |
164 (interactive "p") | |
165 (eshell-next-prompt (- (1+ n)))) | |
166 | |
167 (defun eshell-skip-prompt () | |
168 "Skip past the text matching regexp `eshell-prompt-regexp'. | |
169 If this takes us past the end of the current line, don't skip at all." | |
170 (let ((eol (line-end-position))) | |
171 (if (and (looking-at eshell-prompt-regexp) | |
172 (<= (match-end 0) eol)) | |
173 (goto-char (match-end 0))))) | |
174 | |
175 ;;; Code: | |
176 | |
52401 | 177 ;;; arch-tag: 01c1574b-ce70-4e89-bc38-e6619f61e208 |
29876 | 178 ;;; em-prompt.el ends here |