Indent as Tabs?

Post any comments, suggestions, annoyances or ideas for future releases here. Please do not post bug reports or questions here.
Post Reply
egrath
Posts: 14
Joined: Thu Sep 02, 2004 4:48 am
Location: In the Alps of Austria

Indent as Tabs?

Post by egrath » Fri Oct 29, 2004 1:58 pm

Hi,

i have a problem setting up zeus in a way that it accepts my coding style :)

When writing code which contents Braces i am in the choice of letting Zeus create the closing
bracet or write it at my own. I always do the latter thing because i simply don't like this
functionality. However, i always have "Smart Indenting" activated so that the cursor stays on
the same line column position when i hit Enter as the previous line begins.

But heres what drives me crazy:

When on this new line i will write the closing bracet i have not simply hit
backspace one time (to jump back one tabstop) but to press backspace as many times because
the area from the beginning of the line till the cursor position has been filled with
whitespaces from zeus. I don't know if this is a feature or a bug.

To show you what i mean, please take a look at the following example:

Code: Select all

if( x == 3 ) {		| Line 1
    dosomethin();	| Line 2
}			 		 | Line 3
When pressing enter on the end of Line 2, the cursor will be below the 'd' on Line 3
Now i want to close the bracet by simply pressing Backspace on time and the cursor should
go back below the 'i' of Line 1 - but it simply goes back one character.

Is it possible to set this behavior up anywhere? (Maybe a option like "Indent as Tabs"...)

Another good feature would be if i write a bracet on Line 3 without pressing Backspace or

anything else that the bracet is automaticaly positioned below the 'i' of Line 1

And also another good feature (imho) would be if i press enter at the end of Line 1, that
the cursor jumps automaticaly forward one tab (cursor positioned below the 'x' of Line 1)

I hope that the text above is understoodable, because my english is a very poor.

Thanks,


Egon

jussij
Site Admin
Posts: 2449
Joined: Fri Aug 13, 2004 5:10 pm

Post by jussij » Fri Oct 29, 2004 5:35 pm

Hi Egon,
i have a problem setting up zeus in a way that it accepts my coding style [Smile]
If you use the Zeus templates, with a little configuration it should be possible to configure Zeus to handle almost any coding :)

For more information see the Coding faster with templates tip.
But heres what drives me crazy:

When on this new line i will write the closing bracket i have not simply hit backspace one time (to jump back one tabstop) but to press backspace as many times because the area from the beginning of the line till the cursor position has been filled with whitespaces from zeus. I don't know if this is a feature or a bug.
This is a feature :)

But seriously, this is definitely a feature of Zeus. The term smart indent means Zeus does try to be smart about the indent :) When you hit the enter key Zeus will fill the whitespace gap using the same whitespace as used in the line above. This feature is very important for some languages like Python where it is a syntax error if you mix spaces and tabs.

Code: Select all

Is it possible to set this behavior up anywhere? (Maybe a option like "Indent as Tabs"...)
Zeus is fully scriptable with the choice of several macro scripting languages. With a macro script to replace the current backspace behaviour any functionality should be possible :)

For a quick introduction into macro scripting see the Binding a Macro to the Keyboard tip. There are also several example macros in the zMacros directory

I wrote the following very quick, lightly tested Zeus Lua macro that should do something similar to what you describe:

Code: Select all

function key_macro()
  screen_update_disable()

  -- Get a copy of the current line
  local text = get_line_text()

  -- look for an empty line of text
  if string.len(text) == 0 then
-- this is debug only shown in status bar
message ("empty");
      -- position the cursor
      MoveLineDownAndFirst()
      MoveLineUp()
  else
-- this is debug only shown in status bar
message ("normal");
      -- just do a normal backspace
      Backspace()
  end

  screen_update_enable()
  screen_update()
end

key_macro() -- run the macro
Basically this macro uses the fact that a smart indented line contains no text until a character is typed. So this macro test for an empty line and if one is found it does a special backspace usign the line below as a guide, otherwise it just does a normal backspace.

But not that any functionality could be code here. For example it might be better to have a macro like this instead:

Code: Select all

function key_macro()
  screen_update_disable()

  -- Get a copy of the current line
  local text = get_line_text()

  -- look for an empty line of text
  if string.len(text) == 0 then
-- this is debug only shown in status bar
message ("empty");
      -- remove the empty line
      LineDelete()
      MoveLineHome()
      MoveWordNext()
  else
-- this is debug only shown in status bar
message ("normal");
      -- just do a normal backspace
      Backspace()
  end

  screen_update_enable()
  screen_update()
end

key_macro() -- run the macro
Another good feature would be if i write a bracket on Line 3 without pressing Backspace or anything else that the bracket is automatically positioned below the 'i' of Line 1
Zeus does not try to do this, because all languages are different, and one languages brace character is a another languages parenthesis. IMHO Zeus is already very configurable, to a point where is is getting difficult to use because it is too configurable :(

But once again I think this would be fairly easy to script using a Zeus macro. I will leave you this one to write as an exercise in Zeus scripting :)
And also another good feature (imho) would be if i press enter at the end of Line 1, that the cursor jumps automatically forward one tab (cursor positioned below the 'x' of Line 1)
There is a Zeus macro function called is_eol() which returns true if the cursor is at the EOL so once again by using this function it should be fairly easy to write a simple macro to replace the default enter functionality.
I hope that the text above is understoodable, because my English is a very poor.
I would say you English is very good and very easy to understood.

If I had to reply in anything but English I would be lost :)

Cheers Jussi

egrath
Posts: 14
Joined: Thu Sep 02, 2004 4:48 am
Location: In the Alps of Austria

Post by egrath » Fri Oct 29, 2004 7:46 pm

Hi Jussi,

thank you very much for your reply.

I didn't thought about the scripting capabilites of zeus before posting. With this i will definitly get Zeus to satisfy my Coding preferences.

Bye, Egon

egrath
Posts: 14
Joined: Thu Sep 02, 2004 4:48 am
Location: In the Alps of Austria

Post by egrath » Fri Oct 29, 2004 11:22 pm

Hi again,

wow, it's very impressive what can be done with scripting the editor 8)
I've written a Small C Macro to satisfy my needs. Maybe its interesting for other people too, so i post a link here:

http://www.systemv.net/zeus/zeus.html

Bye, Egon

jussij
Site Admin
Posts: 2449
Joined: Fri Aug 13, 2004 5:10 pm

Post by jussij » Sat Oct 30, 2004 3:14 am

Hi Egon,
wow, it's very impressive what can be done with scripting the editor [Cool]
The Zeus scripting is not too bad hey :D

I have lots of little scripts that get used all the time.
I've written a Small C Macro to satisfy my needs. Maybe its interesting for other people too, so i post a link here:
That is a nice macro for your first ever Zeus macro :)

Once you get the hang of it, writing macros is pretty easy.

But there are just a few things I will say. First there is a small bug in you script because it will fail when there is no file open or the file is marked as read only. You can fix this easily using the following scripting code logic:

Code: Select all

-- macro only works for documents
local document = is_document()

-- macro only works for read/write documents.
local locked = is_read_only()

if (locked == 1) or (document == 0) then
  -- let the backspace handle the unexpected case
  Backspace()
else
  -- this is where the new code goes
  ........
end
Secondly, I notice that you have choosen to use the SmallC language.

The SmallC language is very simple to code and is probably the fastest of all the scripting choices. All in all it is not a bad langauge to use. But I have to say this because I wrote the SmallC language :)

Seriously, SmallC is not a bad scripting language, but be warned it is not a real scripting language like Python, Lua, Java Script etc. The SmallC works very well for short, simple scripts, but if you make your scripts too complicated they can easliy break the SmallC interpreter :(

So only use the SmallC for simple scripts. For any complicated scripting it is better to use one of the other scripting languages.

Cheers Jussi

amix

Does not Compute

Post by amix » Wed Apr 13, 2005 2:37 pm

This script does not work for me.

I use Zeus 3.94a evaluation and all the script does (the one from the URI linked) is nothing. I do not get any info in the macro-debugger either, except:

About to execute 'C:\Programme\zfw\zScript\AdvancedBackspace.zm' macro file
Debug: Initialising macro interface
Debug: Destroying macro interface
Macro produced '3' Warning(s), Error(s) and/or Debug(s) messages.

I also added jussij's addendum and tried also without.

Guest

Post by Guest » Wed Apr 13, 2005 11:44 pm

This script does not work for me.
My guess is the script file you created has got the wrong file extension :?:

To test Egon script this is what I did:
  1. Copied the text from Egon web page
  2. Created a file call c:\temp\backspace.zm and paste the script into this file
  3. Created a new file and type in some random text
  4. To run the macro I used the Macros, Execute menu and type in the c:\temp\backspace.zm file name
  5. At least for me the macro ran and the cursor move back one character
The final step in the configuration would be to copy the backspace.zm file to the zScript directory and bind it to the keyboard.
I use Zeus 3.94a evaluation and all the script does (the one from the URI linked) is nothing.

Because Zeus allows scripts to be written in several lanuages the extension given to the macro is very important as Zeus uses the extension to pick the correct scripting interpreter. An easy way to figure out the correct macro file extensions is to use the Macros, Load menu. This resulting macro open dialog display files for the currently active scripting module and also allows you to filter for the macro extensions of the other installed scripting modules.

Jussi

Post Reply
kuchnie warszawa opinie

Who is online

Users browsing this forum: No registered users and 6 guests