From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "William G. Gardella" Newsgroups: gmane.emacs.help Subject: Re: Setting up Emacs tabs like my Vim config Date: Mon, 30 Dec 2013 20:19:56 +0000 Message-ID: <87vby63xcj.fsf@motoko.kusanagi> References: <52C1BEA6.6000902@googlemail.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1388434861 7264 80.91.229.3 (30 Dec 2013 20:21:01 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 30 Dec 2013 20:21:01 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Dec 30 21:21:07 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 1VxjKj-0008DJ-JU for geh-help-gnu-emacs@m.gmane.org; Mon, 30 Dec 2013 21:21:05 +0100 Original-Received: from localhost ([::1]:59689 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VxjKj-0000yP-4Q for geh-help-gnu-emacs@m.gmane.org; Mon, 30 Dec 2013 15:21:05 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:37992) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VxjKR-0000yI-Im for help-gnu-emacs@gnu.org; Mon, 30 Dec 2013 15:20:55 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VxjKK-0001VT-8j for help-gnu-emacs@gnu.org; Mon, 30 Dec 2013 15:20:47 -0500 Original-Received: from plane.gmane.org ([80.91.229.3]:45373) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VxjKJ-0001VM-IJ for help-gnu-emacs@gnu.org; Mon, 30 Dec 2013 15:20:39 -0500 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1VxjK9-0007Qj-9Q for help-gnu-emacs@gnu.org; Mon, 30 Dec 2013 21:20:29 +0100 Original-Received: from 37.221.161.235 ([37.221.161.235]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 30 Dec 2013 21:20:29 +0100 Original-Received: from wgg2 by 37.221.161.235 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 30 Dec 2013 21:20:29 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 51 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: 37.221.161.235 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:QV2PQQBYDREphoCcUngBkWeDk1w= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 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:95205 Archived-At: Some Developer writes: > I'm playing around with Emacs for the first time at the moment 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. > > I've read the manual on it but it seems like Emacs makes this > unnecessarily hard. Here is my current Vim config: > > " Set proper tab / spacing settings set expandtab set smarttab set > shiftwidth=4 set tabstop=4 set softtabstop=4 Indentation is complex in Emacs, as it uses a mix of tabs and spaces by default and it is common for different major modes to supply their own functions and variables for indentation. Therefore, you'd need to enter each mode's local enivronment to really change the effect of the TAB key where you expect. A rough equivalent to your code could be something like this: --8<---------------cut here---------------start------------->8--- (defun tab-is-tab-is-tab () "Configure tab-related settings and ensure that TAB is `tab-to-tab-stop' in the local map." (setq tab-width 4 tab-stop-list (loop for i to 120 by 4 collect i) indent-tabs-mode t) (local-set-key (kbd "TAB") 'tab-to-tab-stop)) --8<---------------cut here---------------end--------------->8--- This is intended to plug in to the local variable settings and keymap of a buffer in a particular major mode. We can add it to a bunch of modes at once by hooking to the modes they inherit from; e.g. programming modes generally inherit from `prog-mode' and natural language composition modes from `text-mode'. --8<---------------cut here---------------start------------->8--- (add-hook 'prog-mode-hook 'tab-is-tab-is-tab) (add-hook 'text-mode-hook 'tab-is-tab-is-tab) --8<---------------cut here---------------end--------------->8--- This will also leave the binding of TAB available in special modes like shell-mode, irc clients, and comint-derived modes (usually REPLs or interfaces to interactive processes), which often use TAB for shell-like completion. P.S. You can use M-x tabify to convert existing code from spaces to tabs, although a bulk processing tool like "astyle" is often a better choice if you have to re-indent a lot of code at once, or if the goal is to make indentation uniform across several people's contributions.