diff options
| author | Luc Teirlinck | 2004-05-01 20:14:23 +0000 |
|---|---|---|
| committer | Luc Teirlinck | 2004-05-01 20:14:23 +0000 |
| commit | b930b8efd4a435ab964b0f513a7b3688eecc58f6 (patch) | |
| tree | d9cabd29b6dd083feb9eb7094c3c9cf2dd8422ed | |
| parent | f8b0f284a37b7ecefc08f7ab4b7a5b5947934e7b (diff) | |
| download | emacs-b930b8efd4a435ab964b0f513a7b3688eecc58f6.tar.gz emacs-b930b8efd4a435ab964b0f513a7b3688eecc58f6.zip | |
(comint-prompt-read-only): Update docstring.
(comint-update-fence, comint-kill-whole-line)
(comint-kill-region): New functions.
| -rw-r--r-- | lisp/comint.el | 96 |
1 files changed, 95 insertions, 1 deletions
diff --git a/lisp/comint.el b/lisp/comint.el index 52217fa8ad6..c5e903fc58f 100644 --- a/lisp/comint.el +++ b/lisp/comint.el | |||
| @@ -173,8 +173,25 @@ This is a good thing to set in mode hooks.") | |||
| 173 | 173 | ||
| 174 | (defcustom comint-prompt-read-only nil | 174 | (defcustom comint-prompt-read-only nil |
| 175 | "If non-nil, the comint prompt is read only. | 175 | "If non-nil, the comint prompt is read only. |
| 176 | The read only region includes the newline before the prompt. | ||
| 176 | This does not affect existing prompts. | 177 | This does not affect existing prompts. |
| 177 | Certain derived modes may override this option." | 178 | Certain derived modes may override this option. |
| 179 | |||
| 180 | If you set this option to t, then the safe way to temporarily | ||
| 181 | override the read-only-ness of comint prompts is to call | ||
| 182 | `comint-kill-whole-line' or `comint-kill-region' with no | ||
| 183 | narrowing in effect. This way you will be certain that none of | ||
| 184 | the remaining prompts will be accidentally messed up. You may | ||
| 185 | wish to put something like the following in your `.emacs' file: | ||
| 186 | |||
| 187 | \(add-hook 'comint-mode-hook | ||
| 188 | '(lambda () | ||
| 189 | (define-key comint-mode-map \"\C-w\" 'comint-kill-region) | ||
| 190 | (define-key comint-mode-map [C-S-backspace] | ||
| 191 | 'comint-kill-whole-line))) | ||
| 192 | |||
| 193 | If you sometimes use comint-mode on text-only terminals or with `emacs-nw', | ||
| 194 | you might wish to use another binding for `comint-kill-whole-line'." | ||
| 178 | :type 'boolean | 195 | :type 'boolean |
| 179 | :group 'comint | 196 | :group 'comint |
| 180 | :version "21.4") | 197 | :version "21.4") |
| @@ -2311,6 +2328,83 @@ This command is like `M-.' in bash." | |||
| 2311 | (just-one-space))) | 2328 | (just-one-space))) |
| 2312 | 2329 | ||
| 2313 | 2330 | ||
| 2331 | ;; Support editing with `comint-prompt-read-only' set to t. | ||
| 2332 | |||
| 2333 | (defun comint-update-fence () | ||
| 2334 | "Update read-only status of newline before point. | ||
| 2335 | The `fence' read-only property is used to indicate that a newline | ||
| 2336 | is read-only for no other reason than to \"fence off\" a | ||
| 2337 | following front-sticky read-only region. This is used to | ||
| 2338 | implement comint read-only prompts. If the text after a newline | ||
| 2339 | changes, the read-only status of that newline may need updating. | ||
| 2340 | That is what this function does. | ||
| 2341 | |||
| 2342 | This function does nothing if point is not at the beginning of a | ||
| 2343 | line, or is at the beginning of the accessible portion of the buffer. | ||
| 2344 | Otherwise, if the character after point has a front-sticky | ||
| 2345 | read-only property, then the preceding newline is given a | ||
| 2346 | read-only property of `fence', unless it already is read-only. | ||
| 2347 | If the character after point does not have a front-sticky | ||
| 2348 | read-only property, any read-only property of `fence' on the | ||
| 2349 | preceding newline is removed." | ||
| 2350 | (let* ((pt (point)) (lst (get-text-property pt 'front-sticky))) | ||
| 2351 | (and (bolp) | ||
| 2352 | (not (bobp)) | ||
| 2353 | (if (and (get-text-property pt 'read-only) | ||
| 2354 | (if (listp lst) (memq 'read-only lst) t)) | ||
| 2355 | (unless (get-text-property (1- pt) 'read-only) | ||
| 2356 | (put-text-property (1- pt) pt 'read-only 'fence)) | ||
| 2357 | (when (eq (get-text-property (1- pt) 'read-only) 'fence) | ||
| 2358 | (remove-list-of-text-properties (1- pt) pt '(read-only))))))) | ||
| 2359 | |||
| 2360 | (defun comint-kill-whole-line (&optional arg) | ||
| 2361 | "Kill current line, ignoring read-only and field properties. | ||
| 2362 | With prefix arg, kill that many lines starting from the current line. | ||
| 2363 | If arg is negative, kill backward. Also kill the preceding newline, | ||
| 2364 | instead of the trailing one. \(This is meant to make C-x z work well | ||
| 2365 | with negative arguments.) | ||
| 2366 | If arg is zero, kill current line but exclude the trailing newline. | ||
| 2367 | The read-only status of newlines is updated with `comint-update-fence', | ||
| 2368 | if necessary." | ||
| 2369 | (interactive "p") | ||
| 2370 | (let ((inhibit-read-only t) (inhibit-field-text-motion t)) | ||
| 2371 | (kill-whole-line arg) | ||
| 2372 | (when (>= arg 0) (comint-update-fence)))) | ||
| 2373 | |||
| 2374 | (defun comint-kill-region (beg end &optional yank-handler) | ||
| 2375 | "Like `kill-region', but ignores read-only properties, if safe. | ||
| 2376 | This command assumes that the buffer contains read-only | ||
| 2377 | \"prompts\" which are regions with front-sticky read-only | ||
| 2378 | properties at the beginning of a line, with the preceding newline | ||
| 2379 | being read-only to protect the prompt. This is true of the | ||
| 2380 | comint prompts if `comint-prompt-read-only' is non-nil. This | ||
| 2381 | command will not delete the region if this would create mutilated | ||
| 2382 | or out of place prompts. That is, if any part of a prompt is | ||
| 2383 | deleted, the entire prompt must be deleted and all remaining | ||
| 2384 | prompts should stay at the beginning of a line. If this is not | ||
| 2385 | the case, this command just calls `kill-region' with all | ||
| 2386 | read-only properties intact. The read-only status of newlines is | ||
| 2387 | updated using `comint-update-fence', if necessary." | ||
| 2388 | (interactive "r") | ||
| 2389 | (save-excursion | ||
| 2390 | (let* ((true-beg (min beg end)) | ||
| 2391 | (true-end (max beg end)) | ||
| 2392 | (beg-bolp (progn (goto-char true-beg) (bolp))) | ||
| 2393 | (beg-lst (get-text-property true-beg 'front-sticky)) | ||
| 2394 | (beg-bad (and (get-text-property true-beg 'read-only) | ||
| 2395 | (if (listp beg-lst) (memq 'read-only beg-lst) t))) | ||
| 2396 | (end-bolp (progn (goto-char true-end) (bolp))) | ||
| 2397 | (end-lst (get-text-property true-end 'front-sticky)) | ||
| 2398 | (end-bad (and (get-text-property true-end 'read-only) | ||
| 2399 | (if (listp end-lst) (memq 'read-only end-lst) t)))) | ||
| 2400 | (if (or (and (not beg-bolp) (or beg-bad end-bad)) | ||
| 2401 | (and (not end-bolp) end-bad)) | ||
| 2402 | (kill-region beg end yank-handler) | ||
| 2403 | (let ((inhibit-read-only t)) | ||
| 2404 | (kill-region beg end yank-handler) | ||
| 2405 | (comint-update-fence)))))) | ||
| 2406 | |||
| 2407 | |||
| 2314 | ;; Support for source-file processing commands. | 2408 | ;; Support for source-file processing commands. |
| 2315 | ;;============================================================================ | 2409 | ;;============================================================================ |
| 2316 | ;; Many command-interpreters (e.g., Lisp, Scheme, Soar) have | 2410 | ;; Many command-interpreters (e.g., Lisp, Scheme, Soar) have |