all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "William G. Gardella" <wgg2@member.fsf.org>
To: help-gnu-emacs@gnu.org
Subject: Re: Setting up Emacs tabs like my Vim config
Date: Mon, 30 Dec 2013 20:19:56 +0000	[thread overview]
Message-ID: <87vby63xcj.fsf@motoko.kusanagi> (raw)
In-Reply-To: 52C1BEA6.6000902@googlemail.com

Some Developer <someukdeveloper@gmail.com> 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.




  reply	other threads:[~2013-12-30 20:19 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-30 18:42 Setting up Emacs tabs like my Vim config Some Developer
2013-12-30 20:19 ` William G. Gardella [this message]
     [not found] ` <mailman.10722.1388434857.10748.help-gnu-emacs@gnu.org>
2013-12-30 20:39   ` Damien Wyart
2013-12-30 20:49 ` Bob Proulx

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87vby63xcj.fsf@motoko.kusanagi \
    --to=wgg2@member.fsf.org \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.