From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Christopher J. Madsen" Newsgroups: gmane.emacs.bugs Subject: bug#385: [PATCH] comment-indent doesn't respect comment-indent-function Date: 11 Jun 2008 17:11:02 -0000 Message-ID: <20080611171102.7261.qmail@byte.local> Reply-To: "Christopher J. Madsen" , 385@emacsbugs.donarmstrong.com NNTP-Posting-Host: lo.gmane.org X-Trace: ger.gmane.org 1213205252 22747 80.91.229.12 (11 Jun 2008 17:27:32 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 11 Jun 2008 17:27:32 +0000 (UTC) To: bug-gnu-emacs@gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Jun 11 19:28:14 2008 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1K6U7A-0000sc-H3 for geb-bug-gnu-emacs@m.gmane.org; Wed, 11 Jun 2008 19:28:04 +0200 Original-Received: from localhost ([127.0.0.1]:40257 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1K6U6M-0000BL-J3 for geb-bug-gnu-emacs@m.gmane.org; Wed, 11 Jun 2008 13:27:14 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1K6U6I-00009e-9Q for bug-gnu-emacs@gnu.org; Wed, 11 Jun 2008 13:27:10 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1K6U6H-00009O-FZ for bug-gnu-emacs@gnu.org; Wed, 11 Jun 2008 13:27:10 -0400 Original-Received: from [199.232.76.173] (port=50822 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1K6U6H-00009E-C8 for bug-gnu-emacs@gnu.org; Wed, 11 Jun 2008 13:27:09 -0400 Original-Received: from rzlab.ucr.edu ([138.23.92.77]:47284) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1K6U6H-0002qa-3I for bug-gnu-emacs@gnu.org; Wed, 11 Jun 2008 13:27:09 -0400 Original-Received: from rzlab.ucr.edu (rzlab.ucr.edu [127.0.0.1]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m5BHR7Fu003707; Wed, 11 Jun 2008 10:27:07 -0700 Original-Received: (from debbugs@localhost) by rzlab.ucr.edu (8.13.8/8.13.8/Submit) id m5BHK4wj001451; Wed, 11 Jun 2008 10:20:04 -0700 X-Loop: don@donarmstrong.com Resent-From: "Christopher J. Madsen" Resent-To: bug-submit-list@donarmstrong.com Resent-CC: Emacs Bugs Resent-Date: Wed, 11 Jun 2008 17:20:04 +0000 Resent-Message-ID: Resent-Sender: don@donarmstrong.com X-Emacs-PR-Message: report 385 X-Emacs-PR-Package: emacs X-Emacs-PR-Keywords: Original-Received: via spool by submit@emacsbugs.donarmstrong.com id=B.121320429132617 (code B ref -1); Wed, 11 Jun 2008 17:20:04 +0000 Original-Received: (at submit) by emacsbugs.donarmstrong.com; 11 Jun 2008 17:11:31 +0000 Original-Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m5BHBO6q032594 for ; Wed, 11 Jun 2008 10:11:25 -0700 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1K6Tr1-0003Ey-SJ for bug-gnu-emacs@gnu.org; Wed, 11 Jun 2008 13:11:23 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1K6Tqy-0003DT-Qk for bug-gnu-emacs@gnu.org; Wed, 11 Jun 2008 13:11:23 -0400 Original-Received: from [199.232.76.173] (port=34187 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1K6Tqy-0003DQ-Mh for bug-gnu-emacs@gnu.org; Wed, 11 Jun 2008 13:11:20 -0400 Original-Received: from a-sasl-quonix.sasl.smtp.pobox.com ([208.72.237.25]:47180 helo=sasl.smtp.pobox.com) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1K6Tqy-0007RT-Jf for bug-gnu-emacs@gnu.org; Wed, 11 Jun 2008 13:11:20 -0400 Original-Received: from localhost.localdomain (localhost [127.0.0.1]) by a-sasl-quonix.sasl.smtp.pobox.com (Postfix) with ESMTP id 9E08F24B9 for ; Wed, 11 Jun 2008 13:11:15 -0400 (EDT) Original-Received: from orthanc.cjmweb.net (cpe-24-175-86-179.tx.res.rr.com [24.175.86.179]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by a-sasl-quonix.sasl.smtp.pobox.com (Postfix) with ESMTPSA id 3B8DB24B8 for ; Wed, 11 Jun 2008 13:11:13 -0400 (EDT) Original-Received: (qmail 7262 invoked by uid 1000); 11 Jun 2008 17:11:02 -0000 X-Pobox-Relay-ID: 6665F4FE-37D9-11DD-910D-B8BFEAD4C077-09214675!a-sasl-quonix.pobox.com X-detected-kernel: by monty-python.gnu.org: Solaris 10 (beta) X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 3) Resent-Date: Wed, 11 Jun 2008 13:27:10 -0400 X-BeenThere: bug-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:18330 Archived-At: Please describe exactly what actions triggered the bug and the precise symptoms of the bug: It appears that comment-indent changed in 22.1. It gained some code to attempt to align the comment with those on surrounding lines. Unfortunately, this made it impossible to do certain things with comment-indent-function. For example, I had a custom indent function that placed comments immediately after a closing brace. However, in Emacs 22, I'd see this: while (1) { while (2) { } # end 2 <-- this comment placed correctly } # end 1 <-- this comment was aligned with the previous one instead of this: while (1) { while (2) { } # end 2 } # end 1 <-- here's where comment-indent-function placed it On the other hand, I do like the idea of automatically aligning comments. I had code in my custom indent functions to do that, but it would be nice if I didn't need to handle that in every indent function. I think what's needed is a way for comment-indent-function to distinguish between "Here's where the comment goes, and that's final" and "I suggest this position, but make it blend in with the neighborhood". Ideally, this would be backwards-compatible with older versions of Emacs. Here's a patch I came up with to provide that. If comment-indent-function sets comment-indent-fixed to non-nil, then the return value will be used as-is. Otherwise, it behaves like Emacs 22.2 did. Perhaps the sense should be reversed, and it should always respect the value of comment-indent-function unless told it's ok to adjust it. *** orig/newcomment.el Fri Mar 07 18:01:12 2008 --- new/newcomment.el Wed Jun 11 11:13:24 2008 *************** (defvar comment-indent-function 'comment *** 135,140 **** --- 135,143 ---- This function is called with no args with point at the beginning of the comment's starting delimiter and should return either the desired column indentation or nil. + The returned value may be adjusted by `comment-choose-indent'. + To prevent that, the function should set `comment-indent-fixed' + to a non-nil value. If nil is returned, indentation is delegated to `indent-according-to-mode'.") ;;;###autoload *************** (defun comment-indent (&optional continu *** 585,591 **** (beginning-of-line) (let* ((eolpos (line-end-position)) (begpos (comment-search-forward eolpos t)) ! cpos indent) ;; An existing comment? (if begpos (progn --- 588,594 ---- (beginning-of-line) (let* ((eolpos (line-end-position)) (begpos (comment-search-forward eolpos t)) ! cpos indent comment-indent-fixed) ;; An existing comment? (if begpos (progn *************** (defun comment-indent (&optional continu *** 622,636 **** (if (not indent) ;; comment-indent-function refuses: delegate to line-indent. (indent-according-to-mode) ! ;; If the comment is at the right of code, adjust the indentation. ! (unless (save-excursion (skip-chars-backward " \t") (bolp)) ! (setq indent (comment-choose-indent indent))) ! ;; Update INDENT to leave at least one space ! ;; after other nonwhite text on the line. ! (save-excursion ! (skip-chars-backward " \t") ! (unless (bolp) ! (setq indent (max indent (1+ (current-column)))))) ;; If that's different from comment's current position, change it. (unless (= (current-column) indent) (delete-region (point) (progn (skip-chars-backward " \t") (point))) --- 625,640 ---- (if (not indent) ;; comment-indent-function refuses: delegate to line-indent. (indent-according-to-mode) ! (unless comment-indent-fixed ! ;; If the comment is at the right of code, adjust the indentation. ! (unless (save-excursion (skip-chars-backward " \t") (bolp)) ! (setq indent (comment-choose-indent indent))) ! ;; Update INDENT to leave at least one space ! ;; after other nonwhite text on the line. ! (save-excursion ! (skip-chars-backward " \t") ! (unless (bolp) ! (setq indent (max indent (1+ (current-column))))))) ;; If that's different from comment's current position, change it. (unless (= (current-column) indent) (delete-region (point) (progn (skip-chars-backward " \t") (point))) In GNU Emacs 22.2.1 (i386-mingw-nt5.1.2600) of 2008-03-26 on RELEASE Windowing system distributor `Microsoft Corp.', version 5.1.2600 configured using `configure --with-gcc (3.4)' -- Chris Madsen cjm cjmweb.net -------------------- http://www.cjmweb.net --------------------