Does anyone know if there is a way to indent/unindent a group of lines
instead of one by one? For example it would be nice if I could highlite and press TAB. Also how can I nest comments? Sometimes I have to save my code which has a compile error but I need to run. The only way to do it is by commenting it out. But if there is a comment inside the code I have to go and remove the other double quotes. Is there some neat trick that works for this situation? Happy New Year Costas Menico |
Costas,
> Does anyone know if there is a way to indent/unindent a group of lines > instead of one by one? For example it would be nice if I could > highlite and press TAB. The RichTextEdit that OA use to provide the editing in Dolphin is, basically, a word processing editor as opposed to a text processing editor (as in a "programmers" text editor). Because of this, and as far as I can see, moving blocks of text around is always done by increasing/decreasing margin sizes and not by inserting/removing tabs. I agree that the ability to indent/outdent selections is something that is missing in the Dolphin editor though. It's one of those thing that you mindlessly work around and don't realise how much you would use it until someone points out that it is missing <g> Adding the actual indent/outdent code appears to be quite easy (as long as you don't want to indent/outdent multiple spaces as well as tabs) SmalltalkWorkspace>>indent | currentText newText start | (currentText := self selection) isEmpty ifTrue: [^self]. start := self selectionRange first. newText := currentText copyReplaceAll: String lineDelimiter with: String lineDelimiter, String tab. newText := String tab, newText. self replaceSelection: newText. self selectionRange: (start to: start + newText size) SmalltalkWorkspace>>outdent | currentText newText start | (currentText := self selection) isEmpty ifTrue: [^self]. start := self selectionRange first. newText := currentText copyReplaceAll: String lineDelimiter, String tab with: String lineDelimiter. (newText indexOfSubCollection: String tab) = 1 ifTrue: [newText := newText copyFrom: String tab size + 1]. self replaceSelection: newText. self selectionRange: (start to: start + newText size) A simple way of automatically integrating into the working environment is a bit more difficult. For the time being I've settled on just modifying the ClassBrowser.Default view's edit menu bar (just add two commands that send #indent and #outdent with accelerators of your choice). Hopefully OA might consider something like this as a permanent addition to the image? > Also how can I nest comments? Sometimes I have to save my code which > has a compile error but I need to run. The only way to do it is by > commenting it out. But if there is a comment inside the code I have to > go and remove the other double quotes. Is there some neat trick that > works for this situation? That one bugs me as well but I can't think of an easy solution. > Happy New Year And the same to you and anyone else browsing past. Ian |
"Ian Bartholomew" <[hidden email]> wrote in message
news:92mu7q$7e6ef$[hidden email]... > > Also how can I nest comments? Sometimes I have to save my code which > > has a compile error but I need to run. The only way to do it is by > > commenting it out. But if there is a comment inside the code I have to > That one bugs me as well but I can't think of an easy solution. This is related to the suggestion I posted to my web site and mentioned the other day about possibly saving methods even though they do not compile (turn them red, as happens now when moving (copying) a method to another class where it will not compile, or loading a package). My concern was that this could be dangerous as the default action if it replaces an important system method with a version which does not work. Perhaps a context menu item to 'yes, really save it, even if it doesn''t compile' would be a way to handle this? That way you wouldn't be surprised by replacing an important method with a non-functional version, but you could force your work-in-progress to be remembered when you wanted to. -- Frank [hidden email] |
In reply to this post by Ian Bartholomew
Ian
You wrote in message news:92mu7q$7e6ef$[hidden email]... > ... > Adding the actual indent/outdent code appears to be quite easy (as long as > you don't want to indent/outdent multiple spaces as well as tabs) > ...[clever code snipped]... Clever idea. I hadn't thought of using simple string replacement to do it. As you say, it's not as sophisticated as the indent/outdent capabilities in, for example, Visual Studio, but a lot better than nothing. > > A simple way of automatically integrating into the working environment is a > bit more difficult. For the time being I've settled on just modifying the > ClassBrowser.Default view's edit menu bar (just add two commands that send > #indent and #outdent with accelerators of your choice). > > Hopefully OA might consider something like this as a permanent addition to > the image? Yes, I think we might. What accelerator keys would you prefer? I was thinking of Ctrl-< and Ctrl-> for outdent and indent respectively. > > Also how can I nest comments? Sometimes I have to save my code which > > has a compile error but I need to run. The only way to do it is by > > commenting it out. But if there is a comment inside the code I have to > > go and remove the other double quotes. Is there some neat trick that > > works for this situation? > > That one bugs me as well but I can't think of an easy solution. Unfortunately standard Smalltalk does not allow nested comments - although the ANSI standard was a recent effort, even then the need was not identified. The rational for this was bunkum as I recall. Anyway short of a language extension, one way to comment out code with comments in it is to wrap it all up as a block which is not then evaluated. This is not ideal because the block is still created (even though it is not used the compiler does not optimize it away), and visually it does not look like a comment. Nevertheless it is sometimes a handy trick when debugging. Regards Blair |
Blair,
> Yes, I think we might. What accelerator keys would you prefer? I was > thinking of Ctrl-< and Ctrl-> for outdent and indent respectively. When I try to set them in a menu these get displayed as Ctrl+Shift+, and Ctrl+Shift+, respectively so might it not, and you might have meant this anyway, be better to lose the Shift and just use Ctrl+, and Ctrl+. I'm assuming that everones keyboard is laid out like mine with < as shifted , and > as shifted . A false assumption??? > Nevertheless it is sometimes a handy trick when debugging. I hadn't thought of using the block trick before - neat. It doesn't help much if you're still at the compilation stage and want to comment out a block because it won't compile but it certainly helps when commenting out during debugging. Ian |
In reply to this post by Ian Bartholomew
Ian,
> [re: commenting out comments] > That one bugs me as well but I can't think of an easy solution. Why not change every " into "" (i.e. double-up every included occurence of a double quote) ? -- chris |
I wrote:
> Why not change every " into "" (i.e. double-up every included occurence > of a double quote) ? Ugly (and barely tested) code: =============== SmalltalkWorkspace>>encomment "comment-out the currently selected text (if any)" | currentText newText start | (currentText := self selection) isEmpty ifTrue: [^self]. start := self selectionRange first. "have to deal with embedded comments" newText := currentText copyReplaceAll: '"' with: '""'. newText := '"' , newText , '"'. self replaceSelection: newText. self selectionRange: (start to: start + newText size) =============== SmalltalkWorkspace>>decomment "undo the commenting-out of the currently selected text (if any)" | currentText newText start leadingWS trailingWS index body | (currentText := self selection) isEmpty ifTrue: [^self]. start := self selectionRange first. "reverse the doubling-up of embedded comments" newText := currentText copyReplaceAll: '""' with: '"'. "strip out the first and last non-whitespace quotes" body := newText trimBlanks. index := newText indexOfSubCollection: body. leadingWS := newText copyFrom: 1 to: index - 1. trailingWS := newText copyFrom: index + body size to: newText size. (body notEmpty and: [body first = $"]) ifTrue: [body := body rightString: body size - 1]. (body notEmpty and: [body last = $"]) ifTrue: [body := body leftString: body size - 1]. newText := leadingWS , body , trailingWS. self replaceSelection: newText. self selectionRange: (start to: start + newText size) =============== -- chris |
In reply to this post by Blair McGlashan
"Blair McGlashan" <[hidden email]> wrote:
> >> > Also how can I nest comments? Sometimes I have to save my code which >> > has a compile error but I need to run. The only way to do it is by >> > commenting it out. But if there is a comment inside the code I have to >> > go and remove the other double quotes. Is there some neat trick that >> > works for this situation? >> >> That one bugs me as well but I can't think of an easy solution. > >Unfortunately standard Smalltalk does not allow nested comments - although >the ANSI standard was a recent effort, even then the need was not >identified. The rational for this was bunkum as I recall. Anyway short of a >language extension, one way to comment out code with comments in it is to >wrap it all up as a block which is not then evaluated. This is not ideal >because the block is still created (even though it is not used the compiler >does not optimize it away), and visually it does not look like a comment. >Nevertheless it is sometimes a handy trick when debugging. Blair, I like the idea using [] to simulate comment wrapping. But if I may ask. Since the ANSI standard doesn't dissalow of adding a new comment delimiter, why not have a Pascal or C style comments where you can use something like: {* *} On the comments issue you are suggesting Ctl-> and Ctrl-< for code indent. What is the problem with using TAB and Shift-TAB. The reason I would prefer this is that it's the default in Visual Studio. Also JBuilder defaults to that. But in any case it should be easily customized by the programmer. Regards, Costas |
Free forum by Nabble | Edit this page |