| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
(provide 'em-prompt) |
|---|
| 26 |
|
|---|
| 27 |
(eval-when-compile (require 'esh-maint)) |
|---|
| 28 |
|
|---|
| 29 |
(defgroup eshell-prompt nil |
|---|
| 30 |
"This module provides command prompts, and navigation between them, |
|---|
| 31 |
as is common with most shells." |
|---|
| 32 |
:tag "Command prompts" |
|---|
| 33 |
:group 'eshell-module) |
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
(defcustom eshell-prompt-load-hook '(eshell-prompt-initialize) |
|---|
| 43 |
"*A list of functions to call when loading `eshell-prompt'." |
|---|
| 44 |
:type 'hook |
|---|
| 45 |
:group 'eshell-prompt) |
|---|
| 46 |
|
|---|
| 47 |
(defcustom eshell-prompt-function |
|---|
| 48 |
(function |
|---|
| 49 |
(lambda () |
|---|
| 50 |
(concat (eshell/pwd) |
|---|
| 51 |
(if (= (user-uid) 0) " # " " $ ")))) |
|---|
| 52 |
"*A function that returns the Eshell prompt string. |
|---|
| 53 |
Make sure to update `eshell-prompt-regexp' so that it will match your |
|---|
| 54 |
prompt." |
|---|
| 55 |
:type 'function |
|---|
| 56 |
:group 'eshell-prompt) |
|---|
| 57 |
|
|---|
| 58 |
(defcustom eshell-prompt-regexp "^[^#$\n]* [#$] " |
|---|
| 59 |
"*A regexp which fully matches your eshell prompt. |
|---|
| 60 |
This setting is important, since it affects how eshell will interpret |
|---|
| 61 |
the lines that are passed to it. |
|---|
| 62 |
If this variable is changed, all Eshell buffers must be exited and |
|---|
| 63 |
re-entered for it to take effect." |
|---|
| 64 |
:type 'regexp |
|---|
| 65 |
:group 'eshell-prompt) |
|---|
| 66 |
|
|---|
| 67 |
(defcustom eshell-highlight-prompt t |
|---|
| 68 |
"*If non-nil, Eshell should highlight the prompt." |
|---|
| 69 |
:type 'boolean |
|---|
| 70 |
:group 'eshell-prompt) |
|---|
| 71 |
|
|---|
| 72 |
(defface eshell-prompt |
|---|
| 73 |
'((((class color) (background light)) (:foreground "Red" :bold t)) |
|---|
| 74 |
(((class color) (background dark)) (:foreground "Pink" :bold t)) |
|---|
| 75 |
(t (:bold t))) |
|---|
| 76 |
"*The face used to highlight prompt strings. |
|---|
| 77 |
For highlighting other kinds of strings -- similar to shell mode's |
|---|
| 78 |
behavior -- simply use an output filer which changes text properties." |
|---|
| 79 |
:group 'eshell-prompt) |
|---|
| 80 |
|
|---|
| 81 |
(put 'eshell-prompt-face 'face-alias 'eshell-prompt) |
|---|
| 82 |
|
|---|
| 83 |
(defcustom eshell-before-prompt-hook nil |
|---|
| 84 |
"*A list of functions to call before outputting the prompt." |
|---|
| 85 |
:type 'hook |
|---|
| 86 |
:options '(eshell-begin-on-new-line) |
|---|
| 87 |
:group 'eshell-prompt) |
|---|
| 88 |
|
|---|
| 89 |
(defcustom eshell-after-prompt-hook nil |
|---|
| 90 |
"*A list of functions to call after outputting the prompt. |
|---|
| 91 |
Note that if `eshell-scroll-show-maximum-output' is non-nil, then |
|---|
| 92 |
setting `eshell-show-maximum-output' here won't do much. It depends |
|---|
| 93 |
on whether the user wants the resizing to happen while output is |
|---|
| 94 |
arriving, or after." |
|---|
| 95 |
:type 'hook |
|---|
| 96 |
:options '(eshell-show-maximum-output) |
|---|
| 97 |
:group 'eshell-prompt) |
|---|
| 98 |
|
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 |
(defun eshell-prompt-initialize () |
|---|
| 102 |
"Initialize the prompting code." |
|---|
| 103 |
(unless eshell-non-interactive-p |
|---|
| 104 |
(add-hook 'eshell-post-command-hook 'eshell-emit-prompt nil t) |
|---|
| 105 |
|
|---|
| 106 |
(make-local-variable 'eshell-prompt-regexp) |
|---|
| 107 |
(if eshell-prompt-regexp |
|---|
| 108 |
(set (make-local-variable 'paragraph-start) eshell-prompt-regexp)) |
|---|
| 109 |
|
|---|
| 110 |
(set (make-local-variable 'eshell-skip-prompt-function) |
|---|
| 111 |
'eshell-skip-prompt) |
|---|
| 112 |
|
|---|
| 113 |
(define-key eshell-command-map [(control ?n)] 'eshell-next-prompt) |
|---|
| 114 |
(define-key eshell-command-map [(control ?p)] 'eshell-previous-prompt))) |
|---|
| 115 |
|
|---|
| 116 |
(defun eshell-emit-prompt () |
|---|
| 117 |
"Emit a prompt if eshell is being used interactively." |
|---|
| 118 |
(run-hooks 'eshell-before-prompt-hook) |
|---|
| 119 |
(if (not eshell-prompt-function) |
|---|
| 120 |
(set-marker eshell-last-output-end (point)) |
|---|
| 121 |
(let ((prompt (funcall eshell-prompt-function))) |
|---|
| 122 |
(and eshell-highlight-prompt |
|---|
| 123 |
(add-text-properties 0 (length prompt) |
|---|
| 124 |
'(read-only t |
|---|
| 125 |
face eshell-prompt |
|---|
| 126 |
rear-nonsticky (face read-only)) |
|---|
| 127 |
prompt)) |
|---|
| 128 |
(eshell-interactive-print prompt))) |
|---|
| 129 |
(run-hooks 'eshell-after-prompt-hook)) |
|---|
| 130 |
|
|---|
| 131 |
(defun eshell-backward-matching-input (regexp arg) |
|---|
| 132 |
"Search backward through buffer for match for REGEXP. |
|---|
| 133 |
Matches are searched for on lines that match `eshell-prompt-regexp'. |
|---|
| 134 |
With prefix argument N, search for Nth previous match. |
|---|
| 135 |
If N is negative, find the next or Nth next match." |
|---|
| 136 |
(interactive (eshell-regexp-arg "Backward input matching (regexp): ")) |
|---|
| 137 |
(let* ((re (concat eshell-prompt-regexp ".*" regexp)) |
|---|
| 138 |
(pos (save-excursion (end-of-line (if (> arg 0) 0 1)) |
|---|
| 139 |
(if (re-search-backward re nil t arg) |
|---|
| 140 |
(point))))) |
|---|
| 141 |
(if (null pos) |
|---|
| 142 |
(progn (message "Not found") |
|---|
| 143 |
(ding)) |
|---|
| 144 |
(goto-char pos) |
|---|
| 145 |
(eshell-bol)))) |
|---|
| 146 |
|
|---|
| 147 |
(defun eshell-forward-matching-input (regexp arg) |
|---|
| 148 |
"Search forward through buffer for match for REGEXP. |
|---|
| 149 |
Matches are searched for on lines that match `eshell-prompt-regexp'. |
|---|
| 150 |
With prefix argument N, search for Nth following match. |
|---|
| 151 |
If N is negative, find the previous or Nth previous match." |
|---|
| 152 |
(interactive (eshell-regexp-arg "Forward input matching (regexp): ")) |
|---|
| 153 |
(eshell-backward-matching-input regexp (- arg))) |
|---|
| 154 |
|
|---|
| 155 |
(defun eshell-next-prompt (n) |
|---|
| 156 |
"Move to end of Nth next prompt in the buffer. |
|---|
| 157 |
See `eshell-prompt-regexp'." |
|---|
| 158 |
(interactive "p") |
|---|
| 159 |
(forward-paragraph n) |
|---|
| 160 |
(eshell-skip-prompt)) |
|---|
| 161 |
|
|---|
| 162 |
(defun eshell-previous-prompt (n) |
|---|
| 163 |
"Move to end of Nth previous prompt in the buffer. |
|---|
| 164 |
See `eshell-prompt-regexp'." |
|---|
| 165 |
(interactive "p") |
|---|
| 166 |
(eshell-next-prompt (- (1+ n)))) |
|---|
| 167 |
|
|---|
| 168 |
(defun eshell-skip-prompt () |
|---|
| 169 |
"Skip past the text matching regexp `eshell-prompt-regexp'. |
|---|
| 170 |
If this takes us past the end of the current line, don't skip at all." |
|---|
| 171 |
(let ((eol (line-end-position))) |
|---|
| 172 |
(if (and (looking-at eshell-prompt-regexp) |
|---|
| 173 |
(<= (match-end 0) eol)) |
|---|
| 174 |
(goto-char (match-end 0))))) |
|---|
| 175 |
|
|---|
| 176 |
|
|---|
| 177 |
|
|---|
| 178 |
|
|---|
| 179 |
|
|---|
| 180 |
|
|---|