Preserving blanks
Forum rules
This forum is for discussing APL-related issues. If you think that the subject is off-topic, then the Chat forum is probably a better place for your thoughts !
This forum is for discussing APL-related issues. If you think that the subject is off-topic, then the Chat forum is probably a better place for your thoughts !
6 posts
• Page 1 of 1
Preserving blanks
Contributors to these forums seem to be quite keen to mix their questions and suggestions with session input and output without using the rather intrusive code boxes.
I've found that using a combination of copy (Ctrl+Ins) and paste (Shift+Ins) or the "Copy Object" and "Paste Object" tools with the following function does the trick.
The function takes a right argument of either a character matrix or a nested list of strings and returns the same structure but with leading and embedded blanks replaced by non-breaking space. Thanks to Peter-Michael for the suggestion.
pb←{⎕ML←0
⍵{
(↑⍣⍺)⎕UCS∘{
⊃⍵ 160+.×0 1=⊂⍵=32
}∘⎕UCS¨{(+/∨\' '≠⌽⍵)↑¨↓⍵}⍣⍺{⍵}⍵
}⍨1=≡⍵
⍝ Preserve leading and embedded blanks by converting them to
⍝ Prevent Dyalog Forums software from squashing everything down
⍝ to the left margin.
}
I know you could all write a better one and perhaps so could I but this works for me.
By the way I used it on this so the function would stay nice.
I've found that using a combination of copy (Ctrl+Ins) and paste (Shift+Ins) or the "Copy Object" and "Paste Object" tools with the following function does the trick.
The function takes a right argument of either a character matrix or a nested list of strings and returns the same structure but with leading and embedded blanks replaced by non-breaking space. Thanks to Peter-Michael for the suggestion.
pb←{⎕ML←0
⍵{
(↑⍣⍺)⎕UCS∘{
⊃⍵ 160+.×0 1=⊂⍵=32
}∘⎕UCS¨{(+/∨\' '≠⌽⍵)↑¨↓⍵}⍣⍺{⍵}⍵
}⍨1=≡⍵
⍝ Preserve leading and embedded blanks by converting them to
⍝ Prevent Dyalog Forums software from squashing everything down
⍝ to the left margin.
}
I know you could all write a better one and perhaps so could I but this works for me.
By the way I used it on this so the function would stay nice.
-
Phil Last - Posts: 628
- Joined: Thu Jun 18, 2009 6:29 pm
- Location: Wessex
Re: Preserving blanks
The other option is to paste or type your APL code into the Forum's edit field, select that block of text in which you wish to preserve blanks, and click on the APLCode button which should appear at the end of the row of buttons immediately above the edit field.
Doesn't have to be APL code .. all it does is force the selected text to be put in a <pre> .. </pre> block, so all spacing should be preserved. I have set it up at the moment so that the first line which you enter is preceded by 6 spaces; I'm not sure that was such a good move though - I could be easily persuaded to remove those 6 spaces, and with the agreement of anyone who has used the APLCode feature, sort out the text layout in their posts.
And if you don't see the APLCode button, let me know .. having checked in your User Control Panel -> Board Prefernces -> Edit Posting Defaults and ensuring that BBCodes are enabled by default.
Doesn't have to be APL code .. all it does is force the selected text to be put in a <pre> .. </pre> block, so all spacing should be preserved. I have set it up at the moment so that the first line which you enter is preceded by 6 spaces; I'm not sure that was such a good move though - I could be easily persuaded to remove those 6 spaces, and with the agreement of anyone who has used the APLCode feature, sort out the text layout in their posts.
And if you don't see the APLCode button, let me know .. having checked in your User Control Panel -> Board Prefernces -> Edit Posting Defaults and ensuring that BBCodes are enabled by default.
-
AndyS|Dyalog - Posts: 257
- Joined: Tue May 12, 2009 6:06 pm
Re: Preserving blanks
Contributors to these forums seem to be quite keen to mix their questions and suggestions with session input and output without using the rather intrusive code boxes.
I've found that using a combination of copy (Ctrl+Ins) and paste (Shift+Ins) or the "Copy Object" and "Paste Object" tools with the following function does the trick.
The function takes a right argument of either a character matrix or a nested list of strings and returns the same structure but with leading and embedded blanks replaced by non-breaking space. Thanks to Peter-Michael for the suggestion.
I know you could all write a better one and perhaps so could I but this works for me.
By the way I used it on this so the function would stay nice.
I've found that using a combination of copy (Ctrl+Ins) and paste (Shift+Ins) or the "Copy Object" and "Paste Object" tools with the following function does the trick.
The function takes a right argument of either a character matrix or a nested list of strings and returns the same structure but with leading and embedded blanks replaced by non-breaking space. Thanks to Peter-Michael for the suggestion.
- Code: Select all
pb←{⎕ML←0
⍵{
(↑⍣⍺)⎕UCS∘{
⊃⍵ 160+.×0 1=⊂⍵=32
}∘⎕UCS¨{(+/∨\' '≠⌽⍵)↑¨↓⍵}⍣⍺{⍵}⍵
}⍨1=≡⍵
⍝ Preserve leading and embedded blanks by converting them to
⍝ Prevent Dyalog Forums software from squashing everything down
⍝ to the left margin.
}
I know you could all write a better one and perhaps so could I but this works for me.
By the way I used it on this so the function would stay nice.
-
Phil Last - Posts: 628
- Joined: Thu Jun 18, 2009 6:29 pm
- Location: Wessex
Re: Preserving blanks
My apologies but I hit the wrong button. My intention was to preview what I submitted.
If you can change this stuff would it be possible to change the look of the code box and get rid of the header line that says "Code: Select all"? It overwhelms anything but a large block of code.
If you can change this stuff would it be possible to change the look of the code box and get rid of the header line that says "Code: Select all"? It overwhelms anything but a large block of code.
-
Phil Last - Posts: 628
- Joined: Thu Jun 18, 2009 6:29 pm
- Location: Wessex
Re: Preserving blanks
Further apologies required. I never noticed the "[ APLCode ]" button at the right end of the row and used the "[ Code ]" button near the left. The "[ APLCode ]" button does the trick except the leading six blanks as you say. If I paste in the ⎕CR of a function it offsets the header line by six blanks ignoring the one that was already there.
But otherwise well done!
It turns out I can correct for the offset by putting a non-breaking space alone on the first line and start my function on the next but that isn't really the point, is it?
But otherwise well done!
It turns out I can correct for the offset by putting a non-breaking space alone on the first line and start my function on the next but that isn't really the point, is it?
-
Phil Last - Posts: 628
- Joined: Thu Jun 18, 2009 6:29 pm
- Location: Wessex
Re: Preserving blanks
My only excuse for putting those 6 spaces in was that it seemed like a good idea at the time.
Memo to self: stop trying to be clever.
I have removed the 6 spaces, and over the next few days with the agreement of the original posters I'll fix up any posts that now have incorrect formatting as a result of this change. If anyone would rather that I didn't, then please can they drop me an email. I could be persuaded to rename "APLCode" to something a but more general, but what appears on the button is what has to be typed in the "[]"s .. JohnS suggested using "Pre" but I wonder if that's a little too HTML-centric ?
The other huge benefit of using the APLCode route is that you can copy and paste APL code into a Dyalog APL session and have it run. With the non-breaking space (U+00A0) you will get a large number of unexpected SYNTAX ERRORs. I've logged a suggestion for this, but the full list to consider would be something like:
Update later that evening: not as simple as I first thought .. I've put those 6 spaces back in, and will investigate why any leading spaces after the [APLCode] are removed ..
Memo to self: stop trying to be clever.
I have removed the 6 spaces, and over the next few days with the agreement of the original posters I'll fix up any posts that now have incorrect formatting as a result of this change. If anyone would rather that I didn't, then please can they drop me an email. I could be persuaded to rename "APLCode" to something a but more general, but what appears on the button is what has to be typed in the "[]"s .. JohnS suggested using "Pre" but I wonder if that's a little too HTML-centric ?
The other huge benefit of using the APLCode route is that you can copy and paste APL code into a Dyalog APL session and have it run. With the non-breaking space (U+00A0) you will get a large number of unexpected SYNTAX ERRORs. I've logged a suggestion for this, but the full list to consider would be something like:
- space U+0020
no-break space U+00A0
figure space U+2007
narrow no-break space U+202F
word joiner U+2060
zero width no-break space U+FEFF
Update later that evening: not as simple as I first thought .. I've put those 6 spaces back in, and will investigate why any leading spaces after the [APLCode] are removed ..
-
AndyS|Dyalog - Posts: 257
- Joined: Tue May 12, 2009 6:06 pm
6 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group