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 16:43:42 +0200 Message-ID: <20190411144342.ozqqehwpoamvaanu@Ergus> References: <20190411090223.GA5183@ACM> <20190411102405.vcwdygrz36cjt3ld@Ergus> <83bm1c656x.fsf@gnu.org> 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="13900"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: NeoMutt/20180716 Cc: acm@muc.de, emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Apr 11 16:44:09 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 1hEavw-0003VC-QE for ged-emacs-devel@m.gmane.org; Thu, 11 Apr 2019 16:44:09 +0200 Original-Received: from localhost ([127.0.0.1]:50019 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hEavv-00074b-RL for ged-emacs-devel@m.gmane.org; Thu, 11 Apr 2019 10:44:07 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:35942) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hEavf-00074T-V3 for emacs-devel@gnu.org; Thu, 11 Apr 2019 10:43:53 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hEave-00025K-K3 for emacs-devel@gnu.org; Thu, 11 Apr 2019 10:43:51 -0400 Original-Received: from sonic309-24.consmr.mail.ir2.yahoo.com ([77.238.179.82]:42565) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hEave-000245-2w for emacs-devel@gnu.org; Thu, 11 Apr 2019 10:43:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aol.com; s=a2048; t=1554993828; bh=sdMhXxwIPXBLMIcvyxVmC3iVEitjr0ewGrwYl9YwM5U=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From:Subject; b=qGwCNDc9BOr7kUkvGbdj+fK8gvlJQ4kVTtmm0Gdl3c5KHBNlhrXS/MXnxtRcxKOPiKuHTaLZ/zWkDizs+lXZLbLAe1SYlG3/8oQNFJ+8ryoHIa5RX8v36clW2JD1MlPpSHbh9fPs5REVtJr996tb9tktq1GUW9El4pNqBOcmFlUJ3YJeyoRINsFyOnTu4rZ74UUqa8MU51+3UoY/UNcRGDMBHCuBEBC1X3CPNj0peBpIdWGt2rfTT0lsDspSe4knKDtnemfLRgn1zrSCh/fob9kmp7jOYdamJq/4Rt1A+S/WNXq4kkgbP26wtcBYZMllUndSqUX6PtWUmYLrZOHktw== X-YMail-OSG: WCt6RX0VM1kNUJ9.KhExvIMx8ktnRCgx8NVJ7SS30Nx9R2LWJVIJIihxeLzk2DG wjaUmOLUMWKnMSAt7fOtQhFhYux2wpphL3XhRhEW6gCing1hNDn_DWa12ab3YnV6HlLh5Km1U2Gs K07AvhQE8DvqZUp5OamtTi2DewDhYIjyDWt427MIv3lN4SIDurzTl6iLayOYfYFvs4GnKxFgwe.3 EhFT72bJXOvL3GWuEcT8wZyzS7CT9yLhtz0A1sezQNBfwA5LHlqwOfNmldB0PMkzivWSYoA7d875 zjD7m9egfaNlvZLaUXGa8nO37m4gasXVzwbuV1OXq31ilPlMyyDXeFdi46DOlQ9kxMb62G2cTgsC Hv4ptGvE.B2yZ04iufEWz8HC1w1uYwj.Jegm.s8F7pxXlZrlXX.l0ZSfPjA595.EW0WQhSGIwLUY SXPkZ06vznL56UCXus.3GwPYQd1VJmtljaOca06W8YcsmXQTLIGQNwrtYX4MtOnFV4McC2YXCt70 22A0m5X3q6Ph2gp1bYOb2qGJsiMekSiw_CoAkUWMdHWGQyoP9g6dZ27Fpo63tsSS4vAsX8ye_yYs FJdsNEF1ICIo5uKvREiTu7J8qEFSOrujA4Yilq8I7juISCYDosSu8YBT.L7evJeZwcmgIRJklIt8 B6S5qfqamHEv_uxnmGwQ6CneYl9WNFaa1gf9cgm.aFOm7lTWyEeWPRiSULkHM7hC6jnRRfFGetRu xhbylsl2wsaMZUP1jmfmbPrFxA3cZGJMnBtHaGLa7ZHSaZwxMBFOJ44Z3ZmOhoxWGDVWjKE6E2HK B38S6eD9ZvZ5gbpYtcKguxgU9dMc2Ylhoc7zkBS.ht Original-Received: from sonic.gate.mail.ne1.yahoo.com by sonic309.consmr.mail.ir2.yahoo.com with HTTP; Thu, 11 Apr 2019 14:43:48 +0000 Original-Received: from 84.88.50.33 (EHLO Ergus) ([84.88.50.33]) by smtp425.mail.ir2.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID fcba41a17339968e0cd31c55e612b5e9; Thu, 11 Apr 2019 14:43:45 +0000 (UTC) Content-Disposition: inline In-Reply-To: <83bm1c656x.fsf@gnu.org> 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:235294 Archived-At: On Thu, Apr 11, 2019 at 04:29:26PM +0300, Eli Zaretskii wrote: >> Date: Thu, 11 Apr 2019 12:24:05 +0200 >> From: Ergus >> Cc: emacs-devel@gnu.org >> >> 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. > >I don't think you need to write any Lisp for that: CC Mode includes a >feature called "Interactive Customization of Indentation", read all >about it in the CC Mode manual. Hi Eli: I have already seen that part in the manual. But these options I'm talking about are not available with simple customization. The google's indentation style can be included in the list of styles (at least the basic support) because there are many details and offsets to correct. And really many people seems to be using it (look at the melpa statistics). But also the tab-width and indent-tabs-mode normally are set in the init file (is what we see in the documentation, and in emacswiki), but if the user needs to change style, the init values will "win" so he ends with a mixed style not very useful. The way to avoid that (the right way) is to create a style that inherits from one of the existing like I do for linux style: ``` (c-add-style "mylinux" '("linux" (tab-width . 4) (c-basic-offset . 4) (fill-column . 80) (c-offsets-alist (inline-open . 0) (cpp-macro . 0) ))) (setq-default c-default-style '((java-mode . "java") (awk-mode . "awk") (other . "mylinux"))) ``` But this for a new user this code is pretty close to Latin or ancient Cyrillic. Using the guess command in cc-mode at least for me didn't give good results because not all the syntactic symbols were present in a single file. So finally I ended doing most if it manually. Finally the indent with tabs align with spaces behavior, as it is not a customizable behavior; it needs to be implemented with the Alan's recommended work around (which is not in the documentation): ``` (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) ``` Or use the package... But this will need more code in case the user changes the style to a not tab-indented one. What I mean is that such small pieces of code are very useful for many people and can save time and customization time/code from the user (and potential error sources) if they are added as customization options. But also those small details represent a big difference for the final user's experience (specially for new ones) Sorry for bothering with this because they are basic editor functionalities people expect to have without too much effort in an editor. We can play tetris, music and there is a psychoanalyst, a pdf player debugger interface and so on... but it needs an external package and coding for so a basic editor tasks... It is like we put a lot of effort extending emacs, but not the editor/ide features. Which is where it is expected to shine first and more. Sorry for the long mail.