From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.bugs Subject: bug#22369: 24.5; comment-style 'extra-line' doesn't correctly indent with tabs Date: 15 Jan 2016 11:56:28 -0000 Organization: muc.de e.V. Message-ID: <20160115115628.56863.qmail@mail.muc.de> References: NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1452859042 32094 80.91.229.3 (15 Jan 2016 11:57:22 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 15 Jan 2016 11:57:22 +0000 (UTC) Cc: 22369@debbugs.gnu.org To: "Geyslan G. Bem" Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Jan 15 12:57:12 2016 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1aK30B-0007VD-O4 for geb-bug-gnu-emacs@m.gmane.org; Fri, 15 Jan 2016 12:57:11 +0100 Original-Received: from localhost ([::1]:46408 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aK309-0008SY-Q6 for geb-bug-gnu-emacs@m.gmane.org; Fri, 15 Jan 2016 06:57:09 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:56361) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aK305-0008SO-H9 for bug-gnu-emacs@gnu.org; Fri, 15 Jan 2016 06:57:06 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aK302-00028Z-8s for bug-gnu-emacs@gnu.org; Fri, 15 Jan 2016 06:57:05 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:33215) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aK302-00028C-5E; Fri, 15 Jan 2016 06:57:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84) (envelope-from ) id 1aK301-0002eY-OZ; Fri, 15 Jan 2016 06:57:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Alan Mackenzie Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org, bug-cc-mode@gnu.org Resent-Date: Fri, 15 Jan 2016 11:57:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 22369 X-GNU-PR-Package: emacs,cc-mode X-GNU-PR-Keywords: Original-Received: via spool by 22369-submit@debbugs.gnu.org id=B22369.145285899310160 (code B ref 22369); Fri, 15 Jan 2016 11:57:01 +0000 Original-Received: (at 22369) by debbugs.gnu.org; 15 Jan 2016 11:56:33 +0000 Original-Received: from localhost ([127.0.0.1]:49668 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aK2zY-0002dn-LD for submit@debbugs.gnu.org; Fri, 15 Jan 2016 06:56:32 -0500 Original-Received: from mail.muc.de ([193.149.48.3]:20631) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aK2zW-0002df-JB for 22369@debbugs.gnu.org; Fri, 15 Jan 2016 06:56:31 -0500 Original-Received: (qmail 56864 invoked by uid 3782); 15 Jan 2016 11:56:28 -0000 In-Reply-To: X-Newsgroups: gnu.emacs.bug User-Agent: tin/2.3.1-20141224 ("Tallant") (UNIX) (FreeBSD/10.2-RELEASE-p9 (amd64)) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:111635 Archived-At: Hello, Geyslan. In article you wrote: > (setq c-basic-offset 8 > tab-width 8 > indent-tabs-mode t > comment-style 'extra-line) > (c-set-style "linux") > Using the above settings the comment-dwim (with region active) indent > the second and last lines with spaces instead of tabs. > /* > * void main() > * { > * int i; > * int b; > * printf("format string"); > * } > */ Yes. Thanks for taking the trouble to report this. The following patch should fix this bug. After applying the patch (in .../emacs-24.5/lisp), byte-compile the file with: $ emacs -Q -batch -f batch-byte-compile newcomment.el on the command line. If you then load the file (with M-x load-file) it should then work. However, the complication is that newcomment.el is a built-in part of Emacs rather than being a file loaded at runtime. So you then have the choice of either putting "(load newcomment.elc)" into your .emacs, or rebuilding Emacs entirely (which isn't that time-consuming or difficult). To do this, in directory .../emacs-24.5, do: $ make . If there are still problems with the fix, please report these to the bug mailing list at 22369@debbugs.gnu.org. > For better comprehension check out this > http://stackoverflow.com/questions/34710840/c-comment-in-emacs-linux-kernel-style-v2 > May I suggest the addition of a new comment-style option that does like this? > /* void main() > * { > * int i; > * int b; > * printf("format string"); > * } > */ OK, because of this feature request, I'll leave the bug open. This would indeed not be difficult to implement, but it'll have to be discussed on the developers' mailing list. > In GNU Emacs 24.5.1 (x86_64-unknown-linux-gnu, GTK+ Version 3.16.6) > of 2015-09-09 on foutrelis > Windowing system distributor `The X.Org Foundation', version 11.0.11800000 > System Description: Arch Linux [ .... ] Here's the patch: --- newcomment.el~ 2015-04-02 07:23:06.000000000 +0000 +++ newcomment.el 2016-01-15 11:41:24.912588709 +0000 @@ -969,6 +969,14 @@ (goto-char (point-max)))))) (set-marker end nil)) +(defun comment-make-bol-ws (len) + "Make a white-space string of width LEN for use at BOL. +When `indent-tabs-mode' is non-nil, tab characters will be used." + (if (and indent-tabs-mode (> tab-width 0)) + (concat (make-string (/ len tab-width) ?\t) + (make-string (% len tab-width) ? )) + (make-string len ? ))) + (defun comment-make-extra-lines (cs ce ccs cce min-indent max-indent &optional block) "Make the leading and trailing extra lines. This is used for `extra-line' style (or `box' style if BLOCK is specified)." @@ -1004,8 +1012,8 @@ (setq cs (replace-match fill t t s))) (string-match re e) (setq ce (replace-match fill t t e)))) - (cons (concat cs "\n" (make-string min-indent ? ) ccs) - (concat cce "\n" (make-string (+ min-indent eindent) ? ) ce)))) + (cons (concat cs "\n" (comment-make-bol-ws min-indent) ccs) + (concat cce "\n" (comment-make-bol-ws (+ min-indent eindent)) ce)))) (defmacro comment-with-narrowing (beg end &rest body) "Execute BODY with BEG..END narrowing. -- Alan Mackenzie (Nuremberg, Germany).