all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Bob Proulx <bob@proulx.com>
To: Some Developer <someukdeveloper@gmail.com>
Cc: help-gnu-emacs@gnu.org
Subject: Re: Setting up Emacs tabs like my Vim config
Date: Mon, 30 Dec 2013 13:49:54 -0700	[thread overview]
Message-ID: <20131230204954.GA12372@hysteria.proulx.com> (raw)
In-Reply-To: <52C1BEA6.6000902@googlemail.com>

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



      parent reply	other threads:[~2013-12-30 20:49 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
     [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 [this message]

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=20131230204954.GA12372@hysteria.proulx.com \
    --to=bob@proulx.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=someukdeveloper@gmail.com \
    /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.