diff options
| author | Richard M. Stallman | 2005-01-15 18:07:21 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 2005-01-15 18:07:21 +0000 |
| commit | bdd5fa993233b9c57af2068bdbdd54a792d10981 (patch) | |
| tree | 095dd6ce42af523ead0d98a0466d43975b21eb07 | |
| parent | ad8f7f494f69b7705953475ba9cb68797a9172da (diff) | |
| download | emacs-bdd5fa993233b9c57af2068bdbdd54a792d10981.tar.gz emacs-bdd5fa993233b9c57af2068bdbdd54a792d10981.zip | |
(sh-mode-map): Bind C-c C-\.
(sh-backslash-column, sh-backslash-align): New variables.
(sh-backslash-region, sh-append-backslash): New functions.
| -rw-r--r-- | lisp/progmodes/sh-script.el | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/lisp/progmodes/sh-script.el b/lisp/progmodes/sh-script.el index bcabc505a49..019a19ed007 100644 --- a/lisp/progmodes/sh-script.el +++ b/lisp/progmodes/sh-script.el | |||
| @@ -448,6 +448,7 @@ This is buffer-local in every such buffer.") | |||
| 448 | (define-key map "\C-c=" 'sh-set-indent) | 448 | (define-key map "\C-c=" 'sh-set-indent) |
| 449 | (define-key map "\C-c<" 'sh-learn-line-indent) | 449 | (define-key map "\C-c<" 'sh-learn-line-indent) |
| 450 | (define-key map "\C-c>" 'sh-learn-buffer-indent) | 450 | (define-key map "\C-c>" 'sh-learn-buffer-indent) |
| 451 | (define-key map "\C-c\C-\\" 'sh-backslash-region) | ||
| 451 | 452 | ||
| 452 | (define-key map "=" 'sh-assignment) | 453 | (define-key map "=" 'sh-assignment) |
| 453 | (define-key map "\C-c+" 'sh-add) | 454 | (define-key map "\C-c+" 'sh-add) |
| @@ -1183,6 +1184,16 @@ This is for the rc shell." | |||
| 1183 | :type `(choice ,@ sh-number-or-symbol-list) | 1184 | :type `(choice ,@ sh-number-or-symbol-list) |
| 1184 | :group 'sh-indentation) | 1185 | :group 'sh-indentation) |
| 1185 | 1186 | ||
| 1187 | (defcustom sh-backslash-column 48 | ||
| 1188 | "*Column in which `sh-backslash-region' inserts backslashes." | ||
| 1189 | :type 'integer | ||
| 1190 | :group 'sh) | ||
| 1191 | |||
| 1192 | (defcustom sh-backslash-align t | ||
| 1193 | "*If non-nil, `sh-backslash-region' will align backslashes." | ||
| 1194 | :type 'boolean | ||
| 1195 | :group 'sh) | ||
| 1196 | |||
| 1186 | ;; Internal use - not designed to be changed by the user: | 1197 | ;; Internal use - not designed to be changed by the user: |
| 1187 | 1198 | ||
| 1188 | (defun sh-mkword-regexpr (word) | 1199 | (defun sh-mkword-regexpr (word) |
| @@ -3547,6 +3558,77 @@ The document is bounded by `sh-here-document-word'." | |||
| 3547 | (if (re-search-forward sh-end-of-command nil t) | 3558 | (if (re-search-forward sh-end-of-command nil t) |
| 3548 | (goto-char (match-end 1)))) | 3559 | (goto-char (match-end 1)))) |
| 3549 | 3560 | ||
| 3561 | ;; Backslashification. Stolen from make-mode.el. | ||
| 3562 | |||
| 3563 | (defun sh-backslash-region (from to delete-flag) | ||
| 3564 | "Insert, align, or delete end-of-line backslashes on the lines in the region. | ||
| 3565 | With no argument, inserts backslashes and aligns existing backslashes. | ||
| 3566 | With an argument, deletes the backslashes. | ||
| 3567 | |||
| 3568 | This function does not modify the last line of the region if the region ends | ||
| 3569 | right at the start of the following line; it does not modify blank lines | ||
| 3570 | at the start of the region. So you can put the region around an entire | ||
| 3571 | shell command and conveniently use this command." | ||
| 3572 | (interactive "r\nP") | ||
| 3573 | (save-excursion | ||
| 3574 | (goto-char from) | ||
| 3575 | (let ((column sh-backslash-column) | ||
| 3576 | (endmark (make-marker))) | ||
| 3577 | (move-marker endmark to) | ||
| 3578 | ;; Compute the smallest column number past the ends of all the lines. | ||
| 3579 | (if sh-backslash-align | ||
| 3580 | (progn | ||
| 3581 | (if (not delete-flag) | ||
| 3582 | (while (< (point) to) | ||
| 3583 | (end-of-line) | ||
| 3584 | (if (= (preceding-char) ?\\) | ||
| 3585 | (progn (forward-char -1) | ||
| 3586 | (skip-chars-backward " \t"))) | ||
| 3587 | (setq column (max column (1+ (current-column)))) | ||
| 3588 | (forward-line 1))) | ||
| 3589 | ;; Adjust upward to a tab column, if that doesn't push | ||
| 3590 | ;; past the margin. | ||
| 3591 | (if (> (% column tab-width) 0) | ||
| 3592 | (let ((adjusted (* (/ (+ column tab-width -1) tab-width) | ||
| 3593 | tab-width))) | ||
| 3594 | (if (< adjusted (window-width)) | ||
| 3595 | (setq column adjusted)))))) | ||
| 3596 | ;; Don't modify blank lines at start of region. | ||
| 3597 | (goto-char from) | ||
| 3598 | (while (and (< (point) endmark) (eolp)) | ||
| 3599 | (forward-line 1)) | ||
| 3600 | ;; Add or remove backslashes on all the lines. | ||
| 3601 | (while (and (< (point) endmark) | ||
| 3602 | ;; Don't backslashify the last line | ||
| 3603 | ;; if the region ends right at the start of the next line. | ||
| 3604 | (save-excursion | ||
| 3605 | (forward-line 1) | ||
| 3606 | (< (point) endmark))) | ||
| 3607 | (if (not delete-flag) | ||
| 3608 | (sh-append-backslash column) | ||
| 3609 | (sh-delete-backslash)) | ||
| 3610 | (forward-line 1)) | ||
| 3611 | (move-marker endmark nil)))) | ||
| 3612 | |||
| 3613 | (defun sh-append-backslash (column) | ||
| 3614 | (end-of-line) | ||
| 3615 | ;; Note that "\\\\" is needed to get one backslash. | ||
| 3616 | (if (= (preceding-char) ?\\) | ||
| 3617 | (progn (forward-char -1) | ||
| 3618 | (delete-horizontal-space) | ||
| 3619 | (indent-to column (if sh-backslash-align nil 1))) | ||
| 3620 | (indent-to column (if sh-backslash-align nil 1)) | ||
| 3621 | (insert "\\"))) | ||
| 3622 | |||
| 3623 | (defun sh-delete-backslash () | ||
| 3624 | (end-of-line) | ||
| 3625 | (or (bolp) | ||
| 3626 | (progn | ||
| 3627 | (forward-char -1) | ||
| 3628 | (if (looking-at "\\\\") | ||
| 3629 | (delete-region (1+ (point)) | ||
| 3630 | (progn (skip-chars-backward " \t") (point))))))) | ||
| 3631 | |||
| 3550 | (provide 'sh-script) | 3632 | (provide 'sh-script) |
| 3551 | 3633 | ||
| 3552 | ;;; arch-tag: eccd8b72-f337-4fc2-ae86-18155a69d937 | 3634 | ;;; arch-tag: eccd8b72-f337-4fc2-ae86-18155a69d937 |