From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Ergus Newsgroups: gmane.emacs.devel Subject: Re: Supporting tabs for indentation, spaces for alignment Date: Thu, 11 Apr 2019 12:24:05 +0200 Message-ID: <20190411102405.vcwdygrz36cjt3ld@Ergus> References: <20190411090223.GA5183@ACM> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="43272"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: NeoMutt/20180716 Cc: emacs-devel@gnu.org To: Alan Mackenzie Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Apr 11 12:46:20 2019 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hEXDn-000B4p-6H for ged-emacs-devel@m.gmane.org; Thu, 11 Apr 2019 12:46:19 +0200 Original-Received: from localhost ([127.0.0.1]:46018 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hEXDm-0004zI-27 for ged-emacs-devel@m.gmane.org; Thu, 11 Apr 2019 06:46:18 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:54953) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hEWsT-0003CZ-Rj for emacs-devel@gnu.org; Thu, 11 Apr 2019 06:24:19 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hEWsR-00059X-2b for emacs-devel@gnu.org; Thu, 11 Apr 2019 06:24:17 -0400 Original-Received: from sonic309-24.consmr.mail.ir2.yahoo.com ([77.238.179.82]:44030) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hEWsP-00056x-85 for emacs-devel@gnu.org; Thu, 11 Apr 2019 06:24:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aol.com; s=a2048; t=1554978250; bh=kUP6nWSfMlCZ0tK716Eap/3XEC05nHJsB8FiJ4XKUx0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From:Subject; b=TcwLMIueBoagZaCamWqHS0BJkTJq3KUbAqw9aY45WUwXdF2Kde/DAt1SjNhJMqb4LGcYg0X3gHAitlVnUWov2pbLirEV62P+fVcaFA8iLAYe0vvqDh/UY3qF/nfC66bmDLJaZNcpnYymAFb2ADyvZA1edXvXCtRXL0ZauqXrxXzTA3yrD0KGD/mZVeQT5MaNvZslqyvxlL+ouEfArkmYWfpIINRZsipS/0qu2bISDyus32encZT1NcjgvC8bd/O1lupWWbsTRwhGL2HIKhu8g8lqfniQBcHSfpCnhto/MZ4UU7noaQdRl99XVq6xG5/qMSIyIKya6nvJEeXry7kg+w== X-YMail-OSG: d6oE2WMVM1keWUVfexjX8H6S4cLut473iLYG8elR6Jx4cw9BitldkEQwRWlmQom b1daKAQktyk_EWTn3Ml40eoX9jC.8_MloeRL5UlQklQ9RWE0bC0aOh5r1Tcr6V_bt_tb2H_WRHA3 uWZ.QenMY5P52JppMKh_dLVHvAeneRELoN4schkuLyAEQxs17WMF1A0mY4okMb12EjtOXeDd.SDB Gc9es7g7qiXWLzUQ3unolCkaJc7TpDJJKE0neS6yeT6RZng_JL.zlgvM7FECMArU0692Myxk4yTD deYoGCobIDxgb2lk6.nqqeAiEpOa3r03Udnaxw8awh2itYzKd4KwR_ujvbdz.dT3uhu8uYlsk3qW aePKtY.2FbtTh7QCHzXyV0tLI8VFWw8JZLmqiUswt0EsaXpUdiVYULrndd6D4HPcgFMyy1n9t_Cq cFsD4NMJykQ49mRizBq8QaA2.ZVwKrSOYtNHKxfPFhOSQolcTRZNCbqKsAFPsRhxQG6MGu8AGWzA 6Yszht_LSsr3MJ6x09W1OFBkfmwhvUSwIGUM4WQM1_PqmQrqGetf8oUzLXL0dgN.4YHLnxFmqjnd kFMIxoNlOSyHzxL_reU0soSbYhEm6n53T4w_i2ujAMW7b71S9MPTdaMzfRhUG8q5fCqPe88zqU6K A0.nb_PS4EnmxJMyeV8H5G_EjM6jxt0mZX7JowbDpU_5qsbXeCuL7zaGWrxzKMlwh9H.wzNp0Sz7 9jKYNOcJKMtipjr2HLp1s1ghARMlwomw0un5a7XDlxkiHns26KM7n2iUJZvcjByQmh1Pb4pWWCDW QA764JX6ZBTEd.IgS1_TFNuzvemaL.4xawZq75bfAI Original-Received: from sonic.gate.mail.ne1.yahoo.com by sonic309.consmr.mail.ir2.yahoo.com with HTTP; Thu, 11 Apr 2019 10:24:10 +0000 Original-Received: from 84.88.50.33 (EHLO Ergus) ([84.88.50.33]) by smtp416.mail.ir2.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 25aee0256abaad278a844b685754aab7; Thu, 11 Apr 2019 10:24:08 +0000 (UTC) Content-Disposition: inline In-Reply-To: <20190411090223.GA5183@ACM> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 77.238.179.82 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:235275 Archived-At: Hi Alan: Very thanks for replying. I will try to implement your solution for now in my config. But I'm wondering if after 11 years, with much better machines, improved emacs with many new functionalities (most of them nothing to do with a text editor) and the constant growing of languages that uses cc-mode as a base (rust || C++>=11 for example). But also with new indentation styles (like the google's one which is by far the most popular package in melpa). And this package which seems to work; so some experience already: https://github.com/jcsalomon/smarttabs And the increase in popularity of other editors/ides which use different policies (from vim, kdevelop, eclipse, notepad++, visual-studio-code); so a emacs user (like me) needs to attach and don't break the global project schema. Maybe it makes sense to think how to add other tab-indent-policies and styles in the c-indent-alist list. Even if they are not the defaults. So the users could find their needs without writing 40 lisp lines and read 20 manual pages full of therms that makes sense only after reading 1000 previous pages. Or needing to install an external package that potentially gets abandon. On Thu, Apr 11, 2019 at 09:02:23AM +0000, Alan Mackenzie wrote: >Hello again, Ergus. > >You were asking in your post Subject: Re: C style alist question? for a >way of indenting CC Mode modes with "tabs for indentation and spaces for >alignment." > >The topic has come up before, and I answered back in 2008 with the >following post to the OP and bug-cc-mode@gnu.org. It's a bit wordy, I >admit, but does provide a way of getting what you're asking for. I >admit not having tried it out recently. > >-- >Alan Mackenzie (Nuremberg, Germany). > > >----- Forwarded message from Alan Mackenzie ----- > >X-Spam-Checker-Version: SpamAssassin 3.2.0 (2007-05-01) on colin2.muc.de >X-Spam-Level: >X-Spam-Status: No, score=0.1 required=5.0 tests=AWL,BAYES_50 autolearn=no version=3.2.0 >Date: Fri, 11 Apr 2008 20:31:42 +0000 >To: Mike Sullivan >Subject: Re: Supporting tabs for indentation, spaces for alignment >X-Delivery-Agent: TMDA/1.1.5 (Fettercairn) >From: Alan Mackenzie >X-Primary-Address: acm@muc.de >X-detected-kernel: by monty-python.gnu.org: FreeBSD 4.6-4.9 >Cc: bug-cc-mode@gnu.org >X-BeenThere: cc-mode-help@lists.sourceforge.net >X-Mailman-Version: 2.1.8 >Reply-To: bug-cc-mode@gnu.org >List-Id: "Bug reports, feature requests, and general talk about CC Mode." >List-Unsubscribe: , >List-Archive: >List-Post: >List-Help: >List-Subscribe: , > >Hi, Mike, > >Sorry it's taken me so long to answer. > >On Wed, Jan 09, 2008 at 02:04:40AM -0600, Mike Sullivan wrote: >> Currently, cc-mode offers no simple way to use tabs for indentation, >> but spaces for alignment (as described many places on the web, >> including http://wiki.chad.org/wiki?IndentationUsingTabs). Is there >> any chance that this will be added as a feature in a future version? > >OK: Here's what I think that page means. Supposing your tab-width is 8, >in > >{ > if (a really long conditional that won't fit > onto one line) { .... > .... > } >} > >, you want (I think), tabs here: >tttttttt >, yet spaces here: > .... > >If your tab-width were 2, you'd want to see this: > >{ > if (a really long conditional that won't fit > onto one line) { .... > .... > } >} > >, with tabs here: >tt >, and spaces here: > .... > >. > >Currently, assuming indent-tabs-mode is set, with a sufficiently large >tab-width (say, 8), this is what you'll get, but with a smaller >tab-width (2), the four spaces will be replaced by two tabs, not what >you want. > >No, there are no plans for putting such a feature into CC Mode at the >moment. One could opine that the opinions on that web page are somewhat >opinionated, capable of triggering religious wars. ;-) My own view is >that that indentation strategy would be a right royal pain, unless it >somehow got enforced 100% by the project's management and _every_ editor >in use supported it. To implement the idea "properly" in CC Mode would >entail a non-trivial amount of work. > >However, this is the sort of thing that seems tailor-made for >c-special-indent-hook (see page "Other Indentation" in the CC Mode >manual), and shows just how flexible Emacs (in general) and CC Mode (in >particular) are, and just how superior they are to lesser editors. ;-) > >I've written a quick hack, to give you an idea how this sort of thing >could work. Here's the source file I tried it on, _without_ tabs here >(it goes more easily into an email that way), with c-basic-offset = 3: > > >int foo (char a, char b, char c, char d, char e, > char f, char g) { > if (a = 'a' > && b = 'b' > && c = 'c') > { > print "hi!\n" ; > return 0 ; > } > return 1 ; >} > > >As a quick tip, to _see_ tabs in a buffer, do M-x hi-lock-mode, then C-x >w h. On being prompted for a regexp just do C-q , then select >some highlighting face. > >OK, here's the hack: > >(defun ms-space-for-alignment () > "Make the current line use tabs for indentation and spaces for alignment. > >It is intended to be called from the hook >`c-special-indent-hook'. It assumes that `indent-tabs-mode' is >non-nil and probably assumes that `c-basic-offset' is the same as >`tab-width'." > (save-excursion > (let* ((indent-pos (progn (back-to-indentation) (point))) > (indent-col (current-column)) > (syn-elt (car c-syntactic-context)) > (syn-sym (c-langelem-sym syn-elt))) > (when (memq syn-sym '(arglist-cont-nonempty)) ;; <============== > (let* ((syn-anchor (c-langelem-pos syn-elt)) > (anchor-col (progn (goto-char syn-anchor) > (back-to-indentation) > (current-column))) > num-tabs) > ;; > (goto-char indent-pos) > (delete-horizontal-space) > (insert-char ?\t (/ anchor-col tab-width)) > (insert-char ?\ (- indent-col (current-column)))))))) > >To enable it, do this: > > M-: (setq indent-tabs-mode t) > M-: (setq tab-width 3) > M-: (setq c-basic-offset tab-width) > (add-hook 'c-special-indent-hook 'ms-space-for-alignment nil t) > > >If you were to develop this hack into fully working code, I would be >willing to put it into the next full version of CC Mode (subject to the >customary copyright assignment to the FSF, which we all have to do). > > >> Thanks, Mike Sullivan > >Happy hacking! > >-- >Alan Mackenzie (Nuremberg, Germany). > >------------------------------------------------------------------------- >This SF.net email is sponsored by the 2008 JavaOne(SM) Conference >Don't miss this year's exciting event. There's still time to save $100. >Use priority code J8TL2D2. >http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone > >----- End forwarded message ----- >