Getting Emacs Tabs to Indent 2 ( Using Emacs Live ) - emacs

What I want:
Tabs to be a length of 2.
What I have:
Tabbing moves me several spaces. Ether 2 spaces or 6. Seemingly randomly.
And they are spaces, literally, it seems. In that if press tab then I move up 6 characters, I press backspaces and it moves me back 1 ( to the 5th position).
So tabs move me to either a mod 2 or a mod 6 location all via spaces.
I want it to move me two at a time via tabs.
I have hacked around with different commands to no avail. = (
Thank you
Edit:
Also why the heck is this article titled tabs are evil when it says they are necessary...
http://www.emacswiki.org/emacs/TabsAreEvil

Related

Emacs tabs strange behaviour .conf files

Edit: Fresh install of emacs (emacs version from M-x emacs-version: GNU Emacs 25.2.2 (x86_64-pc-linux-gnu, GTK+ Version 3.22.21) of 2017-09-22, modified by Debian)
I had originall had emacs version 47.0 (that was from dpkg -l emacs which showed that as a metapackage)
Server was new and never had it before.
I am not an emacs guru. I don't fiddle too much and I can just get around in it.
I set
tab-width 4
indent-tabs-mode nil
I tried it before setting tab-stop-list and then setting it to nil and to "4 8 12" and to "0 4 8" but it didn't change the behaviour I describe below. In fact none of the settings I changed seemed to affect anything for this.
I then tried searching for the problem, and I tried everything mentioned (c-basic-offset, standard-indent, etc) nothing seemed to help.
I am simply trying to edit conf files.
This is an example
settings.conf:
setting name {
param1=1
param2={
s1="test"
s2=5
}
}
however when I hit the tab key the behaviour is all over the place.
[a1]
setting name {
[a2]
param1=1
param2={
[a3]
s1="test"
s2=5
}
}
in [a1] - tab is 4 spaces - I can hit all day and its fine - perfect
in [a2] hitting tab from the start of the line:
first tab key inserts a tab (size of 4 spaces but backspace deletes it as a whole) and then 3 spaces
second tab key inserts 3 tabs (each the size of 4 spaces)
third tab key inserts 2 tabs (4 spaces size) and then 3 spaces
in [a3] hitting from the start of the line:
first tab key inserts a tab (size 4 spaces)
second tab key inserts a tab (4 spaces) and then 3 individual spaces
third tab key seems to move forward 1 space and converts the 3 individual spaces from before and its newly added 1 space to a tab character as backspace deletes a size of 4 spaces in 1 go
I have no idea what is going on and except for those settings mentioned above that I change through M-x customize I haven't touched anything else at all.
Only other thing I can say is I am running emacs on Ubuntu 18.04 (edit from 20.04 - my mistake, sorry) on a server I ssh too.
By C-h k I get the following:
TAB runs the command indent-for-tab-command (found in global-map),
which is an interactive compiled Lisp function in ‘indent.el’.
It is bound to TAB.
(indent-for-tab-command &optional ARG)
Indent the current line or region, or insert a tab, as appropriate.
This function either inserts a tab, or indents the current line,
or performs symbol completion, depending on ‘tab-always-indent’.
The function called to actually indent the line or insert a tab
is given by the variable ‘indent-line-function’.
If a prefix argument is given, after this function indents the
current line or inserts a tab, it also rigidly indents the entire
It works in 'text-mode" but I don't want to switch to 'text-mode' (in which it works) as I like the highlighting it does.
*Edit (from comment):
I need to edit files that are listed as .conf and .cnf. There are hundreds of them in total. Some are for internal applications. The .cnf file are for nagios, and the .conf files are for icinga
Any help is appreciated.
Thanks.

Indent multiple lines in Emacs

I am looking for shortcuts or functions to add one tab to all lines in the selection. Also how to reduce one tab to all lines in the selection?
There are multiple references for this. But I could not find one that mimics use of tab and shift-tab on selected text as in regular editors like geany. There one can select multiple lines and then use tab or shift-tab to move text left and right till one finds it best.
I found C-x tab <left> or <right> : this moves all lines in the selection to left or right one space at a time. C-5 C-x tab move it 5 spaces but then stops. But I want these lines to move tab spaces at a time while keeping the selection so that I can repeat or undo the process. How can I do that?
Basically, I need a function which I can call after selecting some lines. It should:
Detect the selected lines
On pressing a key (say 1 on num pad) it should move selected text to left by 5 spaces (and keeping the selection)
On pressing another key (say 3 on num pad), it should move selected text to right by 5 spaces (and keep selection)
The function should end on pressing ENTER.
Can above ability be added to C-x tab shortcut, which works exactly like that (with left and right keys) but it moves selected text only one space at a time.
I am looking for shortcuts or functions to add one tab to all lines in the selection.
First select a region.
C-SPC [set-mark-command]
Select region of lines, with the mark at beginning of first line and the point at the beginning of last last line (or vice versa), and then
C-x r t [string-rectangle]
C-q TAB [quoted-insert]
I found C-x TAB <left> or <right>: this moves all lines in the selection to left or right one space at a time.
Did you see on option for hitting S-<left> and S-<right>? That should do it for you, Shift + Right, perhaps only depending on what mode you are in and whether indent-tabs-mode is enabled.
If you use evil-mode, you have the key > that indents the current line or the selection to one level, according to the mode. I don't know how to make it insert tabs. By a quick look at the documentation by keywords (C-h d indent tab RET) it looks like we have the variable indent-tabs-mode:
indentation can insert tabs if this is non nil
More generally, this doesn't seem to suit your requirements but nearly in that it helps on indenting multiple lines in a row and repeatedly: indent-tools (on melpa) (my toy). It's meant for indentation-based files (so yaml, python,…) and it gives an hydra (which helps to repeat the actions) with the commands: indent or de-indent the current block of indentation, the paragraph, etc, and the same to comment, delete, fold, and move around blocks of indentation.

How can you clear or overwrite a line of text in DrRacket?

I would like to display text and then overwrite it (for simple progress bars, etc.). The usual trick of displaying a carriage return ("\r") works fine when running Racket in the terminal in Linux and Windows, but in DrRacket and GRacket the carriage return does not seem to move the cursor to the beginning of the line.
With this code as an example:
(for ([x 5])
(display "\r")
(display x)
(flush-output) ; The result is the same with or without this line
(sleep 0.1))
Running in the terminal results in a counter that overwrites itself; at the end only 4 is displayed in the terminal.
Running in DrRacket results in the numbers displaying and not being overwritten:
0
1
2
3
4
Is there a way to overwrite a line of text in the interactions window of DrRacket?
For an authoritative answer on this, you'll want to hear from Robby Findler on the racket users mailing list, (see https://lists.racket-lang.org/).
I'm about 85% certain that the interactions window doesn't do this: that is, allow you to overwrite already displayed text. If you wanted to do something like this, you'd probably want to create your own text window using the graphical toolbox. That way, you could alter the text in the window in any way you wanted.

De-indent region as rigid block

I want to move a region leftwards by one tab stop, as a rigid block (not changing indentation of internal lines).
Here's the quote from the relevant documentation, but I don't understand:
C-x TAB This command is used to change the indentation of all lines
that begin in the region, moving the affected lines as a “rigid” unit.
If called with no argument, the command activates a transient mode for
adjusting the indentation of the affected lines interactively. While
this transient mode is active, typing LEFT or RIGHT indents leftward
and rightward, respectively, by one space. You can also type S-LEFT or
S-RIGHT to indent leftward or rightward to the next tab stop (see Tab
Stops). Typing any other key disables the transient mode, and resumes
normal editing.
I'm not seeing a transient mode. How do I move a region to the previous tab stop?
Related answer, to un-indent by 4 spaces
This behaviour, of a transient mode, was introduced in Emacs 24.4. In this case the submitter was running 24.3.
On Emacs 24.3, indent-rigidly cannot shift forward or back "to the nearest tab stop". Instead it may only be used to shift by a given number of characters.
For example:
to shift the region to the left by 7 characters use C-u - 7 C-x <tab>
to shift the region to the right by 3 characters use C-u 3 C-x <tab>
I think your goal can also be achieved by 'rectangle operations'.
To move a text block to left by one tab stop, you can just delete a column of tabs in the left, then the text block will be moved automatically to left by the length of what have been deleted.
The steps to do so:
select the content you want to delete as region. Be aware of that the start point and end point of the region will be the rectangle's two vertexes.
issue \C-x r d, or M-x delete-rectangle.
And to move a text block to right by one tab stop, you can just insert a column of tabs before the text block.
same as above one. But now the rectangle's width should be 0 (that is, the start point and end point of the region is on the same column).
issue \C-x r t <TAB>, or M-x string-rectangle. Here <TAB> is the contents you want to insert, it can be anything else.

Indent several lines in Emacs

In my Emacs, space key can indent correctly 1 line. If I select several lines, and press space key, the indenting does not work.
By following this link, I try C-M-\ or C-M-q, but C-M deletes directly the whole block selected.
Here is my .emacs, could anyone help?
Select multiply lines, then type C-u 8 C-x Tab, it will indent the region by 8 spaces.
C-u -4 C-x Tab will un-indent by 4 spaces
If you want Emacs to correctly indent multiple lines, then the command is C-META \ also known as C-M-\. In other words, it's not Control - M, but Control - Meta - Backslash (Control + Alt + \ on most keyboards)
[Warning: This approach might lead to errors as mentioned in one of the comments. Iniviting suggestions to fix it.]
Steps to do indentation interactively.
Select the region to be indented.
C-x TAB.
Use arrows (← and →) to indent interactively.
Press Esc three times when you are done with the required indentation.
None of the above method worked for me except Kev's- and that is too verbose for my slow fingers.
For me, I can highlight the region and press Alt-left arrow . Strangely, even though Alt registers as meta in emacs, Esc-left arrow doesn't work.
Another method to indent several lines is just to use the commands to edit several lines: Edit multiple lines at once in Emacs.
Basically, select region and then C-x r t+Tab.