unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* adaptive-fill-mode and auto-fill-mode
@ 2006-10-07 10:00 martin rudalics
  2006-10-07 16:22 ` Stefan Monnier
  0 siblings, 1 reply; 13+ messages in thread
From: martin rudalics @ 2006-10-07 10:00 UTC (permalink / raw)


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)

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2006-10-10  0:32 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-10-07 10:00 adaptive-fill-mode and auto-fill-mode martin rudalics
2006-10-07 16:22 ` Stefan Monnier
2006-10-07 18:43   ` martin rudalics
2006-10-08  4:29     ` Stefan Monnier
2006-10-08 10:29       ` martin rudalics
2006-10-08 16:21         ` Stefan Monnier
2006-10-08 19:03           ` martin rudalics
2006-10-09  1:37             ` Stefan Monnier
2006-10-09 12:35               ` martin rudalics
2006-10-09 16:45                 ` Stefan Monnier
2006-10-09 21:04                   ` martin rudalics
2006-10-10  0:32                     ` Stefan Monnier
2006-10-08  4:30     ` Stefan Monnier

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).