intelligent tab and bracket placement |
Site Admin
|
Hi Jeff,
All you said is just excellent and with pretty good examples. Although I'd like to see your comments about the following 1. suppose we have code like this
where would closing bracket be inserted ? I suspect it would be placed under i in if. Right ? 2. suppose we have code like this
how would the bottom line be formatted if I press TAB ? I suspect the leftmost w would be two spaces on right than i in if. Right ? 3. suppose we have code like this
how would the bottom line be formatted if I press TAB ? and finally how does TAB work if there is some text selected in the editor ? |
||||||||||||||||||
|
|
hi ddmitrie,
thanks for the compliments and i will try to answer your questions. first please let me apologize for not returning your email right away.. it's been a combination of being busy for the holiday season and avoiding the detail of going back through and answering your question.. please excuse me.. i will answer the current question since i didn't tell you about php-mode before (see below) and i owe you an answer. however, please note that for me to experiment with emacs's php-mode behavior and then record it all here in the forum with bbcode is rather time intensive for me and most-likely quite error-prone. also, my response time sux (as you can see so maybe it might be better/faster/more accurate for you to load and use emacs (with php-mode) directly to get answers to these types of questions? again, i should have said this in the first place, sorry.. emacs's main web site is at http://www.gnu.org/software/emacs/emacs.html and if you hunt around you can find several windows versions (free and commercial). there are also many different pre-packaged versions. for instance, on my redhat-linux 9, i use a compilation/distribution of emacs which comes with that os (version 21.2.1), distributed by its vendor... regarding php-mode: as you probably know (and i am weak here so please correct me anyone), emacs is itself written in a variant of the artificial intelligence language LISP -- the variant being called 'e-lisp'. furthermore, the various 'modes' for emacs are also written in e-lisp. also, they are most often contributed by third parties. php-mode for emacs is such a third-party contribution and its project is on the web at http://sourceforge.net/projects/php-mode/ for instance.. there you can talk to its authors and ask them any questions you may have, read their forums, etc. okay, here's best answers i can give for your questions... hope they help.. 1) suppose the 'i' in 'if' is one indent in (2 spaces before it). generally the '}' will go under the 'i' in 'if' regardless of where your zzzzzzzzzzz and wwwwwww lines are. however, long before you get to this point, php-mode will not like it that you have yyyyyyyyyyyy code after the '{' and will have told you this by not indenting the zzzzzzzzzzz or wwwwwwwwwww lines correctly. instead, when you hit TAB on the zzzzzzzzz or wwwwwwww lines (or hit ';' at the end -- same behavior as TAB), it will indent the zzzzzzzzz line only 1 space --- not 4 spaces. this tells you that php-mode is having a problem with something --- in this case the yyyyyy stuff. if you move yyyyy down to the next line, then with each line you hit TAB or finish off with a ';', these lines will now be moved 4 spaces in (2 indents) which is correct. regardless of whether the yyyyy is there and regardless of whether the zzzzzzzz and wwwwwww lines are correctly indented, the closing bracket ('}') will be inserted directly udner the 'i' in 'if' --- and this is regardless of where you are on the line at the time you hit '}'. 2) this is a similar question to 1, above. again, under most circumstances, your zzzzz line ('b=1;') would have a ';' at the end, and so would have been properly indented automatically by the time you got to the www line ('c=1;'). however, if like above, i go back up and forcefully un-indent the zzzzzzzz and wwwww lines:
and then hit TAB then under this condition php-mode gives me error feedback by indenting the 'c' line only one space -- not 4, as it should be:
again, this is the way the php-mode tells me the user that something is bogus and it doesn't know what to do and i should fix it. at this point i realize b line is wrong, i go back up 1 line and hit TAB:
which indents b line correctly. then i go down to the c line and hit TAB and now we're all lined up correctly again:
then i go to end of line (after semi-colon):
and hit RETURN and i'm back in business right where i need to be again to continue typing:
( i should also mention that besides indenting single lines, php-mode can auto-indent the whole buffer with the 'Ctrl-x h ESC Ctrl-\' command -- rather awkward and i keep the dang thing on a post-it note on my screen BUT i use it when i've screwed up so badly on my code (not just a line or two above but somewhere further up that i can't find) that i need to auto-indent the whole buffer to find it: the error is then easy to find, again because where the indenting stops working correctly is most likely where i did something bizarre.) 3) when i try the following under emacs php-mode:
and then hit ';', again, the mode puts the d line out only 1 character. again, php-mode's way of telling me it doesn't grok what i did on the line before. the problem is not with the <?php but with the fact that i forcefully removed the indentation on the 'b' line:
now, if i get to your question by going to the beginning of the 'd' line and erasing the space:
and now moving over to between the 'd' and the '=' (middle of wwwwww line as you have it):
and i now hit TAB, it is the same behavior as i just had with the ';': php-mode again indents the line only 1 space out:
again: php-mode's way of saying, 'hey dude, something's not write on one or more lines above). so finally, again, same behavior may be 'fixed' by going up one line (to b line) hitting TAB:
and then coming back down to the d line:
and hitting TAB again. at that point, d will space out properly and we're back in business:
4) TAB works correctly on the code whether or not code is 'selected' (there are two different ways to 'select' code in emacs -- behavior is same regardless). i hope this helped.. please let me know what i've left out or obfuscated.. yours, jeff |
||||||||||||||||||||||||||||||||||||||||
|
|
here's best answers i can give for your questions... hope they help..
|
||||||||||||
|
intelligent tab and bracket placement |
|
||
Content © NuSphere Corp., PHP IDE team
Powered by phpBB © phpBB Group, Design by phpBBStyles.com | Styles Database.
Powered by
Powered by phpBB © phpBB Group, Design by phpBBStyles.com | Styles Database.
Powered by