unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: martin rudalics <rudalics@gmx.at>
Cc: emacs-devel@gnu.org
Subject: Re: adaptive-fill-mode and auto-fill-mode
Date: Sat, 07 Oct 2006 20:43:53 +0200	[thread overview]
Message-ID: <4527F569.2030007@gmx.at> (raw)
In-Reply-To: <jwv8xjsrtxv.fsf-monnier+emacs@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 564 bytes --]

> Why not use comment-start-skip instead?

OK

> I disagree with the "at left margin" thingy.  I'm not 100% sure what it's
> trying to fix, tho, so please explain which scenario it fixes.

I agree with your disagreement.

> As for the rest of the code above, please merge it with the two subsequent
> lines which already do something like that.  I.e. move the code to
> comment-valid-prefix-p.

Please look at the attached patch.

BTW is the fill.el change harmless?  In my opinion the `fill-nobreak-predicate'
stuff was broken.  Did anyone ever use that?

martin

[-- Attachment #2: auto-fill.patch --]
[-- Type: text/plain, Size: 4719 bytes --]

*** 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	Sat Oct  7 20:19:18 2006
***************
*** 238,244 ****
  (defcustom comment-empty-lines nil
    "If nil, `comment-region' does not comment out empty lines.
  If t, it always comments out empty lines.
! if `eol' it only comments out empty lines if comments are
  terminated by the end of line (i.e. `comment-end' is empty)."
    :type '(choice (const :tag "Never" nil)
  	  (const :tag "Always" t)
--- 238,244 ----
  (defcustom comment-empty-lines nil
    "If nil, `comment-region' does not comment out empty lines.
  If t, it always comments out empty lines.
! If `eol' it only comments out empty lines if comments are
  terminated by the end of line (i.e. `comment-end' is empty)."
    :type '(choice (const :tag "Never" nil)
  	  (const :tag "Always" t)
***************
*** 1124,1135 ****
    :group 'comment)

  (defun comment-valid-prefix-p (prefix compos)
!   (or
!    ;; Accept any prefix if the current comment is not EOL-terminated.
!    (save-excursion (goto-char compos) (comment-forward) (not (bolp)))
!    ;; Accept any prefix that starts with a comment-start marker.
!    (string-match (concat "\\`[ \t]*\\(?:" comment-start-skip "\\)")
! 		 prefix)))

  ;;;###autoload
  (defun comment-indent-new-line (&optional soft)
--- 1124,1152 ----
    :group 'comment)

  (defun comment-valid-prefix-p (prefix compos)
!   (if compos
!       (and
!        (or
! 	;; Accept any prefix if the current comment is not EOL-terminated.
! 	(save-excursion (goto-char compos) (comment-forward) (not (bolp)))
! 	;; Accept any prefix that starts with a comment-start marker.
! 	(string-match (concat "\\`[ \t]*\\(?:" comment-start-skip "\\)")
! 		      prefix))
!        ;; Don't accept a prefix in an end-of-line comment that doesn't start at
!        ;; line beginning or whose start sequence doesn't match the prefix.
!        ;; This should work around a bug where `do-auto-fill' determines the
!        ;; prefix from the beginning of the paragraph but doesn't pay attention
!        ;; to comments.
!        (or (not (string-equal comment-end ""))
! 	   (and (<= compos (line-beginning-position 0))
! 		(save-excursion
! 		  (goto-char compos)
! 		  (looking-at (regexp-quote prefix))))))
!     ;; Don't accept a prefix if we are not in a comment and the adaptive prefix
!     ;; matches `comment-start-skip'.  This should work around the `do-auto-fill'
!     ;; bug cited above which may cause code put inadvertently inside a comment.
!     (or (null comment-start)
! 	(not (string-match comment-start-skip prefix)))))

  ;;;###autoload
  (defun comment-indent-new-line (&optional soft)
***************
*** 1179,1189 ****
  	    (setq comin (point))))

  	(cond
! 	 ;; 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
! 	       (or (not compos)
! 		   (comment-valid-prefix-p fill-prefix compos)))
  	  (indent-to-left-margin)
  	  (insert-and-inherit fill-prefix))
  	 ;; If we're not inside a comment, just try to indent.
--- 1196,1203 ----
  	    (setq comin (point))))

  	(cond
! 	 ;; If there's an adaptive prefix, use it provided it's valid.
! 	 ((and fill-prefix (comment-valid-prefix-p fill-prefix compos))
  	  (indent-to-left-margin)
  	  (insert-and-inherit fill-prefix))
  	 ;; If we're not inside a comment, just try to indent.


*** emacs-lisp/lisp-mode.el.~1.194.~	Tue Aug 15 10:00:52 2006
--- emacs-lisp/lisp-mode.el	Sat Oct  7 20:30:42 2006
***************
*** 210,215 ****
--- 210,223 ----
    ;; 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)
+        ;; Try to avoid that auto-fill breaks strings.
+        (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)

[-- Attachment #3: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel

  reply	other threads:[~2006-10-07 18:43 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4527F569.2030007@gmx.at \
    --to=rudalics@gmx.at \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).