From 090ce14817083789f1dc69524c347c003d61abc5 Mon Sep 17 00:00:00 2001 From: Chris Hanson Date: Fri, 25 Feb 2000 14:20:56 +0000 Subject: [PATCH] Integrate auto-fill and abbrev into M-x self-insert, as in Emacs. --- v7/src/edwin/basic.scm | 32 ++++++++++++++++++------- v7/src/edwin/fill.scm | 52 +++++------------------------------------ v7/src/edwin/lincom.scm | 9 ++++--- 3 files changed, 36 insertions(+), 57 deletions(-) diff --git a/v7/src/edwin/basic.scm b/v7/src/edwin/basic.scm index 47b0b3356..9072169a5 100644 --- a/v7/src/edwin/basic.scm +++ b/v7/src/edwin/basic.scm @@ -1,8 +1,8 @@ ;;; -*-Scheme-*- ;;; -;;; $Id: basic.scm,v 1.132 1999/01/28 06:03:18 cph Exp $ +;;; $Id: basic.scm,v 1.133 2000/02/25 14:20:56 cph Exp $ ;;; -;;; Copyright (c) 1986, 1989-1999 Massachusetts Institute of Technology +;;; Copyright (c) 1986, 1989-2000 Massachusetts Institute of Technology ;;; ;;; This program is free software; you can redistribute it and/or ;;; modify it under the terms of the GNU General Public License as @@ -23,12 +23,28 @@ (declare (usual-integrations)) (define-command self-insert-command - "Insert the character used to invoke this. -With an argument, insert the character that many times." - "P" - (lambda (argument) - (insert-chars (last-command-key) - (command-argument-numeric-value argument)))) + "Insert the character you type. +Whichever character you type to run this command is inserted." + "p" + (lambda (n) + (let ((char (last-command-key))) + (if (not (char? char)) + (editor-error "self-insert-command only works on character keys.")) + (self-insert char n #t)))) + +(define (self-insert char n allow-auto-fill?) + (if (> n 0) + (begin + (if (and (current-minor-mode? (ref-mode-object abbrev)) + (not (char=? #\w (char-syntax char))) + (buffer-writable? (selected-buffer)) + (eqv? #\w (char-syntax (extract-left-char)))) + ((ref-command expand-abbrev))) + (insert-chars char n) + (if (and (or (char=? #\space char) + (char=? #\newline char)) + (current-minor-mode? (ref-mode-object auto-fill))) + (auto-fill-break))))) (define (read-quoted-char prompt-string) (let ((read-ascii-char diff --git a/v7/src/edwin/fill.scm b/v7/src/edwin/fill.scm index fe007ea65..6629889a5 100644 --- a/v7/src/edwin/fill.scm +++ b/v7/src/edwin/fill.scm @@ -1,6 +1,6 @@ ;;; -*-Scheme-*- ;;; -;;; $Id: fill.scm,v 1.61 2000/02/23 17:37:03 cph Exp $ +;;; $Id: fill.scm,v 1.62 2000/02/25 14:20:32 cph Exp $ ;;; ;;; Copyright (c) 1986, 1989-2000 Massachusetts Institute of Technology ;;; @@ -315,6 +315,8 @@ Prefix arg means justify as well." (and (not (group-start? m)) (memv (extract-left-char m) '(#\. #\? #\!))))) +;;;; Auto Fill + (define-command auto-fill-mode "Toggle auto-fill mode. With argument, turn auto-fill mode on iff argument is positive." @@ -327,50 +329,8 @@ With argument, turn auto-fill mode on iff argument is positive." (enable-current-minor-mode! mode) (disable-current-minor-mode! mode))))) -(define-command &auto-fill-space - "Breaks the line if it exceeds the fill column, then inserts a space." - "p" - (lambda (argument) - (conditionally-override-key (ref-command-object &auto-fill-space) - (ref-command-object self-insert-command) - (lambda () - (insert-chars #\space argument) - (auto-fill-break))))) - -(define-command &auto-fill-newline - "Breaks the line if it exceeds the fill column, then inserts a newline." - "P" - (lambda (argument) - (conditionally-override-key (ref-command-object &auto-fill-newline) - (ref-command-object newline) - (lambda () - (auto-fill-break) - ((ref-command newline) argument))))) - -(define (conditionally-override-key overriding overridden 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 ((command - (local-comtab-entry - (let ((comtabs (current-comtabs))) - (let ((tail - (memq (minor-mode-comtab (ref-mode-object auto-fill)) - comtabs))) - (if (or (null? tail) (null? (cdr tail))) - comtabs - (cdr tail)))) - (current-command-key) - (current-point)))) - (if (or (eq? command overriding) - (eq? command overridden) - (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-minor-mode auto-fill "Fill" + "Minor mode in which lines are automatically wrapped when long enough.") (define (auto-fill-break) (let ((point (current-point))) @@ -378,7 +338,7 @@ With argument, turn auto-fill mode on iff argument is positive." (if (re-search-backward "[^ \t][ \t]+" (move-to-column point - (1+ (ref-variable fill-column))) + (+ (ref-variable fill-column) 1)) (line-start point 0)) (with-current-point (re-match-end 0) (ref-command indent-new-comment-line)))))) diff --git a/v7/src/edwin/lincom.scm b/v7/src/edwin/lincom.scm index fb26e5df0..56b45101d 100644 --- a/v7/src/edwin/lincom.scm +++ b/v7/src/edwin/lincom.scm @@ -1,8 +1,8 @@ ;;; -*-Scheme-*- ;;; -;;; $Id: lincom.scm,v 1.123 1999/01/02 06:11:34 cph Exp $ +;;; $Id: lincom.scm,v 1.124 2000/02/25 14:20:43 cph Exp $ ;;; -;;; Copyright (c) 1986, 1989-1999 Massachusetts Institute of Technology +;;; Copyright (c) 1986, 1989-2000 Massachusetts Institute of Technology ;;; ;;; This program is free software; you can redistribute it and/or ;;; modify it under the terms of the GNU General Public License as @@ -363,7 +363,10 @@ With argument COLUMN, indent each line to that column." "Insert a newline. With arg, insert that many newlines." "*P" (lambda (argument) - (insert-newlines (command-argument-numeric-value argument)))) + (self-insert #\newline + (command-argument-numeric-value argument) + ;; Don't do auto-fill if argument supplied. + (not argument)))) (define-command split-line "Move rest of this line vertically down. -- 2.25.1