diff options
| author | Boris Goldowsky | 1995-02-23 18:34:22 +0000 |
|---|---|---|
| committer | Boris Goldowsky | 1995-02-23 18:34:22 +0000 |
| commit | 34c3f2b8d9037d24d2f0af21926f8b478f7d9702 (patch) | |
| tree | 4fd6257211d9120d5bb0e003711f325452c803d2 | |
| parent | 1095bc3caa984f840eea3d025e877813892b9892 (diff) | |
| download | emacs-34c3f2b8d9037d24d2f0af21926f8b478f7d9702.tar.gz emacs-34c3f2b8d9037d24d2f0af21926f8b478f7d9702.zip | |
(current-left-margin): careful of EOB.
(move-to-left-margin): Never move past left-margin, even in funny
justify modes.
(set-left-margin): include following whitespace.
(set-left-margin, increase-left-margin): indent rigidly.
(increase-left-margin): allow negative left-margins
(increase-right-margin): allow negative right-margin
(beginning-of-line-text): new fn.
| -rw-r--r-- | lisp/indent.el | 106 |
1 files changed, 66 insertions, 40 deletions
diff --git a/lisp/indent.el b/lisp/indent.el index 131a5a48628..d1777c8681a 100644 --- a/lisp/indent.el +++ b/lisp/indent.el | |||
| @@ -81,9 +81,8 @@ only if necessary. It leaves point at end of indentation." | |||
| 81 | (let ((bol (point)) | 81 | (let ((bol (point)) |
| 82 | (cur-col (current-indentation))) | 82 | (cur-col (current-indentation))) |
| 83 | (cond ((> cur-col column) ; too far right (after tab?) | 83 | (cond ((> cur-col column) ; too far right (after tab?) |
| 84 | (let ((beg (progn (move-to-column column t) (point)))) | 84 | (delete-region (progn (move-to-column column t) (point)) |
| 85 | (back-to-indentation) | 85 | (progn (back-to-indentation) (point)))) |
| 86 | (delete-region beg (point)))) | ||
| 87 | ((< cur-col column) | 86 | ((< cur-col column) |
| 88 | (back-to-indentation) | 87 | (back-to-indentation) |
| 89 | (indent-to column))))) | 88 | (indent-to column))))) |
| @@ -95,49 +94,49 @@ of the `left-margin' text-property at the start of the line." | |||
| 95 | (save-excursion | 94 | (save-excursion |
| 96 | (back-to-indentation) | 95 | (back-to-indentation) |
| 97 | (max 0 | 96 | (max 0 |
| 98 | (+ left-margin (or (get-text-property (point) 'left-margin) 0))))) | 97 | (+ left-margin (or (get-text-property |
| 98 | (if (and (eobp) (not (bobp))) | ||
| 99 | (1- (point)) (point)) | ||
| 100 | 'left-margin) 0))))) | ||
| 99 | 101 | ||
| 100 | (defun move-to-left-margin (&optional n) | 102 | (defun move-to-left-margin (&optional n force) |
| 101 | "Move to the left margin of the current line. | 103 | "Move to the left margin of the current line. |
| 102 | With optional argument, move forward N-1 lines first. | 104 | With optional argument, move forward N-1 lines first. |
| 103 | The column moved to is the one given by the `left-margin' function, or the | 105 | The column moved to is the one given by the `current-left-margin' function. |
| 104 | column where text actually starts if the region is centered or right-justified. | 106 | If the line's indentation appears to be wrong, and this command is called |
| 105 | When called interactively, this function corrects the line's indentation | 107 | interactively or with optional argument FORCE, it will be fixed." |
| 106 | if it appears to be incorrect. | 108 | (interactive (list (prefix-numeric-value current-prefix-arg) t)) |
| 107 | When called noninteractively, however, it just moves to the beginning of | ||
| 108 | the text in this case." | ||
| 109 | (interactive "p") | ||
| 110 | (beginning-of-line n) | 109 | (beginning-of-line n) |
| 111 | (skip-chars-forward " \t") | 110 | (let ((lm (current-left-margin))) |
| 112 | (if (not (memq (current-justification) '(right center))) | 111 | (if (memq (current-justification) '(right center)) |
| 113 | (let ((cc (current-column)) | 112 | (move-to-column lm) |
| 114 | (lm (current-left-margin))) | 113 | (skip-chars-forward " \t")) |
| 115 | (cond ((> cc lm) | 114 | (let ((cc (current-column))) |
| 116 | (move-to-column lm t)) | 115 | (cond ((> cc lm) |
| 117 | ((and (< cc lm) (interactive-p)) | 116 | (if (> (move-to-column lm force) lm) |
| 118 | (indent-to-left-margin)))))) | 117 | ;; If lm is in a tab and we are not forcing, move before tab |
| 118 | (backward-char 1))) | ||
| 119 | ((and force (< cc lm)) | ||
| 120 | (indent-to-left-margin)))))) | ||
| 119 | 121 | ||
| 120 | ;; This is the default indent-line-function, | 122 | ;; This is the default indent-line-function, |
| 121 | ;; used in Fundamental Mode, Text Mode, etc. | 123 | ;; used in Fundamental Mode, Text Mode, etc. |
| 122 | (defun indent-to-left-margin () | 124 | (defun indent-to-left-margin () |
| 123 | "Indent current line to `left-margin'." | 125 | "Indent current line to the column given by `current-left-margin'." |
| 124 | (indent-line-to (current-left-margin))) | 126 | (indent-line-to (current-left-margin))) |
| 125 | 127 | ||
| 126 | (defun delete-to-left-margin (from to) | 128 | (defun delete-to-left-margin (&optional from to) |
| 127 | "Remove left-margin indentation from region. | 129 | "Remove left margin indentation from a region. |
| 128 | This is careful only to delete whitespace, and not to delete any more than | 130 | This deletes to the column given by `current-left-margin'. |
| 129 | the \(current-left-margin) value for each line." | 131 | In no case will it delete non-whitespace. |
| 132 | Args FROM and TO are optional; default is the whole buffer." | ||
| 130 | (save-excursion | 133 | (save-excursion |
| 131 | (goto-char to) | 134 | (goto-char (or to (point-max))) |
| 132 | (setq to (point-marker)) | 135 | (setq to (point-marker)) |
| 133 | (goto-char from) | 136 | (goto-char (or from (point-min))) |
| 134 | (or (bolp) (forward-line 1)) | 137 | (or (bolp) (forward-line 1)) |
| 135 | (while (< (point) to) | 138 | (while (< (point) to) |
| 136 | (delete-region (point) (let ((lm (current-left-margin))) | 139 | (delete-region (point) (progn (move-to-left-margin nil t) (point))) |
| 137 | (skip-chars-forward " \t") | ||
| 138 | (if (> (current-column) lm) | ||
| 139 | (move-to-column lm)) | ||
| 140 | (point))) | ||
| 141 | (forward-line 1)) | 140 | (forward-line 1)) |
| 142 | (move-marker to nil))) | 141 | (move-marker to nil))) |
| 143 | 142 | ||
| @@ -151,12 +150,15 @@ If `auto-fill-mode' is active, re-fill the region to fit the new margin." | |||
| 151 | (goto-char from) | 150 | (goto-char from) |
| 152 | (skip-chars-backward " \t") | 151 | (skip-chars-backward " \t") |
| 153 | (if (bolp) (setq from (point))) | 152 | (if (bolp) (setq from (point))) |
| 153 | ;; Place end after whitespace | ||
| 154 | (goto-char to) | 154 | (goto-char to) |
| 155 | (skip-chars-forward " \t") | ||
| 155 | (setq to (point-marker))) | 156 | (setq to (point-marker))) |
| 156 | ;; Delete indentation first, so that paragraph indentation is preserved. | 157 | ;; Delete margin indentation first, but keep paragraph indentation. |
| 157 | (if auto-fill-function (delete-to-left-margin from to)) | 158 | (delete-to-left-margin from to) |
| 158 | (put-text-property from to 'left-margin lm) | 159 | (put-text-property from to 'left-margin lm) |
| 159 | (if auto-fill-function (fill-region from to nil t t)) | 160 | (indent-rigidly from to lm) |
| 161 | (if auto-fill-function (save-excursion (fill-region from to nil t t))) | ||
| 160 | (move-marker to nil)) | 162 | (move-marker to nil)) |
| 161 | 163 | ||
| 162 | (defun set-right-margin (from to lm) | 164 | (defun set-right-margin (from to lm) |
| @@ -169,7 +171,7 @@ If `auto-fill-mode' is active, re-fill the region to fit the new margin." | |||
| 169 | (skip-chars-backward " \t") | 171 | (skip-chars-backward " \t") |
| 170 | (if (bolp) (setq from (point)))) | 172 | (if (bolp) (setq from (point)))) |
| 171 | (put-text-property from to 'right-margin lm) | 173 | (put-text-property from to 'right-margin lm) |
| 172 | (if auto-fill-function (fill-region from to nil t t))) | 174 | (if auto-fill-function (save-excursion (fill-region from to nil t t)))) |
| 173 | 175 | ||
| 174 | (defun alter-text-property (from to prop func &optional object) | 176 | (defun alter-text-property (from to prop func &optional object) |
| 175 | "Programmatically change value of a text-property. | 177 | "Programmatically change value of a text-property. |
| @@ -199,10 +201,10 @@ If `auto-fill-mode' is active, re-fill the region to fit the new margin." | |||
| 199 | (if (bolp) (setq from (point))) | 201 | (if (bolp) (setq from (point))) |
| 200 | (goto-char to) | 202 | (goto-char to) |
| 201 | (setq to (point-marker))) | 203 | (setq to (point-marker))) |
| 202 | (if auto-fill-function (delete-to-left-margin from to)) | ||
| 203 | (alter-text-property from to 'left-margin | 204 | (alter-text-property from to 'left-margin |
| 204 | (lambda (v) (max 0 (+ inc (or v 0))))) | 205 | (lambda (v) (max (- left-margin) (+ inc (or v 0))))) |
| 205 | (if auto-fill-function (fill-region from to nil t t)) | 206 | (indent-rigidly from to inc) |
| 207 | (if auto-fill-function (save-excursion (fill-region from to nil t t))) | ||
| 206 | (move-marker to nil)) | 208 | (move-marker to nil)) |
| 207 | 209 | ||
| 208 | (defun decrease-left-margin (from to inc) | 210 | (defun decrease-left-margin (from to inc) |
| @@ -228,7 +230,7 @@ If `auto-fill-mode' is active, re-fill the region to fit the new margin." | |||
| 228 | standard-indent))) | 230 | standard-indent))) |
| 229 | (save-excursion | 231 | (save-excursion |
| 230 | (alter-text-property from to 'right-margin | 232 | (alter-text-property from to 'right-margin |
| 231 | (lambda (v) (max 0 (+ inc (or v 0))))) | 233 | (lambda (v) (+ inc (or v 0)))) |
| 232 | (if auto-fill-function | 234 | (if auto-fill-function |
| 233 | (fill-region from to nil t t)))) | 235 | (fill-region from to nil t t)))) |
| 234 | 236 | ||
| @@ -243,6 +245,30 @@ If `auto-fill-mode' is active, re-fills region to fit in new margin." | |||
| 243 | (setq inc (if inc (prefix-numeric-value inc) standard-indent)) | 245 | (setq inc (if inc (prefix-numeric-value inc) standard-indent)) |
| 244 | (increase-right-margin from to (- inc))) | 246 | (increase-right-margin from to (- inc))) |
| 245 | 247 | ||
| 248 | (defun beginning-of-line-text (&optional n) | ||
| 249 | "Move to the beginning of the text on this line. | ||
| 250 | With optional argument, move forward N-1 lines first. | ||
| 251 | From the beginning of the line, moves past the left-margin indentation, the | ||
| 252 | fill-prefix, and any indentation used for centering or right-justifying the | ||
| 253 | line, but does not move past any whitespace that was explicitly inserted | ||
| 254 | \(such as a tab used to indent the first line of a paragraph)." | ||
| 255 | (interactive "p") | ||
| 256 | (beginning-of-line n) | ||
| 257 | (skip-chars-forward " \t") | ||
| 258 | ;; Skip over fill-prefix. | ||
| 259 | (if (and fill-prefix | ||
| 260 | (not (string-equal fill-prefix ""))) | ||
| 261 | (if (equal fill-prefix | ||
| 262 | (buffer-substring | ||
| 263 | (point) (min (point-max) (+ (length fill-prefix) (point))))) | ||
| 264 | (forward-char (length fill-prefix))) | ||
| 265 | (if (and adaptive-fill-mode | ||
| 266 | (looking-at adaptive-fill-regexp)) | ||
| 267 | (goto-char (match-end 0)))) | ||
| 268 | ;; Skip centering or flushright indentation | ||
| 269 | (if (memq (current-justification) '(center right)) | ||
| 270 | (skip-chars-forward " \t"))) | ||
| 271 | |||
| 246 | (defvar indent-region-function nil | 272 | (defvar indent-region-function nil |
| 247 | "Function which is short cut to indent region using indent-according-to-mode. | 273 | "Function which is short cut to indent region using indent-according-to-mode. |
| 248 | A value of nil means really run indent-according-to-mode on each line.") | 274 | A value of nil means really run indent-according-to-mode on each line.") |