Redefine auto-fill minor mode so that it has no effect if the commands
authorChris Hanson <org/chris-hanson/cph>
Thu, 14 May 1992 18:38:58 +0000 (18:38 +0000)
committerChris Hanson <org/chris-hanson/cph>
Thu, 14 May 1992 18:38:58 +0000 (18:38 +0000)
being overridden are not the expected ones.

v7/src/edwin/comred.scm
v7/src/edwin/fill.scm

index 0726907b9ed371e7679ef3edb3b61efc7ed81cd6..871bd90e3bf4163391c08e6630da3875a5483409 100644 (file)
@@ -1,6 +1,6 @@
 ;;; -*-Scheme-*-
 ;;;
-;;;    $Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/edwin/comred.scm,v 1.93 1992/04/08 17:57:38 cph Exp $
+;;;    $Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/edwin/comred.scm,v 1.94 1992/05/14 18:38:58 cph Exp $
 ;;;
 ;;;    Copyright (c) 1986, 1989-92 Massachusetts Institute of Technology
 ;;;
             (normal))
            ((and (char? *command-key*)
                  (or (eq? command (ref-command-object self-insert-command))
-                     (and (eq? command (ref-command-object auto-fill-space))
+                     (and (eq? command (ref-command-object &auto-fill-space))
                           (not (auto-fill-break? point)))
                      (command-argument-self-insert? command)))
             (let ((key *command-key*))
index 531c3652c8b2437ffa4a744daa39b3a662de9e7a..de74fbb83e9ef60dbb378263f1906cc7bea90179 100644 (file)
@@ -1,6 +1,6 @@
 ;;; -*-Scheme-*-
 ;;;
-;;;    $Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/edwin/fill.scm,v 1.53 1992/02/04 03:42:15 cph Exp $
+;;;    $Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/edwin/fill.scm,v 1.54 1992/05/14 18:38:50 cph Exp $
 ;;;
 ;;;    Copyright (c) 1986, 1989-92 Massachusetts Institute of Technology
 ;;;
@@ -349,23 +349,46 @@ With argument, turn auto-fill mode on iff argument is positive."
                  (current-minor-mode? mode))
             (disable-current-minor-mode! mode))))))
 
-(define-command auto-fill-space
+(define-command &auto-fill-space
   "Breaks the line if it exceeds the fill column, then inserts a space."
   "p"
   (lambda (argument)
-    (insert-chars #\space argument)
-    (auto-fill-break)))
+    (conditionally-override-key
+     (ref-command-object self-insert-command)
+     (lambda ()
+       (insert-chars #\space argument)
+       (auto-fill-break)))))
 
-(define-command auto-fill-newline
+(define-command &auto-fill-newline
   "Breaks the line if it exceeds the fill column, then inserts a newline."
   "P"
   (lambda (argument)
-    (auto-fill-break)
-    ((ref-command newline) argument)))
+    (conditionally-override-key
+     (ref-command-object newline)
+     (lambda ()
+       (auto-fill-break)
+       ((ref-command newline) argument)))))
+
+(define (conditionally-override-key override-command action)
+  ;; This looks at the context in which the auto-fill commands are
+  ;; invoked, and performs the auto-fill action only when the context
+  ;; is the expected one.
+  (let ((comtabs (current-comtabs))
+       (key (current-command-key)))
+    (let ((tail
+          (memq (minor-mode-comtab (ref-mode-object auto-fill)) comtabs)))
+      (if (or (null? tail)
+             (null? (cdr tail)))
+         (dispatch-on-key comtabs key)
+         (let ((command (comtab-entry (cdr tail) key)))
+           (if (or (eq? command override-command)
+                   (eq? command (ref-command-object undefined)))
+               (action)
+               (dispatch-on-command command)))))))
 
 (define-minor-mode auto-fill "Fill" "")
-(define-key 'auto-fill #\space 'auto-fill-space)
-(define-key 'auto-fill #\return 'auto-fill-newline)
+(define-key 'auto-fill #\space '&auto-fill-space)
+(define-key 'auto-fill #\return '&auto-fill-newline)
 
 (define (auto-fill-break)
   (let ((point (current-point)))
@@ -381,7 +404,7 @@ With argument, turn auto-fill mode on iff argument is positive."
 (define (auto-fill-break? point)
   (and (> (mark-column point) (ref-variable fill-column))
        (line-end? (horizontal-space-end point))))
-
+\f
 (define-variable-per-buffer left-margin
   "Column for the default indent-line-function to indent to.
 Linefeed indents to this column in Fundamental mode.