all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Re: turning off all indentation
       [not found] <d337ac07-d622-400f-9520-ac22ce0e4f86@k29g2000yqh.googlegroups.com>
@ 2010-05-12 16:44 ` Andreas Politz
       [not found]   ` <81679436-5d3c-429c-bc39-7121f452d51b@d39g2000yqa.googlegroups.com>
       [not found] ` <87pr1145gl.fsf@lola.goethe.zz>
  1 sibling, 1 reply; 6+ messages in thread
From: Andreas Politz @ 2010-05-12 16:44 UTC (permalink / raw)
  To: help-gnu-emacs

Lynn Newton <lynn.newton@gmail.com> writes:

>
>     I want a trivial way to disable autoindenting for
>     all languages and in all modes. I want it to work
>     in all versions of Emacs and I don't want it stop
>     working.
>
To summarize, the following are _not_ solutions :

- A piece of code that does disable indentation in all modes and all
versions, but foo-mode in Emacs 22.3.174.

- A piece of code that always works, ever, but contains a very short,
but incomprehensible algorithm.

- A piece of code that works in all modes he uses. But not in some c++
  mode, some Indian teenager wrote in the '90, which of course he never
  published. (Because his girl-friend had left him at the time.)

>
> Suggestions? Thank you.

(add-hook 'after-change-major-mode-hook
          (lambda nil
            (local-set-key [return] nil)
            (local-set-key [tab] nil)))

I don't know which version this hook was introduced.

-ap


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: turning off all indentation
       [not found]   ` <81679436-5d3c-429c-bc39-7121f452d51b@d39g2000yqa.googlegroups.com>
@ 2010-05-12 19:11     ` Alan Mackenzie
  2010-05-12 19:15     ` Lowell Gilbert
  2010-05-12 19:59     ` Andreas Politz
  2 siblings, 0 replies; 6+ messages in thread
From: Alan Mackenzie @ 2010-05-12 19:11 UTC (permalink / raw)
  To: help-gnu-emacs

Hi, Lynn,

Lynn Newton <lynn.newton@gmail.com> wrote:
>> (add-hook 'after-change-major-mode-hook
>> ? ? ? ? ? (lambda nil
>> ? ? ? ? ? ? (local-set-key [return] nil)
>> ? ? ? ? ? ? (local-set-key [tab] nil)))

> With this, if I start up Emacs and start to edit a file myfile.c,
> I get this far:

> main()
> {
>        int i

> Pretend there's a tab in front of int. When I add a semicolon to that
> line, it backindents it to column 2 (counting from 0), which is what I
> meant about the local modes taking over.

To configure CC Mode not to this, turn off CC Mode's "electric mode", as
described on pages "Minor Modes" and  "Getting Started" in the CC Mode
manual.  Or, if you can't be bothered with the manual, stick this in your
.emacs:

    (setq-default c-electric-flag nil)

.  By default, <CR> just inserts a new line; it doesn't put any
indentation on the new line.

> If I edit a plain text file, e.g., myfile.txt or without an extension,
> a tab indents me only four spaces. If a line is indented more spaces,
> typing a tab on the line below indents the next line to whatever column
> the previous line is indented to.

It's actually cleverer than that; it indents the new line to the
syntactically right place.

> Mind you, I think that's clever and wonderful, but what my friend wants
> is whenever he presses a TAB key, in whatever mode, and in whatever
> context, it skips to the next 8-character tab stop, regardless of the
> mode, the position of the line above, etc.

There's no way of doing this for EVERY mode, because the modes don't
invoke indentation in the same way.  It can be done for _each_ mode in a
small finite set.  To make <TAB> insert a tab in CC Mode, put this into
your .emacs:

    (eval-after-load 'cc-mode
     '(define-key c-mode-base-map ?\C-i 'tab-to-tab-stop))

(not tested).

> And whenever he hits RETURN, he wants the cursor to go to column zero
> of the next line, period, no ifs ands or buts.

This should be happening by default anyway.  Might there be something in
his .emacs which binds <CR> to `newline-and-indent'?

> And I'm pretty sure that when he hits other keys, such as semicolons,
> curly brackets, and other syntactically significant characters within
> some given mode, he wants it *not* to change the alignment of the
> current line or any other line nearby.

See above for CC Mode.

> One would think that would be pretty easy to do, but the subtleties of
> various languages and accompanying modes are so thoroughly built in
> that it's hard to escape them.  Most people consider that a Good Thing.

:-)

-- 
Alan Mackenzie (Nuremberg, Germany).



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: turning off all indentation
       [not found]   ` <81679436-5d3c-429c-bc39-7121f452d51b@d39g2000yqa.googlegroups.com>
  2010-05-12 19:11     ` Alan Mackenzie
@ 2010-05-12 19:15     ` Lowell Gilbert
  2010-05-12 19:59     ` Andreas Politz
  2 siblings, 0 replies; 6+ messages in thread
From: Lowell Gilbert @ 2010-05-12 19:15 UTC (permalink / raw)
  To: help-gnu-emacs

Lynn Newton <lynn.newton@gmail.com> writes:

>> (add-hook 'after-change-major-mode-hook
>>           (lambda nil
>>             (local-set-key [return] nil)
>>             (local-set-key [tab] nil)))
>
> With this, if I start up Emacs and start to edit a file myfile.c,
> I get this far:
>
> main()
> {
>         int i
>
> Pretend there's a tab in front of int. When I add a semicolon
> to that line, it backindents it to column 2 (counting from 0),
> which is what I meant about the local modes taking over.
>
> If I edit a plain text file, e.g., myfile.txt or without an
> extension, a tab indents me only four spaces. If a line
> is indented more spaces, typing a tab on the line below
> indents the next line to whatever column the previous
> line is indented to.
>
> Mind you, I think that's clever and wonderful, but what
> my friend wants is whenever he presses a TAB key,
> in whatever mode, and in whatever context, it skips
> to the next 8-character tab stop, regardless of the mode,
> the position of the line above, etc. And whenever he
> hits RETURN, he wants the cursor to go to column zero
> of the next line, period, no ifs ands or buts.
>
> And I'm pretty sure that when he hits other keys, such
> as semicolons, curly brackets, and other syntactically
> significant characters within some given mode, he
> wants it *not* to change the alignment of the current
> line or any other line nearby.
>
> One would think that would be pretty easy to do, but the
> subtleties of various languages and accompanying modes
> are so thoroughly built in that it's hard to escape them.
> Most people consider that a Good Thing.

Yes.  To follow the approach, you'd need to extend it to all of the
other keys that should strictly self-insert.  It might be easier to just
delete the local keymap.  On the other hand, deleting the local keymap
in all keymaps would make some non-programming modes (like dired and
info) pretty much useless.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: turning off all indentation
       [not found]   ` <81679436-5d3c-429c-bc39-7121f452d51b@d39g2000yqa.googlegroups.com>
  2010-05-12 19:11     ` Alan Mackenzie
  2010-05-12 19:15     ` Lowell Gilbert
@ 2010-05-12 19:59     ` Andreas Politz
  2 siblings, 0 replies; 6+ messages in thread
From: Andreas Politz @ 2010-05-12 19:59 UTC (permalink / raw)
  To: help-gnu-emacs

Lynn Newton <lynn.newton@gmail.com> writes:

>> (add-hook 'after-change-major-mode-hook
>>           (lambda nil
>>             (local-set-key [return] nil)
>>             (local-set-key [tab] nil)))
>
> With this, if I start up Emacs and start to edit a file myfile.c,
> I get this far:
>
> main()
> {
>         int i
>
> Pretend there's a tab in front of int. When I add a semicolon
> to that line, it backindents it to column 2 (counting from 0),
> which is what I meant about the local modes taking over.
>
The author of cc-mode probably worked hours on this one.

> If I edit a plain text file, e.g., myfile.txt or without an
> extension, a tab indents me only four spaces. If a line
> is indented more spaces, typing a tab on the line below
> indents the next line to whatever column the previous
> line is indented to.
>

This is easily fixed by finding the desired command (obviously not
`indent-for-tab-command').

> Mind you, I think that's clever and wonderful, but what
> my friend wants is whenever he presses a TAB key,
> in whatever mode, and in whatever context, it skips
> to the next 8-character tab stop, regardless of the mode,
> the position of the line above, etc. And whenever he
> hits RETURN, he wants the cursor to go to column zero
> of the next line, period, no ifs ands or buts.

 Is this any different than simply inserting a tab character ?
 
 (global-set-key [tab] 'self-insert-command)
 
>
> And I'm pretty sure that when he hits other keys, such
> as semicolons, curly brackets, and other syntactically
> significant characters within some given mode, he
> wants it *not* to change the alignment of the current
> line or any other line nearby.
>
> One would think that would be pretty easy to do, but the
> subtleties of various languages and accompanying modes
> are so thoroughly built in that it's hard to escape them.
> Most people consider that a Good Thing.

Yes, most.

I don't think a foolproof, automatic solution is worth the time. It
would have to examine all bound commands and make a guess about it
being on the blacklist (touching indentation) or not.

Also, unconditionally unbinding tab and return in all mode-maps would
break e.g. help-mode, where return follows a link.

Ask your friend how many modes he really uses. 5-10 ? Not to much for
manually configuration.

Supplementary the idea of a hot-button comes to mind, which your friend
can push and tell Emacs that the last command sucked.  At this point the
binding in the mode-map could be cleared, in order to make way for the
global one.

Or maybe installing an Emacs from a time where people, who wanted to
have full control over indentation, still constituted the majority.

-ap


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: turning off all indentation
       [not found]   ` <a08c7e68-3949-41de-bdbf-5d4c81e377f9@d27g2000yqc.googlegroups.com>
@ 2010-05-13  0:31     ` Tim X
  2010-05-13 14:53       ` Scott Frazer
  0 siblings, 1 reply; 6+ messages in thread
From: Tim X @ 2010-05-13  0:31 UTC (permalink / raw)
  To: help-gnu-emacs

Lynn Newton <lynn.newton@gmail.com> writes:

>> I have a hard time imagining why you would run
>> indent-region if you definitely don't want Emacs to
>> indent the region.
>
> Me too. It was just an example. I've had all variations
> Emacsen behave obstreperously for no reason that I
> could detect, suddenly changing its characteristics and
> forgetting my preferences, right in the middle of
> editing when in some particular programming mode. (This
> happens a lot to me in cperl-mode.) In some cases I
> wind up having little recourse other than to kill the
> editing session and start a new one.
>
>> > (Note the 8-space tabs.)
>
>> It's not like you can't configure cc-mode to do
>> exactly that style of indentation.
>
> True enough, but that doesn't answer the original
> question about how to set that for every mode all the
> time. It's just what the person in whose behalf I'm
> asking wants. Certainly not my own preference, as I
> think that in most modes the defaults that are set are
> good, and probably should not be altered without good
> reason.

Doing it for all possible modes is probably an impossible task as there
is no way to identify all possible modes - if not an infinite set, it
certainly wold be a very large one. 

The best I suspect you can do is use hooks to ensure keys like enter and
tab are bound to their basic functions. This could be difficult as there
is no guarantee that a mode provides such a hook and there are some
modes that provide quite sophisticated behavior, such as behving
differently depending on how many time the key is pressed within a
certain interval etc. Re-binding such keys could easily result in the
loss of valuable functionality as well as indentation. 

There is no simple way this can be done. It is very much working against
what the modes are desinged for. In many cases, once you remove custom
indentation behavior, all you are left with is font locking. 

If the only thing your friend wants is font-locking, I would just derive
new modes from someting like fundamental mode, add font-lock keywords
and use that mode instead of the standard modes.  If they don't even
want font-locking, then just use fundamental mode for everythig and be
done with it. 

In the end, it feels very much like a grandmother who has purchased a
high performance v12 to only use it in the slow lane, You may
as well just use a simpler less featured editor that supports emacs key
bindings. and save some resources. 

As DK points out, the real solution is to put in the effort to customize
the modes your friend uses to behave the way he wants and then just
forget about it. Either stop fighting against the system or change
systems. The proposed approach will never be reliable, will probably
break after upgrades and will just be a constant source of frustration. 

Tim

-- 
tcross (at) rapttech dot com dot au


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: turning off all indentation
  2010-05-13  0:31     ` Tim X
@ 2010-05-13 14:53       ` Scott Frazer
  0 siblings, 0 replies; 6+ messages in thread
From: Scott Frazer @ 2010-05-13 14:53 UTC (permalink / raw)
  To: help-gnu-emacs

On 5/12/10 8:31 PM, Tim X wrote:

> Doing it for all possible modes is probably an impossible task as there
> is no way to identify all possible modes - if not an infinite set, it
> certainly wold be a very large one.
>
> The best I suspect you can do is use hooks to ensure keys like enter and
> tab are bound to their basic functions. This could be difficult as there
> is no guarantee that a mode provides such a hook and there are some
> modes that provide quite sophisticated behavior, such as behving
> differently depending on how many time the key is pressed within a
> certain interval etc. Re-binding such keys could easily result in the
> loss of valuable functionality as well as indentation.
>
> There is no simple way this can be done. It is very much working against
> what the modes are desinged for. In many cases, once you remove custom
> indentation behavior, all you are left with is font locking.

I use a minor-mode, defined at the end of my .emacs.d/init.el, that overrides
things in major-modes that annoy me:

(defvar my-keys-minor-mode-map (make-keymap) "my-keys-minor-mode keymap.")

(defmacro my-keys-define (key fn)
   (list 'define-key 'my-keys-minor-mode-map (list 'kbd key) fn))

;; Example for OP, I don't do this myself :)

(my-keys-define "<return>" 'newline)

(define-minor-mode my-keys-minor-mode
   "A minor mode so that my key settings override annoying major modes."
   t " my-keys" 'my-keys-minor-mode-map)

(my-keys-minor-mode 1)

;; You probably don't want this in the minibuffer

(defun my-minibuffer-setup-hook ()
   (my-keys-minor-mode 0))

(add-hook 'minibuffer-setup-hook 'my-minibuffer-setup-hook)

You may have to add other turn-off-my-keys-minor-mode hooks for things where
<return> needs to do something other than insert a newline.  The set will
probably be relatively small.

Scott


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2010-05-13 14:53 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <d337ac07-d622-400f-9520-ac22ce0e4f86@k29g2000yqh.googlegroups.com>
2010-05-12 16:44 ` turning off all indentation Andreas Politz
     [not found]   ` <81679436-5d3c-429c-bc39-7121f452d51b@d39g2000yqa.googlegroups.com>
2010-05-12 19:11     ` Alan Mackenzie
2010-05-12 19:15     ` Lowell Gilbert
2010-05-12 19:59     ` Andreas Politz
     [not found] ` <87pr1145gl.fsf@lola.goethe.zz>
     [not found]   ` <a08c7e68-3949-41de-bdbf-5d4c81e377f9@d27g2000yqc.googlegroups.com>
2010-05-13  0:31     ` Tim X
2010-05-13 14:53       ` Scott Frazer

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.