From: Chris Hanson Date: Fri, 2 Jun 2000 00:43:25 +0000 (+0000) Subject: Change AUTO-FILL-BREAK so that it accepts a mark as an argument, and X-Git-Tag: 20090517-FFI~3638 X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=2967b155daa93bfb694be175b2767334dfb8f98b;p=mit-scheme.git Change AUTO-FILL-BREAK so that it accepts a mark as an argument, and returns a boolean indicating whether it broke the line. --- diff --git a/v7/src/edwin/basic.scm b/v7/src/edwin/basic.scm index 3b3e5bc21..9110a7a93 100644 --- a/v7/src/edwin/basic.scm +++ b/v7/src/edwin/basic.scm @@ -1,6 +1,6 @@ ;;; -*-Scheme-*- ;;; -;;; $Id: basic.scm,v 1.137 2000/02/29 01:34:38 cph Exp $ +;;; $Id: basic.scm,v 1.138 2000/06/02 00:43:25 cph Exp $ ;;; ;;; Copyright (c) 1986, 1989-2000 Massachusetts Institute of Technology ;;; @@ -51,7 +51,7 @@ Whichever character you type to run this command is inserted." (char=? #\newline char)) (current-minor-mode? (ref-mode-object auto-fill))) (let ((t (group-modified-tick (mark-group point)))) - (auto-fill-break) + (auto-fill-break (current-point)) (if (not (fix:= t (group-modified-tick (mark-group point)))) (set! hairy? #t)))) hairy?))) @@ -414,7 +414,7 @@ Otherwise, set the comment column to the argument." (current-column)))) (set-variable! comment-column column) (message "comment-column set to " column))))) - + (define-command indent-for-comment "Indent this line's comment to comment column, or insert an empty comment." () @@ -434,7 +434,7 @@ Otherwise, set the comment column to the argument." (begin (insert-string (ref-variable comment-start)) (insert-comment-end))))))))) - + (define-variable comment-multi-line "True means \\[indent-new-comment-line] should continue same comment on new line, with no new terminator or starter." @@ -445,30 +445,39 @@ on new line, with no new terminator or starter." "Break line at point and indent, continuing comment if presently within one." () (lambda () - (delete-horizontal-space) - (insert-newlines 1) + (indent-new-comment-line (current-point) (ref-variable fill-prefix)))) + +(define (indent-new-comment-line mark fill-prefix) + (let ((mark (mark-left-inserting-copy mark))) + (delete-horizontal-space mark) + (insert-newlines 1 mark) (let ((if-not-in-comment (lambda () - (if (ref-variable fill-prefix) - (insert-string (ref-variable fill-prefix)) - ((ref-command indent-according-to-mode)))))) - (if (ref-variable comment-locator-hook) - (let ((com ((ref-variable comment-locator-hook) - (line-start (current-point) -1)))) + (if fill-prefix + (insert-string fill-prefix mark) + (with-selected-buffer (mark-buffer mark) + (lambda () + (with-current-point mark + (ref-command indent-according-to-mode)))))))) + (if (ref-variable comment-locator-hook mark) + (let ((com ((ref-variable comment-locator-hook mark) + (line-start mark -1)))) (if com (let ((start-column (mark-column (car com))) (end-column (mark-column (cdr com))) (comment-start (extract-string (car com) (cdr com)))) - (if (ref-variable comment-multi-line) - (maybe-change-column end-column) - (begin (insert-string (ref-variable comment-end) - (line-end (current-point) -1)) - (maybe-change-column start-column) - (insert-string comment-start))) - (if (line-end? (current-point)) - (insert-comment-end))) + (if (ref-variable comment-multi-line mark) + (maybe-change-column end-column mark) + (begin + (insert-string (ref-variable comment-end mark) + (line-end mark -1)) + (maybe-change-column start-column mark) + (insert-string comment-start mark))) + (if (line-end? mark) + (insert-comment-end mark))) (if-not-in-comment))) - (if-not-in-comment))))) + (if-not-in-comment))) + (mark-temporary! mark))) (define (insert-comment-end) (let ((point (mark-right-inserting (current-point)))) diff --git a/v7/src/edwin/fill.scm b/v7/src/edwin/fill.scm index 7c2f36628..279719530 100644 --- a/v7/src/edwin/fill.scm +++ b/v7/src/edwin/fill.scm @@ -1,6 +1,6 @@ ;;; -*-Scheme-*- ;;; -;;; $Id: fill.scm,v 1.63 2000/03/02 05:37:06 cph Exp $ +;;; $Id: fill.scm,v 1.64 2000/06/02 00:42:32 cph Exp $ ;;; ;;; Copyright (c) 1986, 1989-2000 Massachusetts Institute of Technology ;;; @@ -148,14 +148,34 @@ Prefix arg means justify as well." (ref-variable fill-prefix start) (ref-variable fill-column start) justify?)))) - + (define-command justify-current-line "Add spaces to line point is in, so it ends at fill-column." "d" (lambda (point) (justify-line point - (mark-local-ref point (ref-variable-object fill-prefix)) - (mark-local-ref point (ref-variable-object fill-column))))) + (ref-variable fill-prefix point) + (ref-variable fill-column point)))) + +(define-command center-line + "Center the line point is on, within the width specified by `fill-column'. +This means adjusting the indentation to match +the distance between the end of the text and `fill-column'." + "d" + (lambda (mark) (center-line mark))) + +(define (center-line mark) + (let ((mark (mark-permanent! mark))) + (delete-horizontal-space (line-start mark 0)) + (delete-horizontal-space (line-end mark 0)) + (let ((d + (- (- (ref-variable fill-column mark) + (ref-variable left-margin mark)) + (mark-column (line-end mark 0))))) + (if (positive? d) + (insert-horizontal-space (+ (ref-variable left-margin mark) + (quotient d 2)) + (line-start mark 0)))))) (define (fill-region-as-paragraph start end fill-prefix fill-column justify?) (let ((start (mark-right-inserting-copy (skip-chars-forward "\n" start end))) @@ -466,58 +486,33 @@ With argument, turn auto-fill mode on iff argument is positive." (define-minor-mode auto-fill "Fill" "Minor mode in which lines are automatically wrapped when long enough.") -(define (auto-fill-break) - (let ((point (current-point))) - (if (auto-fill-break? point) - (let ((prefix - (or (and (not (ref-variable paragraph-ignore-fill-prefix point)) - (ref-variable fill-prefix point)) - (and (ref-variable adaptive-fill-mode point) - (fill-context-prefix (or (paragraph-text-start point) - (line-start point 0)) - (or (paragraph-text-end point) - (line-end point 0))))))) - (if (re-search-backward "[^ \t][ \t]+" +(define (auto-fill-break point) + (and (auto-fill-break? point) + (let ((prefix + (or (and (not + (ref-variable paragraph-ignore-fill-prefix point)) + (ref-variable fill-prefix point)) + (and (ref-variable adaptive-fill-mode point) + (fill-context-prefix (or (paragraph-text-start point) + (line-start point 0)) + (or (paragraph-text-end point) + (line-end point 0))))))) + (and (re-search-backward "[^ \t][ \t]+" (move-to-column point (+ (ref-variable fill-column) 1)) (line-start point 0)) (let ((break (re-match-end 0))) - (if (let ((pe - (and prefix - (mark+ (line-start point 0) - (string-length prefix) - #f)))) - (or (not pe) - (mark> break pe))) - (with-fill-prefix prefix - (lambda () - (with-current-point break - (ref-command indent-new-comment-line))))))))))) - -(define (with-fill-prefix prefix thunk) - (with-variable-value! (ref-variable-object paragraph-ignore-fill-prefix) #f - (lambda () - (with-variable-value! (ref-variable-object fill-prefix) prefix - thunk)))) + (and (let ((pe + (and prefix + (mark+ (line-start point 0) + (string-length prefix) + #f)))) + (or (not pe) + (mark> break pe))) + (begin + (indent-new-comment-line break prefix) + #t))))))) (define (auto-fill-break? point) - (> (mark-column point) (ref-variable fill-column))) - -(define (center-line mark) - (let ((mark (mark-permanent! mark))) - (delete-horizontal-space (line-start mark 0)) - (delete-horizontal-space (line-end mark 0)) - (let ((d (- (- (ref-variable fill-column) (ref-variable left-margin)) - (mark-column (line-end mark 0))))) - (if (positive? d) - (insert-horizontal-space (+ (ref-variable left-margin) - (quotient d 2)) - (line-start mark 0)))))) - -(define-command center-line - "Center the line point is on, within the width specified by `fill-column'. -This means adjusting the indentation to match -the distance between the end of the text and `fill-column'." - "d" - center-line) \ No newline at end of file + (> (mark-column point) (ref-variable fill-column))) \ No newline at end of file