help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Make real tabs that stay tabs


From: Bob Proulx
Subject: Re: Make real tabs that stay tabs
Date: Wed, 14 Feb 2018 18:50:16 -0700
User-agent: Mutt/1.9.3 (2018-01-21)

Harry Putnam wrote:
> So insert 2 or three but OOPS If I decide to back one out with
> backspace I'm backing by spaces not by tabs.

That behavior is the behavior of backward-delete-char-untabify.

As I look at things now the keybinding appears to be changed in some
mode specific ways.  For example in fundamental mode DEL is bound to
backward-delete-char-untabify but in a mail composition mode DEL is
bound to delete-backward-char.  I double checked this just now using
'emacs -Q'.

> Seems like if I take care to insert a real tab then it ought to act
> like a real tab when I backspace over it too.

Emacs doesn't keep track of how you inserted the character.  It
doens't know about quoting a key with C-q to insert it.  But emacs
does know about the buffer mode.

Next time you have this problem try this experiment.  Convert back to
funamental mode.  It should work as you want.

  M-x fundamental-mode

> Recently I found myself correcting an rsnapshot.conf file where things
> MUST be separated by tabs.. one way to test is to back over what is
> there and see if your cursor jumps a tabs worth.  But apparently that
> cannot be done with emacs.

I think that apparently the .conf mode which was triggered by the file
name or local variable caused emacs to switch keymaps to bind the
Backspace key DEL to backward-delete-char-untabify .

> I seem to recall being able to do that in the past.

The emacs documentation says:

  For instance, <DEL> runs the command ‘delete-backward-char’ by default
  (some modes bind it to a different command); it does not insert a
  literal ‘DEL’ character (ASCII character code 127).
  ...
  ‘<DEL>’
  ‘<BACKSPACE>’
     Delete the character before point, or the region if it is active
     (‘delete-backward-char’).

The default behavior is as you like it deleting the TAB character.
However the manual also says:

     In most programming languages, indentation should vary from line to
  line to illustrate the structure of the program.  Therefore, in most
  programming language modes, typing <TAB> updates the indentation of the
  current line (*note Program Indent::).  Furthermore, <DEL> is usually
  bound to ‘backward-delete-char-untabify’, which deletes backward
  treating each tab as if it were the equivalent number of spaces, so that
  you can delete one column of indentation without worrying whether the
  whitespace consists of spaces or tabs.

Therefore the .conf mode you were in must be doing the above.  What
mode is displayed in the mode line when you are editing that file?
When I edit a file named rsnapshot.conf here I see "Conf[Unix]" as the
mode and here DEL is mapped to delete-backward-char so I don't know
why your mode was different.  However I see this in other modes such
as in C program modes.  The manual also says:

     Entering a programming language mode runs the custom Lisp functions
  specified in the hook variable ‘prog-mode-hook’, followed by those
  specified in the mode’s own mode hook (*note Major Modes::).

If the .conf file mode you are using is derived from a programming
mode then perhaps the best answer is one of two possibilities.  Either
change to a different mode such as fundamental-mode or configure
programming modes and their children using prog-mode-hook to rebind
the DEL key as you like overriding the mode keymap.

> Can someone explain this to me.

Hopefully this makes sense of what is happening.

Bob



reply via email to

[Prev in Thread] Current Thread [Next in Thread]