Mercurial > emacs
comparison lisp/comint.el @ 61873:1cd2d4d601fa
(comint-prompt-regexp, comint-get-old-input)
(comint-use-prompt-regexp)
(comint-use-prompt-regexp-instead-of-fields)
(comint-replace-by-expanded-history, comint-send-input)
(comint-output-filter, comint-get-old-input-default)
(comint-line-beginning-position, comint-bol, comint-show-output)
(comint-backward-matching-input, comint-forward-matching-input)
(comint-next-prompt, comint-previous-prompt): Rename
`comint-use-prompt-regexp-instead-of-fields' to
`comint-use-prompt-regexp'. Keep old name as alias and declare obsolete.
(comint-use-prompt-regexp): Shorten first line of doc string.
author | Luc Teirlinck <teirllm@auburn.edu> |
---|---|
date | Tue, 26 Apr 2005 23:11:17 +0000 |
parents | 7c224837fcfe |
children | 073c1d646ae1 |
comparison
equal
deleted
inserted
replaced
61872:0c656a4bd81b | 61873:1cd2d4d601fa |
---|---|
157 (defvar comint-prompt-regexp "^" | 157 (defvar comint-prompt-regexp "^" |
158 "Regexp to recognise prompts in the inferior process. | 158 "Regexp to recognise prompts in the inferior process. |
159 Defaults to \"^\", the null string at BOL. | 159 Defaults to \"^\", the null string at BOL. |
160 | 160 |
161 This variable is only used if the variable | 161 This variable is only used if the variable |
162 `comint-use-prompt-regexp-instead-of-fields' is non-nil. | 162 `comint-use-prompt-regexp' is non-nil. |
163 | 163 |
164 Good choices: | 164 Good choices: |
165 Canonical Lisp: \"^[^> \\n]*>+:? *\" (Lucid, franz, kcl, T, cscheme, oaklisp) | 165 Canonical Lisp: \"^[^> \\n]*>+:? *\" (Lucid, franz, kcl, T, cscheme, oaklisp) |
166 Lucid Common Lisp: \"^\\\\(>\\\\|\\\\(->\\\\)+\\\\) *\" | 166 Lucid Common Lisp: \"^\\\\(>\\\\|\\\\(->\\\\)+\\\\) *\" |
167 franz: \"^\\\\(->\\\\|<[0-9]*>:\\\\) *\" | 167 franz: \"^\\\\(->\\\\|<[0-9]*>:\\\\) *\" |
351 This function is called when return is typed while the point is in old | 351 This function is called when return is typed while the point is in old |
352 text. It returns the text to be submitted as process input. The | 352 text. It returns the text to be submitted as process input. The |
353 default is `comint-get-old-input-default', which either grabs the | 353 default is `comint-get-old-input-default', which either grabs the |
354 current input field or grabs the current line and strips off leading | 354 current input field or grabs the current line and strips off leading |
355 text matching `comint-prompt-regexp', depending on the value of | 355 text matching `comint-prompt-regexp', depending on the value of |
356 `comint-use-prompt-regexp-instead-of-fields'.") | 356 `comint-use-prompt-regexp'.") |
357 | 357 |
358 (defvar comint-dynamic-complete-functions | 358 (defvar comint-dynamic-complete-functions |
359 '(comint-replace-by-expanded-history comint-dynamic-complete-filename) | 359 '(comint-replace-by-expanded-history comint-dynamic-complete-filename) |
360 "List of functions called to perform completion. | 360 "List of functions called to perform completion. |
361 Functions should return non-nil if completion was performed. | 361 Functions should return non-nil if completion was performed. |
404 :group 'comint) | 404 :group 'comint) |
405 | 405 |
406 ;; Note: If it is decided to purge comint-prompt-regexp from the source | 406 ;; Note: If it is decided to purge comint-prompt-regexp from the source |
407 ;; entirely, searching for uses of this variable will help to identify | 407 ;; entirely, searching for uses of this variable will help to identify |
408 ;; places that need attention. | 408 ;; places that need attention. |
409 (defcustom comint-use-prompt-regexp-instead-of-fields nil | 409 (defcustom comint-use-prompt-regexp nil |
410 "*If non-nil, use `comint-prompt-regexp' to distinguish prompts from user-input. | 410 "*If non-nil, use `comint-prompt-regexp' to recognize prompts. |
411 If nil, then program output and user-input are given different `field' | 411 If nil, then program output and user-input are given different `field' |
412 properties, which Emacs commands can use to distinguish them (in | 412 properties, which Emacs commands can use to distinguish them (in |
413 particular, common movement commands such as begining-of-line respect | 413 particular, common movement commands such as begining-of-line respect |
414 field boundaries in a natural way)." | 414 field boundaries in a natural way)." |
415 :type 'boolean | 415 :type 'boolean |
416 :group 'comint) | 416 :group 'comint) |
417 | |
418 ;; Autoload is necessary for Custom to recognize old alias. | |
419 ;;;###autoload | |
420 (defvaralias 'comint-use-prompt-regexp-instead-of-fields | |
421 'comint-use-prompt-regexp) | |
422 (make-obsolete-variable 'comint-use-prompt-regexp-instead-of-fields | |
423 'comint-use-prompt-regexp "22.1") | |
417 | 424 |
418 (defcustom comint-mode-hook '(turn-on-font-lock) | 425 (defcustom comint-mode-hook '(turn-on-font-lock) |
419 "Hook run upon entry to `comint-mode'. | 426 "Hook run upon entry to `comint-mode'. |
420 This is run before the process is cranked up." | 427 This is run before the process is cranked up." |
421 :type 'hook | 428 :type 'hook |
1148 See `comint-magic-space' and `comint-replace-by-expanded-history-before-point'. | 1155 See `comint-magic-space' and `comint-replace-by-expanded-history-before-point'. |
1149 | 1156 |
1150 Returns t if successful." | 1157 Returns t if successful." |
1151 (interactive) | 1158 (interactive) |
1152 (if (and comint-input-autoexpand | 1159 (if (and comint-input-autoexpand |
1153 (if comint-use-prompt-regexp-instead-of-fields | 1160 (if comint-use-prompt-regexp |
1154 ;; Use comint-prompt-regexp | 1161 ;; Use comint-prompt-regexp |
1155 (save-excursion | 1162 (save-excursion |
1156 (beginning-of-line) | 1163 (beginning-of-line) |
1157 (looking-at (concat comint-prompt-regexp "!\\|\\^"))) | 1164 (looking-at (concat comint-prompt-regexp "!\\|\\^"))) |
1158 ;; Use input fields. User input that hasn't been entered | 1165 ;; Use input fields. User input that hasn't been entered |
1417 `comint-input-filter' are chosen according to the command interpreter running | 1424 `comint-input-filter' are chosen according to the command interpreter running |
1418 in the buffer. E.g., | 1425 in the buffer. E.g., |
1419 | 1426 |
1420 If the interpreter is the csh, | 1427 If the interpreter is the csh, |
1421 `comint-get-old-input' is the default: | 1428 `comint-get-old-input' is the default: |
1422 If `comint-use-prompt-regexp-instead-of-fields' is nil, then | 1429 If `comint-use-prompt-regexp' is nil, then |
1423 either return the current input field, if point is on an input | 1430 either return the current input field, if point is on an input |
1424 field, or the current line, if point is on an output field. | 1431 field, or the current line, if point is on an output field. |
1425 If `comint-use-prompt-regexp-instead-of-fields' is non-nil, then | 1432 If `comint-use-prompt-regexp' is non-nil, then |
1426 return the current line with any initial string matching the | 1433 return the current line with any initial string matching the |
1427 regexp `comint-prompt-regexp' removed. | 1434 regexp `comint-prompt-regexp' removed. |
1428 `comint-input-filter-functions' monitors input for \"cd\", \"pushd\", and | 1435 `comint-input-filter-functions' monitors input for \"cd\", \"pushd\", and |
1429 \"popd\" commands. When it sees one, it cd's the buffer. | 1436 \"popd\" commands. When it sees one, it cd's the buffer. |
1430 comint-input-filter is the default: returns t if the input isn't all white | 1437 comint-input-filter is the default: returns t if the input isn't all white |
1485 beg end | 1492 beg end |
1486 '(front-sticky t | 1493 '(front-sticky t |
1487 font-lock-face comint-highlight-input | 1494 font-lock-face comint-highlight-input |
1488 mouse-face highlight | 1495 mouse-face highlight |
1489 help-echo "mouse-2: insert after prompt as new input")) | 1496 help-echo "mouse-2: insert after prompt as new input")) |
1490 (unless comint-use-prompt-regexp-instead-of-fields | 1497 (unless comint-use-prompt-regexp |
1491 ;; Give old user input a field property of `input', to | 1498 ;; Give old user input a field property of `input', to |
1492 ;; distinguish it from both process output and unsent | 1499 ;; distinguish it from both process output and unsent |
1493 ;; input. The terminating newline is put into a special | 1500 ;; input. The terminating newline is put into a special |
1494 ;; `boundary' field to make cursor movement between input | 1501 ;; `boundary' field to make cursor movement between input |
1495 ;; and output fields smoother. | 1502 ;; and output fields smoother. |
1496 (put-text-property beg end 'field 'input))) | 1503 (put-text-property beg end 'field 'input))) |
1497 (unless (or no-newline comint-use-prompt-regexp-instead-of-fields) | 1504 (unless (or no-newline comint-use-prompt-regexp) |
1498 ;; Cover the terminating newline | 1505 ;; Cover the terminating newline |
1499 (add-text-properties end (1+ end) | 1506 (add-text-properties end (1+ end) |
1500 '(rear-nonsticky t | 1507 '(rear-nonsticky t |
1501 field boundary | 1508 field boundary |
1502 inhibit-line-move-field-capture t)))) | 1509 inhibit-line-move-field-capture t)))) |
1706 (run-hook-with-args 'comint-output-filter-functions string) | 1713 (run-hook-with-args 'comint-output-filter-functions string) |
1707 (set-marker saved-point (point)) | 1714 (set-marker saved-point (point)) |
1708 | 1715 |
1709 (goto-char (process-mark process)) ; in case a filter moved it | 1716 (goto-char (process-mark process)) ; in case a filter moved it |
1710 | 1717 |
1711 (unless comint-use-prompt-regexp-instead-of-fields | 1718 (unless comint-use-prompt-regexp |
1712 (let ((inhibit-read-only t) | 1719 (let ((inhibit-read-only t) |
1713 (inhibit-modification-hooks t)) | 1720 (inhibit-modification-hooks t)) |
1714 (add-text-properties comint-last-output-start (point) | 1721 (add-text-properties comint-last-output-start (point) |
1715 '(rear-nonsticky t | 1722 '(rear-nonsticky t |
1716 field output | 1723 field output |
1842 (goto-char (point-max)) | 1849 (goto-char (point-max)) |
1843 (recenter -1)) | 1850 (recenter -1)) |
1844 | 1851 |
1845 (defun comint-get-old-input-default () | 1852 (defun comint-get-old-input-default () |
1846 "Default for `comint-get-old-input'. | 1853 "Default for `comint-get-old-input'. |
1847 If `comint-use-prompt-regexp-instead-of-fields' is nil, then either | 1854 If `comint-use-prompt-regexp' is nil, then either |
1848 return the current input field, if point is on an input field, or the | 1855 return the current input field, if point is on an input field, or the |
1849 current line, if point is on an output field. | 1856 current line, if point is on an output field. |
1850 If `comint-use-prompt-regexp-instead-of-fields' is non-nil, then return | 1857 If `comint-use-prompt-regexp' is non-nil, then return |
1851 the current line with any initial string matching the regexp | 1858 the current line with any initial string matching the regexp |
1852 `comint-prompt-regexp' removed." | 1859 `comint-prompt-regexp' removed." |
1853 (let ((bof (field-beginning))) | 1860 (let ((bof (field-beginning))) |
1854 (if (eq (get-char-property bof 'field) 'input) | 1861 (if (eq (get-char-property bof 'field) 'input) |
1855 (field-string-no-properties bof) | 1862 (field-string-no-properties bof) |
1878 (process-send-eof)) | 1885 (process-send-eof)) |
1879 (comint-send-string proc "\n"))) | 1886 (comint-send-string proc "\n"))) |
1880 | 1887 |
1881 (defun comint-line-beginning-position () | 1888 (defun comint-line-beginning-position () |
1882 "Return the buffer position of the beginning of the line, after any prompt. | 1889 "Return the buffer position of the beginning of the line, after any prompt. |
1883 If `comint-use-prompt-regexp-instead-of-fields' is non-nil, then the | 1890 If `comint-use-prompt-regexp' is non-nil, then the prompt skip is done by |
1884 prompt skip is done by skipping text matching the regular expression | 1891 skipping text matching the regular expression `comint-prompt-regexp', |
1885 `comint-prompt-regexp', a buffer local variable." | 1892 a buffer local variable." |
1886 (if comint-use-prompt-regexp-instead-of-fields | 1893 (if comint-use-prompt-regexp |
1887 ;; Use comint-prompt-regexp | 1894 ;; Use comint-prompt-regexp |
1888 (save-excursion | 1895 (save-excursion |
1889 (beginning-of-line) | 1896 (beginning-of-line) |
1890 (comint-skip-prompt) | 1897 (comint-skip-prompt) |
1891 (point)) | 1898 (point)) |
1899 (constrain-to-field (line-beginning-position) (line-end-position)))) | 1906 (constrain-to-field (line-beginning-position) (line-end-position)))) |
1900 | 1907 |
1901 (defun comint-bol (&optional arg) | 1908 (defun comint-bol (&optional arg) |
1902 "Go to the beginning of line, then skip past the prompt, if any. | 1909 "Go to the beginning of line, then skip past the prompt, if any. |
1903 If prefix argument is given (\\[universal-argument]) the prompt is not skipped. | 1910 If prefix argument is given (\\[universal-argument]) the prompt is not skipped. |
1904 If `comint-use-prompt-regexp-instead-of-fields' is non-nil, then the | 1911 If `comint-use-prompt-regexp' is non-nil, then the prompt skip is done |
1905 prompt skip is done by skipping text matching the regular expression | 1912 by skipping text matching the regular expression `comint-prompt-regexp', |
1906 `comint-prompt-regexp', a buffer local variable." | 1913 a buffer local variable." |
1907 (interactive "P") | 1914 (interactive "P") |
1908 (if arg | 1915 (if arg |
1909 ;; Unlike `beginning-of-line', forward-line ignores field boundaries | 1916 ;; Unlike `beginning-of-line', forward-line ignores field boundaries |
1910 (forward-line 0) | 1917 (forward-line 0) |
1911 (goto-char (comint-line-beginning-position)))) | 1918 (goto-char (comint-line-beginning-position)))) |
2032 "Display start of this batch of interpreter output at top of window. | 2039 "Display start of this batch of interpreter output at top of window. |
2033 Sets mark to the value of point when this command is run." | 2040 Sets mark to the value of point when this command is run." |
2034 (interactive) | 2041 (interactive) |
2035 (push-mark) | 2042 (push-mark) |
2036 (let ((pos (or (marker-position comint-last-input-end) (point-max)))) | 2043 (let ((pos (or (marker-position comint-last-input-end) (point-max)))) |
2037 (cond (comint-use-prompt-regexp-instead-of-fields | 2044 (cond (comint-use-prompt-regexp |
2038 (goto-char pos) | 2045 (goto-char pos) |
2039 (beginning-of-line 0) | 2046 (beginning-of-line 0) |
2040 (set-window-start (selected-window) (point)) | 2047 (set-window-start (selected-window) (point)) |
2041 (comint-skip-prompt)) | 2048 (comint-skip-prompt)) |
2042 (t | 2049 (t |
2125 (process-send-eof)) | 2132 (process-send-eof)) |
2126 | 2133 |
2127 | 2134 |
2128 (defun comint-backward-matching-input (regexp n) | 2135 (defun comint-backward-matching-input (regexp n) |
2129 "Search backward through buffer for input fields that match REGEXP. | 2136 "Search backward through buffer for input fields that match REGEXP. |
2130 If `comint-use-prompt-regexp-instead-of-fields' is non-nil, then input | 2137 If `comint-use-prompt-regexp' is non-nil, then input fields are identified |
2131 fields are identified by lines that match `comint-prompt-regexp'. | 2138 by lines that match `comint-prompt-regexp'. |
2132 | 2139 |
2133 With prefix argument N, search for Nth previous match. | 2140 With prefix argument N, search for Nth previous match. |
2134 If N is negative, find the next or Nth next match." | 2141 If N is negative, find the next or Nth next match." |
2135 (interactive (comint-regexp-arg "Backward input matching (regexp): ")) | 2142 (interactive (comint-regexp-arg "Backward input matching (regexp): ")) |
2136 (if comint-use-prompt-regexp-instead-of-fields | 2143 (if comint-use-prompt-regexp |
2137 ;; Use comint-prompt-regexp | 2144 ;; Use comint-prompt-regexp |
2138 (let* ((re (concat comint-prompt-regexp ".*" regexp)) | 2145 (let* ((re (concat comint-prompt-regexp ".*" regexp)) |
2139 (pos (save-excursion (end-of-line (if (> n 0) 0 1)) | 2146 (pos (save-excursion (end-of-line (if (> n 0) 0 1)) |
2140 (if (re-search-backward re nil t n) | 2147 (if (re-search-backward re nil t n) |
2141 (point))))) | 2148 (point))))) |
2157 (goto-char pos)))) | 2164 (goto-char pos)))) |
2158 | 2165 |
2159 | 2166 |
2160 (defun comint-forward-matching-input (regexp arg) | 2167 (defun comint-forward-matching-input (regexp arg) |
2161 "Search forward through buffer for input fields that match REGEXP. | 2168 "Search forward through buffer for input fields that match REGEXP. |
2162 If `comint-use-prompt-regexp-instead-of-fields' is non-nil, then input | 2169 If `comint-use-prompt-regexp' is non-nil, then input fields are identified |
2163 fields are identified by lines that match `comint-prompt-regexp'. | 2170 by lines that match `comint-prompt-regexp'. |
2164 | 2171 |
2165 With prefix argument N, search for Nth following match. | 2172 With prefix argument N, search for Nth following match. |
2166 If N is negative, find the previous or Nth previous match." | 2173 If N is negative, find the previous or Nth previous match." |
2167 (interactive (comint-regexp-arg "Forward input matching (regexp): ")) | 2174 (interactive (comint-regexp-arg "Forward input matching (regexp): ")) |
2168 (comint-backward-matching-input regexp (- arg))) | 2175 (comint-backward-matching-input regexp (- arg))) |
2169 | 2176 |
2170 | 2177 |
2171 (defun comint-next-prompt (n) | 2178 (defun comint-next-prompt (n) |
2172 "Move to end of Nth next prompt in the buffer. | 2179 "Move to end of Nth next prompt in the buffer. |
2173 If `comint-use-prompt-regexp-instead-of-fields' is nil, then this means | 2180 If `comint-use-prompt-regexp' is nil, then this means the beginning of |
2174 the beginning of the Nth next `input' field, otherwise, it means the Nth | 2181 the Nth next `input' field, otherwise, it means the Nth occurrence of |
2175 occurrence of text matching `comint-prompt-regexp'." | 2182 text matching `comint-prompt-regexp'." |
2176 (interactive "p") | 2183 (interactive "p") |
2177 (if comint-use-prompt-regexp-instead-of-fields | 2184 (if comint-use-prompt-regexp |
2178 ;; Use comint-prompt-regexp | 2185 ;; Use comint-prompt-regexp |
2179 (let ((paragraph-start comint-prompt-regexp)) | 2186 (let ((paragraph-start comint-prompt-regexp)) |
2180 (end-of-line (if (> n 0) 1 0)) | 2187 (end-of-line (if (> n 0) 1 0)) |
2181 (forward-paragraph n) | 2188 (forward-paragraph n) |
2182 (comint-skip-prompt)) | 2189 (comint-skip-prompt)) |
2205 (goto-char input-pos))))) | 2212 (goto-char input-pos))))) |
2206 | 2213 |
2207 | 2214 |
2208 (defun comint-previous-prompt (n) | 2215 (defun comint-previous-prompt (n) |
2209 "Move to end of Nth previous prompt in the buffer. | 2216 "Move to end of Nth previous prompt in the buffer. |
2210 If `comint-use-prompt-regexp-instead-of-fields' is nil, then this means | 2217 If `comint-use-prompt-regexp' is nil, then this means the beginning of |
2211 the beginning of the Nth previous `input' field, otherwise, it means the Nth | 2218 the Nth previous `input' field, otherwise, it means the Nth occurrence of |
2212 occurrence of text matching `comint-prompt-regexp'." | 2219 text matching `comint-prompt-regexp'." |
2213 (interactive "p") | 2220 (interactive "p") |
2214 (comint-next-prompt (- n))) | 2221 (comint-next-prompt (- n))) |
2215 | 2222 |
2216 ;; State used by `comint-insert-previous-argument' when cycling. | 2223 ;; State used by `comint-insert-previous-argument' when cycling. |
2217 (defvar comint-insert-previous-argument-last-start-pos nil) | 2224 (defvar comint-insert-previous-argument-last-start-pos nil) |
3020 ;; XXX: This doesn't work so well unless `comint-prompt-regexp' is set; | 3027 ;; XXX: This doesn't work so well unless `comint-prompt-regexp' is set; |
3021 ;; perhaps it should prompt for a terminating string (with an | 3028 ;; perhaps it should prompt for a terminating string (with an |
3022 ;; appropriate magic default by examining what we think is the prompt)? | 3029 ;; appropriate magic default by examining what we think is the prompt)? |
3023 ;; | 3030 ;; |
3024 ;; Fixme: look for appropriate fields, rather than regexp, if | 3031 ;; Fixme: look for appropriate fields, rather than regexp, if |
3025 ;; `comint-use-prompt-regexp-instead-of-fields' is true. | 3032 ;; `comint-use-prompt-regexp' is true. |
3026 | 3033 |
3027 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 3034 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
3028 ;; Variables | 3035 ;; Variables |
3029 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 3036 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
3030 | 3037 |