emacs-devel
[Top][All Lists]
Advanced

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

adaptive-fill-mode and auto-fill-mode


From: martin rudalics
Subject: adaptive-fill-mode and auto-fill-mode
Date: Sat, 07 Oct 2006 12:00:18 +0200

To reproduce with Emacs -Q insert the following text ...

(auto-fill-mode 1)
(setq fill-column 60)

;; x
;; x
(defun foo (from to)
  (yes-or-no-p (format "..... should we foo from %s to %s?" from to
                       ;; xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx yy
;;; xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx zz
                       )))

... in *scratch* and evaluate *scratch*.


(1) Typing SPC at the end of the `yes-or-no-p' line gets me

(defun foo (from to)
  (yes-or-no-p (format "..... should we foo from %s to %s?"
;; from to 
                       ;; xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx yy
;;; xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx zz
                       )))


(2) Typing SPC after yy breaks the comment as

(defun foo (from to)
  (yes-or-no-p (format "..... should we foo from %s to %s?" from to
                       ;; xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
;; yy 
;;; xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx zz
                       )))


(3) Typing SPC after zz breaks the comment as

(defun foo (from to)
  (yes-or-no-p (format "..... should we foo from %s to %s?" from to
                       ;; xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx yy
;;; xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
;; zz 
                       )))


(4) Changing the definition of foo to

(defun foo (from to)
  (yes-or-no-p (format "....... should we foo from %s to %s?" from to
                       ;; xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx yy
;;; xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx zz
                       )))

and typing SPC at the end of the `yes-or-no-p' line gets me

(defun foo (from to)
  (yes-or-no-p (format "....... should we foo from %s to
;; %s?" from to 
                       ;; xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx yy
;;; xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx zz
                       )))


The patch below is an attempt to resolve these problems with minimal
invasiveness (but for the removal of the `fill-nobreak-predicate' let
binding in `fill-move-to-break-point' which, IMHO, breaks the purpose of
`fill-nobreak-predicate' anyway).


*** textmodes/fill.el.~1.191.~  Fri Sep  8 18:07:28 2006
--- textmodes/fill.el   Fri Oct  6 19:42:22 2006
***************
*** 520,526 ****
        ;; Ok, skip at least one word or one \c| character.
        ;; Meanwhile, don't stop at a period followed by one space.
        (let ((to (line-end-position))
-           (fill-nobreak-predicate nil) ;to break sooner.
            (first t))
        (goto-char linebeg)
        (while (and (< (point) to) (or first (fill-nobreak-p)))
--- 520,525 ----


*** newcomment.el.~1.96.~       Mon Aug 21 14:35:24 2006
--- newcomment.el       Fri Oct  6 19:49:14 2006
***************
*** 1182,1187 ****
--- 1182,1202 ----
         ;; If there's an adaptive prefix, use it unless we're inside
         ;; a comment and the prefix is not a comment starter.
         ((and fill-prefix
+              ;; Don't use the adaptive prefix if we are not in a comment and
+              ;; the adaptive prefix matches `comment-start'.
+              (or compos (null comment-start)
+                  (not (string-match
+                        (regexp-quote comment-start) fill-prefix)))
+              ;; Don't use the adaptive prefix if we are in an end-of-line
+              ;; comment that doesn't start at the left margin or whose start
+              ;; sequence doesn't match the prefix.
+              (or (not compos) (not (string-equal comment-end ""))
+                  (and (<= compos
+                           (+ (line-beginning-position 0)
+                              (if (numberp left-margin) left-margin 0)))
+                       (save-excursion
+                         (goto-char compos)
+                         (looking-at (regexp-quote fill-prefix)))))
               (or (not compos)
                   (comment-valid-prefix-p fill-prefix compos)))
          (indent-to-left-margin)


*** emacs-lisp/lisp-mode.el.~1.194.~    Tue Aug 15 10:00:52 2006
--- emacs-lisp/lisp-mode.el     Fri Oct  6 12:21:32 2006
***************
*** 210,215 ****
--- 210,222 ----
    ;; because lisp-fill-paragraph should do the job.
    ;;  I believe that newcomment's auto-fill code properly deals with it  -stef
    ;;(set (make-local-variable 'adaptive-fill-mode) nil)
+   (set (make-local-variable 'fill-nobreak-predicate)
+        (lambda ()
+        (and (eq (get-text-property (point) 'face)
+                 'font-lock-string-face)
+             (or (= (point) (point-min))
+                 (eq (get-text-property (1- (point)) 'face)
+                     'font-lock-string-face)))))
    (make-local-variable 'indent-line-function)
    (setq indent-line-function 'lisp-indent-line)
    (make-local-variable 'indent-region-function)




reply via email to

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