From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: martin rudalics Newsgroups: gmane.emacs.devel Subject: Re: adaptive-fill-mode and auto-fill-mode Date: Mon, 09 Oct 2006 14:35:31 +0200 Message-ID: <452A4213.8080106@gmx.at> References: <4527F569.2030007@gmx.at> <4528D303.3080903@gmx.at> <45294B77.5030202@gmx.at> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------010804000508080904070305" X-Trace: sea.gmane.org 1160398285 31844 80.91.229.2 (9 Oct 2006 12:51:25 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 9 Oct 2006 12:51:25 +0000 (UTC) Cc: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Oct 09 14:51:10 2006 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1GWuV0-00030E-Aa for ged-emacs-devel@m.gmane.org; Mon, 09 Oct 2006 14:44:50 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GWuUz-0001Vo-JV for ged-emacs-devel@m.gmane.org; Mon, 09 Oct 2006 08:44:49 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1GWuUh-0001Sc-Gi for emacs-devel@gnu.org; Mon, 09 Oct 2006 08:44:31 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1GWuUc-0001Jc-CO for emacs-devel@gnu.org; Mon, 09 Oct 2006 08:44:30 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GWuUc-0001JQ-4x for emacs-devel@gnu.org; Mon, 09 Oct 2006 08:44:26 -0400 Original-Received: from [213.165.64.20] (helo=mail.gmx.net) by monty-python.gnu.org with smtp (Exim 4.52) id 1GWucA-0002hD-0t for emacs-devel@gnu.org; Mon, 09 Oct 2006 08:52:14 -0400 Original-Received: (qmail invoked by alias); 09 Oct 2006 12:44:22 -0000 Original-Received: from N809P007.adsl.highway.telekom.at (EHLO [62.47.45.7]) [62.47.45.7] by mail.gmx.net (mp037) with SMTP; 09 Oct 2006 14:44:22 +0200 X-Authenticated: #14592706 User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: de-DE, de, en-us, en Original-To: Stefan Monnier In-Reply-To: X-Y-GMX-Trusted: 0 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:60542 Archived-At: This is a multi-part message in MIME format. --------------010804000508080904070305 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit > Then how 'bout the 100% guaranteed untested > patch below. Neat. I attached a 50% unguaranteed tested revision. >>... but the string at compos is ";; >" ... > > > Not necessarily. I may compute this in adaptive-fill-function straight from > the first line, (when using auto-fill on the first line). ... no matter what you compute in `adaptive-fill-function' the string at compos is the string at compos is the ... >>... if compos is not at line beginning the prefix is rejected. > > > Where? Why? In my first patch. The current one doesn't reject it any more. >>I fail to understand you here. If the comment at compos doesn't match >>the prefix why should I want to insert the prefix on the next line? > > > Why not? Your own patch might impede you. If you manually change the comment-start sequence at compos or the whitespace preceding it, the prefix won't match the comment at compos any more and hence won't be used. >>>Have you tried >>>comment-auto-fill-only-comments? > > >>It doesn't fill doc-strings. > > > But maybe it's the right place to introduce such a feature. > Basically extend this var so you can say "fill in FOO" where FOO is the list > of possible contexts, such as `comment', `string', `doc', `code'? If someone is interested I'll write it. --------------010804000508080904070305 Content-Type: text/plain; name="auto-fill.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="auto-fill.patch" *** newcomment.el.~1.96.~ Mon Aug 21 14:35:24 2006 --- newcomment.el Mon Oct 9 11:23:40 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,1169 ---- :group 'comment) (defun comment-valid-prefix-p (prefix compos) ! "Check that the adaptive-fill-prefix is consistent with the context. ! PREFIX is the prefix (presumably guessed by `adaptive-fill-mode'). ! COMPOS is the position of the beginning of the comment we're in, or nil ! if we're not inside a comment." ! ;; This consistency checking is mostly needed to workaround the limitation ! ;; of auto-fill-mode whose paragraph-determination doesn't pay attention ! ;; to comment boundaries. ! (if (null compos) ! ;; We're not inside a comment: the prefix shouldn't match ! ;; a comment-starter. ! (not (and comment-start comment-start-skip ! (string-match comment-start-skip prefix))) ! (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 the same comment-start marker ! ;; as the current one. ! (when (string-match (concat "\\`[ \t]*\\(?:" comment-start-skip "\\)") ! prefix) ! (let ((prefix-com (comment-string-strip (match-string 0 prefix) nil t))) ! (string-match "\\`[ \t]*" prefix-com) ! (let* ((prefix-space (match-string 0 prefix-com)) ! (prefix-indent (string-width prefix-space)) ! (prefix-comstart (substring prefix-com (match-end 0)))) ! (save-excursion ! (goto-char compos) ! ;; The comstart marker is the same. ! (and (looking-at comment-start-skip) ! (string-equal ! prefix-comstart ! (comment-string-strip (match-string 0) nil t)) ! ;; The indentation as well. ! (or (= prefix-indent ! (- (current-column) (current-left-margin))) ! ;; Check the indentation in two different ways, just ! ;; to try and avoid most of the potential funny cases. ! (equal prefix-space ! (buffer-substring (point) ! (progn (move-to-left-margin) ! (point))))))))))))) ;;;###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. --- 1213,1220 ---- (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. --------------010804000508080904070305 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Emacs-devel mailing list Emacs-devel@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-devel --------------010804000508080904070305--