all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Emanuel Berg <embe8573@student.uu.se>
To: help-gnu-emacs@gnu.org
Subject: Re: While editing a CMake file, how to turn off smart indentation?
Date: Fri, 17 Jul 2015 00:55:15 +0200	[thread overview]
Message-ID: <87io9jk90s.fsf@nl106-137-147.student.uu.se> (raw)
In-Reply-To: CADKOXrDe6aeaPekf1ghdY=gAwuQOwUkUmiNvrOL7apXh0_9AiQ@mail.gmail.com

Yaron Cohen-Tal <yaronct@gmail.com> writes:

> I just want each line to get the same indentation as
> the previous line, and that TAB would indent 4
> spaces. For C++ I managed it with:
>
>     (setq-default indent-tabs-mode nil)

This (not having tabs) is a good idea!

>     (setq-default c-syntactic-indentation nil)

But why not have automatic indentation? C++ (and C)
are very straightforward when it comes to structure
and how nestedness is expressed in code, so why not
have the code display that visually, as well?

And, because it is so easy to do and looks the same
all the time (almost), one might just leave it to the
computer. E.g., fully automatized:

void Sporadic_Task::run(ms_t duration) {
  if (!quiet) {
    std::cout << "task " << id << " executes: " << program << std::endl;
  }
  // for extern processes, this is implicit
  if (!fork_processes) { run_program(program, program_args); }
}

This would save you six TAB strokes if you were to
disable automatic indentation! Why do it? Remember, in
special cases, you might still *change* the
indentation (using other keys than TAB). It is not
Python! But in 9*% of the cases, you don't want it so
why not automatize the common case?

If you want an "alternative TAB" for manual
indentation, why not bind say M-TAB, backtab (S-TAB),
or even write a defun that checks for a prefix
argument - if there is one, don't do
(semi-)automatized indentation, instead insert that
many number of whitespaces!

Like this:

    (defun tab-auto-or-manual (&optional spaces)
      (interactive "p")
      (if (> spaces 1) (insert-char ?\  spaces)
        (indent-for-tab-command) ))
    (global-set-key "\t" 'tab-auto-or-manual)

It is even more powerful than your idea because now
you can do `C-u C-u TAB' to get 4**2 = 16 whitespaces
and so on. (You can also use the variable
`c-basic-offset' that you mention but that is making
it less powerful.)

Of course, this is only if you are bound and
determined to do this with the TAB key. Otherwise, for
example `C-u C-u SPC' works just as well! Which is
what I do (sometimes), in the rare cases auto
indentation isn't what I want.

> In my `.emacs`, but for CMake files Emacs just
> indents the lines automatically according to its own
> rules, and TAB has no effect at all.

What is CMake? I don't get any apropos matches and
there isn't anything in the Emacs documentation
according to my razor-sharp tools for finding out.
But if it is something different (from C and C++)
altogether, it isn't strange that doing that
won't help. You need to examine the Emacs mode not for
the programming, but for the "cmake and CMakefile"
system, and set it there. To find out what TAB does,
hit `C-h k TAB' while in a buffer with that kind of
file. If you don't like what it does, you can change
that, of course.

-- 
underground experts united
http://user.it.uu.se/~embe8573




  reply	other threads:[~2015-07-16 22:55 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-16  7:23 While editing a CMake file, how to turn off smart indentation? Yaron Cohen-Tal
2015-07-16 22:55 ` Emanuel Berg [this message]
2015-07-16 23:55 ` Stefan Monnier
     [not found] ` <mailman.7023.1437087429.904.help-gnu-emacs@gnu.org>
2015-07-17  1:14   ` Dan Espen
2015-07-17  5:39 ` Vaidheeswaran C
2015-07-17 23:37   ` Emanuel Berg
2015-07-17  5:52 ` Vaidheeswaran C
2015-07-17 15:01 ` Ian Zimmerman
  -- strict thread matches above, loose matches on Subject: below --
2015-07-17  4:18 Yaron Cohen-Tal
2015-07-17  5:59 ` Vaidheeswaran C
2015-07-17 23:34 ` Emanuel Berg
2015-07-17 23:54   ` John Mastro
2015-07-18  0:26     ` Emanuel Berg
2015-07-18 17:58       ` Yaron Cohen-Tal
2015-07-18 19:18         ` John Mastro
2015-07-19 17:35           ` Yaron Cohen-Tal

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=87io9jk90s.fsf@nl106-137-147.student.uu.se \
    --to=embe8573@student.uu.se \
    --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.