[gnu.emacs.help] gin-mode for GNU Emacs

ralph@laas.fr (Ralph P. Sobek) (12/06/90)

I have not looked into the problem of mis-specified REGEXPs.

But, I have patched gin-mode to properly indent paragraphs and I even
added gin-indent-region.  The problem with the original gin-mode is
that it uses the free (or special) variable `fill-prefix', and when
one gin-fill's a paragraph or a region it eventually calls
fill-paragraph or fill-region respectively.  When one gin-fill's one
wants to add the gin guessed prefix (gin-fill-prefix) to all lines in
the paragraph that do *not* already have it.

The problem is in paragraph.el: both forward-paragraph and backward
paragraph use fill-prefix in order to isolate the paragraph.  And
gin-mode has already assigned fill-prefix from its gin-fill-prefix.  I
would suggest that fill-prefix become an optional argument to all the
functions that use it rather than be a specail variable.  I do *not*
know if this might break some other code!!

In the mean time, here are the context diffs for gin-mode that work
for me.  Let me know if you have problems.  Basically, I just inserted
the source code for fill-paragraph and fill-region directly into
gin-mode. 

*** /usr/local/emacs/lisp/local/gin.el	Fri Nov  2 20:46:59 1990
--- gin.el	Mon Nov 12 15:46:44 1990
***************
*** 43,48 ****
--- 43,51 ----
  ;; 	* what line beginnings are really hanging indents.  The
  ;; 	  standard setup recognizes the stars used right here,
  ;; 	  enumerations, and some more...
+ 
+ ;; Change History:
+ ;; Nov 9, 1990 - Ralph P.Sobek - Added gin-fill-region.
  
  ;; The guessing stuff
  
***************
*** 98,107 ****
  With arg, also justify."
    (interactive "P")
    (if gin-mode
!       (let ((fill-prefix (gin-guess-prefix)))
! 	(funcall 'gin-old-fill-paragraph arg))
      (funcall 'gin-old-fill-paragraph arg)))
  
  (defun gin-do-auto-fill()
    (if gin-mode
        (let ((fill-prefix (gin-guess-prefix)))
--- 101,138 ----
  With arg, also justify."
    (interactive "P")
    (if gin-mode
!       (let ((gin-fill-prefix (gin-guess-prefix))
! 	    end)
! 	(save-excursion
! 	  (forward-paragraph)
! 	  (or (bolp) (newline 1))
! 	  (setq end (point))
! 	  (backward-paragraph)
! 	  (let ((fill-prefix gin-fill-prefix))
! 	    (fill-region-as-paragraph (point) end arg))))
      (funcall 'gin-old-fill-paragraph arg)))
  
+ (defun gin-fill-region (from to &optional justify-flag)
+   "fill-region in Gin mode, tries to guess the appropriate fill-prefix.
+ Prefix arg (non-nil third arg, if called from program)
+ means justify as well."
+   (interactive "r\nP")
+   (if gin-mode
+       (let ((gin-fill-prefix (gin-guess-prefix)))
+ 	(save-restriction
+ 	  (narrow-to-region from to)
+ 	  (goto-char (point-min))
+ 	  (while (not (eobp))
+ 	    (let* ((initial (point))
+ 		  (end (progn
+ 			 (forward-paragraph 1) (point)))
+ 		  (fill-prefix gin-fill-prefix))
+ 	      (forward-paragraph -1)
+ 	      (if (>= (point) initial)
+ 		  (fill-region-as-paragraph (point) end justify-flag))
+ 	      (goto-char end)))))
+     (funcall 'gin-old-fill-region from to justify-flag)))
+ 
  (defun gin-do-auto-fill()
    (if gin-mode
        (let ((fill-prefix (gin-guess-prefix)))
***************
*** 115,120 ****
--- 146,154 ----
  (defconst gin-old-fill-paragraph nil
    "Keeps the true fill-paragraph function during Gin mode.")
  
+ (defconst gin-old-fill-region nil
+   "Keeps the true fill-region function during Gin mode.")
+ 
  (defconst gin-old-do-auto-fill nil
    "Keeps the true do-auto-fill function during Gin mode.")
  
***************
*** 121,131 ****
--- 155,167 ----
  (defun gin-overlay-functions()
    "Undermine emacs with Gin stuff."
    (fset 'fill-paragraph (symbol-function 'gin-fill-paragraph))
+   (fset 'fill-region (symbol-function 'gin-fill-region))
    (fset 'do-auto-fill (symbol-function 'gin-do-auto-fill)))
  
  (defun gin-restore-originals ()
    "Throw gin-mode functions out everywhere."
    (fset 'fill-paragraph (symbol-function 'gin-old-fill-paragraph))
+   (fset 'fill-region (symbol-function 'gin-old-fill-region))
    (fset 'do-auto-fill (symbol-function 'gin-old-do-auto-fill)))
  
  (if (boundp 'gin-mode)
***************
*** 137,142 ****
--- 173,179 ----
    (make-variable-buffer-local 'gin-left-hang-indent-re)
    (make-variable-buffer-local 'gin-retain-indent-re)
    (fset 'gin-old-fill-paragraph (symbol-function 'fill-paragraph))
+   (fset 'gin-old-fill-region (symbol-function 'fill-region))
    (fset 'gin-old-do-auto-fill (symbol-function 'do-auto-fill))
    (gin-overlay-functions))
  
***************
*** 151,160 ****
  two regexps 'gin-left-hang-indent-re' and 'gin-retain-indent-re', see
  their documentation.
  
! When Gin mode is active, auto-filling and fill-paragraph will both use
! a \"guessed\" value as fill-prefix."
  
    (interactive "P")
    (setq gin-mode
  	(if (null arg) (not gin-mode)
  	  (> (prefix-numeric-value arg) 0)))
--- 188,197 ----
  two regexps 'gin-left-hang-indent-re' and 'gin-retain-indent-re', see
  their documentation.
  
! When Gin mode is active, auto-filling, fill-paragraph, and fill-region
! will both use a \"guessed\" value as fill-prefix."
  
    (interactive "P")
    (setq gin-mode
  	(if (null arg) (not gin-mode)
  	  (> (prefix-numeric-value arg) 0)))
--
Ralph P. Sobek			  Disclaimer: The above ruminations are my own.
ralph@laas.fr				   Addresses are ordered by importance.
ralph@laas.uucp, or ...!uunet!laas!ralph		
If all else fails, try:				      sobek@eclair.Berkeley.EDU
===============================================================================
Reliable software should kill people reliably! -Andy Mickel, Pascal News #13,78