LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Blogs > robertvi
User Name
Password

Notices

Rate this Entry

Kate indentation

Posted 09-27-2010 at 06:36 AM by robertvi
Updated 08-01-2011 at 12:11 PM by robertvi

One of the most annoying things for a programmer is a text editor which is trying to automatically
indent the source code in a different way than the coder wants. I use an editor called kate from the KDE project, and I'm currently trying to figured out what the heck is going on with automatic indentation, and thought I would document the process in the hope of helping someone else avoid this problem. I'm using Kate version 3.4.2. [Jump to the summary at the end if you're in a hurry]

Some relevant settings from the menus:
(1) Tools -> Indentation -> [None|Normal|Python|etc...]

(2) Settings -> Configure Kate -> Editor Component -> Editing -> General ->
(2a) Insert spaces instead of tabulators -> [on|off]
--and--
(2b) Tab width -> [number of characters]

(3) Settings -> Configure Kate -> Editor Component -> Editing -> Indentation ->
(3a) Default indentation mode -> [None|Normal|Python|etc...]
--and--
(3b) Indentation width -> [number of characters]
--and--
(3c) Backspace key in leading blank space unindents -> [on|off]

(4) Settings -> Configure Kate -> Editor Component -> Open/Save -> Modes&Filetypes ->
Filetype: -> [Normal|Assembler/Asm6502|...long-list...|Sources/Zonnon] ->
Indentation mode -> [Use default|None|Normal|Python|etc...]

(5) Settings -> Configure Kate -> Application -> General ->
Keep meta-information past sessions -> [on|off]

(6) "Document variables" http://docs.kde.org/stable/en/kdesdk...variables.html
these seem to be configuration options which you write into the top (or bottom)
lines of your source files
eg insert the following as the first line of your source file:
// kate: space-indent on; indent-width 4; mixedindent off; indent-mode cstyle;

(7) Settings -> Configure Kate -> Application -> Plugins

(8) Unknown unknowns: "More variables may be added in the future"

From the kate docs (http://docs.kde.org/stable/en/kdesdk...riables.html):
<quote>
When reading configuration, katepart looks in the following places (in that order):

* The global configuration.
* Optional session data.
* The "Filetype" configuration.
* Document variables in the document itself.
* Settings made during editing from menu or command line.

As you can understand document variables has the next highest precedence. Whenever a document is saved, the document variables are reread, and will overwrite changes made using menu items or the command line.
</quote>

I like to have an indentation width of 4 characters, which I get by pressing tab and having the tab replaced by
4 space characters, and have the backspace key unindent by deleting 4 spaces when it's on a line containing only whitespace, so I want to have:

(2a) on
(2b) 4
(3b) 4
(3c) on

When I press enter for a new line I simply want the cursor to appear at the same indentation level as the previous line, not to do anything fancy like try to guess what indentation the new line will need. So I want:

(1) Normal - sets the behaviour for the current file only
(3a) Normal - sets the default behaviour
(4) Use default - for all filetypes I will be working with, tell kate to use the default

If you already have a set of files open, kate seems not to change the indentation mode unless you switch to each file and select (1) Normal. Even if the file type is set to use the default indentation mode, and the default indentation mode is Normal, kate seems to remember what mode was used with the file last time it was loaded. To force it to assign the default mode when the file is loaded tell kate to forget meta-information when you close the file:

(5) off

and then close all the files, close the editor, restart it and reopen all your files.

Remember also item (7), plugins have access to your settings. Go through and disable or configure any plugin which may be altering indentation behaviour. Make sure the files you edit do not have any document variables (6) (which can be stored anywhere in the first and last 10 lines of the file) which are changing indentation behaviour.

I hope this helps you out! Post a comment if you see any errors in my text.

=================Summary of the settings I use:==============

(1) Tools -> Indentation -> [None|Normal|Python|etc...]
**Normal**

(2) Settings -> Configure Kate -> Editor Component -> Editing -> General ->
(2a) Insert spaces instead of tabulators -> [on|off]
**on**
--and--
(2b) Tab width -> [number of characters]
**4**

(3) Settings -> Configure Kate -> Editor Component -> Editing -> Indentation ->
(3a) Default indentation mode -> [None|Normal|Python|etc...]
**Normal**
--and--
(3b) Indentation width -> [number of characters]
**4**
--and--
(3c) Backspace key in leading blank space unindents -> [on|off]
**on**

(4) Settings -> Configure Kate -> Editor Component -> Open/Save -> Modes&Filetypes ->
Filetype: -> [Normal|Assembler/Asm6502|...long-list...|Sources/Zonnon] ->
Indentation mode -> [Use default|None|Normal|Python|etc...]
**Use default - for all filetypes you will be working with**

(5) Settings -> Configure Kate -> Application -> General ->
Keep meta-information past sessions -> [on|off]
**off**

(6) "Document variables" http://docs.kde.org/stable/en/kdesdk...variables.html
these seem to be configuration options which you write into the top (or bottom)
lines of your source files
eg insert the following as the first line of your source file:
// kate: space-indent on; indent-width 4; mixedindent off; indent-mode cstyle;
**you'd probably already know if you had any document variables**

(7) Settings -> Configure Kate -> Application -> Plugins
**plugins have access to your settings**

(8) Unknown unknowns: "More variables may be added in the future"
**you maybe using a different version of kate**

===================Miscellaneous=================
Other things I do to configure kate:

Turn autocomplete off:
Settings -> Configure Kate -> Editor component -> Editor -> Autocompletion

Word wrap: this one looks like I can't configure it to do what I (and I suspect most people) would want. I want dynamic word wrap so my lines of latex don't go off the side of the page, but I don't want static word wrap where kate inserts actual new lines in my text. The problem is that dynamic word wrap seems to mess up scrolling for long lines. I recall experiencing this problem once when I first started using kate for writing latex, but now the problem is back again and I've no idea how to fix it.

The problem is that with a paragraph (a single long line as far as kate is concerned) being dynamically wrapped kate still treats this as one line for scrolling purposes, and therefore instead of being able to position the part of the text I need to edit, I see the text jerking about erratically by increments of entire paragraphs. This is apparently by design and not a bug, read the lame reasoning behind this decision here:

https://bugs.kde.org/show_bug.cgi?id=256561
Posted in Uncategorized
Views 6931 Comments 0
« Prev     Main     Next »
Total Comments 0

Comments

 

  



All times are GMT -5. The time now is 06:40 PM.

Main Menu
Advertisement

My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration