bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

patch for make-mode.el


From: Tom Tromey
Subject: patch for make-mode.el
Date: 15 Sep 2002 18:39:20 -0600

Currently, make-mode will fill adjacent code when M-q is used in a
comment.  The appended patch fixes this by finding the boundaries of
the comment before filling.

Similar code already exists in tcl.el and lisp-mode.el, and recently I
added code like this to the (as yet unintegrated) python.el; it seems
like perhaps this should be a general feature of newcomment.el...?

This patch is against the cvs head.  I tested it in Emacs 21.2, but I
think it doesn't contain anything really version-dependent.

Tom

2002-09-15  Tom Tromey  <tromey@redhat.com>

        * progmodes/make-mode.el (makefile-fill-paragraph): Find comment
        boundaries before filling.

Index: lisp/progmodes/make-mode.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/progmodes/make-mode.el,v
retrieving revision 1.71
diff -u -r1.71 make-mode.el
--- lisp/progmodes/make-mode.el 28 Nov 2001 20:41:49 -0000      1.71
+++ lisp/progmodes/make-mode.el 16 Sep 2002 00:37:36 -0000
@@ -1,6 +1,6 @@
 ;;; make-mode.el --- makefile editing commands for Emacs
 
-;; Copyright (C) 1992,94,99,2000,2001  Free Software Foundation, Inc.
+;; Copyright (C) 1992,94,99,2000,2001, 2002  Free Software Foundation, Inc.
 
 ;; Author: Thomas Neumann <tom@smart.bo.open.de>
 ;;     Eric S. Raymond <esr@snark.thyrsus.com>
@@ -1011,12 +1011,30 @@
     (beginning-of-line)
     (cond
      ((looking-at "^#+ ")
-      ;; Found a comment.  Set the fill prefix and then fill.
+      ;; Found a comment.  Set the fill prefix, and find the paragraph
+      ;; boundaries by searching for lines that look like comment-only
+      ;; lines.
       (let ((fill-prefix (buffer-substring-no-properties (match-beginning 0)
                                                         (match-end 0)))
            (fill-paragraph-function nil))
-       (fill-paragraph nil)
-       t))
+       (save-excursion
+         (save-restriction
+           (narrow-to-region
+            ;; Search backwards.
+            (save-excursion
+              (while (and (zerop (forward-line -1))
+                          (looking-at "^#")))
+              ;; We may have gone too far.  Go forward again.
+              (or (looking-at "^#")
+                  (forward-line 1))
+              (point))
+            ;; Search forwards.
+            (save-excursion
+              (while (looking-at "^#")
+                (forward-line))
+              (point)))
+           (fill-paragraph nil)
+           t))))
 
      ;; Must look for backslashed-region before looking for variable
      ;; assignment.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]