From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Bob Proulx Newsgroups: gmane.emacs.help Subject: Re: Setting up Emacs tabs like my Vim config Date: Mon, 30 Dec 2013 13:49:54 -0700 Message-ID: <20131230204954.GA12372@hysteria.proulx.com> References: <52C1BEA6.6000902@googlemail.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1388436615 25465 80.91.229.3 (30 Dec 2013 20:50:15 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 30 Dec 2013 20:50:15 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Some Developer Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Dec 30 21:50:23 2013 Return-path: Envelope-to: geh-help-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 1Vxjn4-00031q-WD for geh-help-gnu-emacs@m.gmane.org; Mon, 30 Dec 2013 21:50:23 +0100 Original-Received: from localhost ([::1]:59752 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vxjn4-0000b3-Fn for geh-help-gnu-emacs@m.gmane.org; Mon, 30 Dec 2013 15:50:22 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:42488) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vxjmp-0000Yt-Id for help-gnu-emacs@gnu.org; Mon, 30 Dec 2013 15:50:11 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vxjml-0000u5-Aj for help-gnu-emacs@gnu.org; Mon, 30 Dec 2013 15:50:07 -0500 Original-Received: from joseki.proulx.com ([216.17.153.58]:59911) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vxjmk-0000qE-AE for help-gnu-emacs@gnu.org; Mon, 30 Dec 2013 15:50:03 -0500 Original-Received: from hysteria.proulx.com (hysteria.proulx.com [192.168.230.119]) by joseki.proulx.com (Postfix) with ESMTP id F2E652122A; Mon, 30 Dec 2013 13:49:54 -0700 (MST) Original-Received: by hysteria.proulx.com (Postfix, from userid 1000) id D46342DCC6; Mon, 30 Dec 2013 13:49:54 -0700 (MST) Mail-Followup-To: Some Developer , help-gnu-emacs@gnu.org Content-Disposition: inline In-Reply-To: <52C1BEA6.6000902@googlemail.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 216.17.153.58 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:95207 Archived-At: Some Developer wrote: > I'm playing around with Emacs for the first time at the moment Welcome! > and so far things seem to be working well. The only problem I have > with Emacs is how it deals with tabs and indentation in general. Tabs are a troubled topic everywhere. Sigh. You will probably get many answers to this question. > I've read the manual on it but it seems like Emacs makes this > unnecessarily hard. Here is my current Vim config: Here is the upstream manual entry on it. http://www.gnu.org/software/emacs/manual/html_node/emacs/Indentation.html#Indentation And of course inside emacs you can easily read the documentation matching your installed version with C-h i m emacs to jump right to the emacs manual. Then I usually simply hit 's' to search and type in a search string. Here the topic is "indentation". The EmacsWiki page on this is: http://www.emacswiki.org/emacs/IndentationBasics As you can see in the discussion on the wiki this topic is neither simple nor settled even after decades. > " Set proper tab / spacing settings > set expandtab > set smarttab > set shiftwidth=4 > set tabstop=4 > set softtabstop=4 Can I say that I really hate it when people change the standard width of tabs to something nonstandard that isn't eight? It makes interoperating with others difficult because everyone will see a different result. Sigh. It is for this reason that most projects have gone to a policy of forbidding using tabs at all and requiring all indention to be spaces. Grr... (The tabstop=4 above is the problem. Should have stopped at softtabstop=4. However I do see expandtab so that there isn't propagation of tab characters to the file. The shiftwidth=4 doesn't affect tab stops and is okay.) This is different from what column the cursor moves to when you press the TAB key. The TAB key moves to the next tab position. The editor then determines if it should use an ASCII TAB character or a combination of TABs and spaces to arrive at that column. Changing the offset is always okay. I only object to changing the hard tab width. I personally like tabs but people changing the standard width of them has killed being able to use them as they were intended. > Does anyone know what an equivalent configuration would be in Emacs? > I'm using 24.3.1 if that makes any difference. If you really, really, really must change the tab-width to 4 then the following. This is the same as your above vim configuration. (setq-default indent-tabs-mode nil) ; no tab characters in files (setq-default tab-width 4) Also, indentation is usually language specific. It is good to keep the original style of the file you are editing. Often this is 2 for one file and 4 for another file and so forth. Instead of globally changing it I think it is better to do customizations in the desired modes only. This is often set in a mode hook for a specific mode. And specific modes often have specific indention capabilities. For example C mode has c-basic-offset and sh mode has sh-basic-offset and so forth. I set the following for sh mode for example. (setq sh-basic-offset 2) Or for text-mode I like the StackOverflow answer. But I set it in a mode hook to be buffer local to that mode. ;; From http://stackoverflow.com/questions/69934/set-4-space-indent-in-emacs-in-text-mode (add-hook 'text-mode-hook (lambda () (abbrev-mode 1) (auto-fill-mode 1) (setq tab-stop-list (number-sequence 4 200 4)))) Personally when I want a custom indentation for a programming language I always set it in a mode specific way. Such as using c-set-style for C files or sh-basic-offset for shell scripts or cperl-indent-level for perl and so forth. Other good related hints are that you can use emacs 'untabify' on a buffer and remove all tab characters. Also the shell 'expand -t4' command. To change tab sizes in a file. 'expand -t4 | unexpand' will reset a file's hard tab characters from a non-standard 4 back to a standard size 8. Bob