Dear DIALOG2 popup developer,
I have a problem ;)
I want to insert a character which could have several names like
↓ arrow down ← arrow left ↑ arrow up α greek alpha β greek beta
My aim is to write e.g. "arrow" and the popup dialog shows all arrow matches (only the glyph). Then I want to choose one and instead of inserting "arrow" it should insert the chosen glyph. Fine. I tried it and I had partly success.
#### First problem: for the suggestions I have to write: {display="↓";match=down;},{display="↓";match=arrow;}
this leads, of course, to having two ↓ in the list. Why not write: {display="↓";matches=("down","arrow");}
In other words to allow more than one match.
#### Second problem: If I want to do that I have to use the options -w for wait, because I want to replace e.g. "arrow" by my chosen glyph. Fine. But if I delete 5 characters to show all suggestions I do not see what I'm writing whereby the popup menu does its job perfectly.
#### Third problem: If I type e.g. "arr" the popup dialog finds all matches beginning with "arr". But it would be nice to have an option to show only those items matching exactly. E.g. I have to type "arrow" to show all 'arrow's not only "a" or "ar" etc.
########## Here's a first naïve example command: Input: Selected Text or Word Output: Replace Selected Text Command:
RES=$(echo '{suggestions=({display="↓";match=down;}, {display="↓";match=arrow;},{display="↑";match=arrow;}, {display="←";match=arrow;},{display="α";match=greek;}, {display="α";match=alpha;},{display="β";match=greek;}, {display="β";match=beta;});}' | "$DIALOG" popup -iwf "$TM_CURRENT_WORD")
RES=$(echo "$RES" | grep display | perl -Xpe 's/.*?display = "(.*?)";/ $1/;s/\U([0-9A-F]+)/chr(hex($1))/iesg;')
echo -n "$RES"
My overall aim is to provide a possibility to insert a glyph by looking for words in its Unicode name.
Or is the DIALOG2 popup dialog not the right tool for it, meaning should one write its own rountine for that? Or is there a better way to do it?
Thanks a lot for any hints in advance!
--Hans
Hi,
On 16.04.2008, at 17:31, Hans-Joerg Bibiko wrote:
I want to insert a character which could have several names like
↓ arrow down ← arrow left ↑ arrow up α greek alpha β greek beta
My aim is to write e.g. "arrow" and the popup dialog shows all arrow matches (only the glyph). Then I want to choose one and instead of inserting "arrow" it should insert the chosen glyph. Fine. I tried it and I had partly success.
I believe that the approach à la 'HTML > Insert Entity' would fit better. But anyway, the three problems could be more general in some sense.
--Hans
On 16 Apr 2008, at 12:39, Hans-Jörg Bibiko wrote:
I believe that the approach à la 'HTML > Insert Entity' would fit better. But anyway, the three problems could be more general in some sense.
I do not think that the popup system is ideal for what you are doing, so personally I would not make any changes to it to handle these situations without a more appropriate example where it fails.
For the first problem you could probably just use --extra-chars=' ' to be able to use the space inside the completion titles. I am not too sure what you are explaining for the second problem.
For the third problem, I have thought of and tested something that seems to work pretty well for this, but it’s really kind of a hack and I would like to avoid it if possible. Currently I think the best argument for implementing this is the obj-c completion, to be able to type out full selectors (where one has multiple parameters).
On 17 Apr 2008, at 06:17, Ciarán Walsh wrote:
On 16 Apr 2008, at 12:39, Hans-Jörg Bibiko wrote:
I believe that the approach à la 'HTML > Insert Entity' would fit better. But anyway, the three problems could be more general in some sense.
I do not think that the popup system is ideal for what you are doing
I agree. popup is made for narrow down completion "only".
For the first problem you could probably just use --extra-chars=' ' to be able to use the space inside the completion titles.
Well, this won't work. If I have match='arrow down', then I can type 'arrow d' but I cannot type 'down arr', because I want to search word- based regardless of the word order.
Second problem: If I want to do that I have to use the options -w for wait, because I want to replace e.g. "arrow" by my chosen glyph. Fine. But if I delete 5 characters to show all suggestions I do not see what I'm writing whereby the popup menu does its job perfectly.
I am not too sure what you are explaining for the second problem.
If I use popup without --wait popup will insert automatically the match string. But I want to insert my self-defined string. Thus I use --wait to get a plist of the chosen item, I parse it, and I insert/ replace what I want. But if I use --wait and I type something to narrow down the popup list - it works fine - but I do NOT see what I'm typing.
For the third problem, I have thought of and tested something that seems to work pretty well for this, but it’s really kind of a hack and I would like to avoid it if possible. Currently I think the best argument for implementing this is the obj-c completion, to be able to type out full selectors (where one has multiple parameters).
As I mentioned popup is made for narrow down completion "only". And this behaviour could be in some sense contra-productive.
Maybe the name "popup" describes not really the function it does quite well. Maybe "complete" would better fit(?) Also "menu" - why not "select". But this is marginal.
Anyway I will try to go an other way.
Thanks,
--Hans
On 17 Apr 2008, at 02:16, Hans-Joerg Bibiko wrote:
If I use popup without --wait popup will insert automatically the match string. But I want to insert my self-defined string. Thus I use --wait to get a plist of the chosen item, I parse it, and I insert/replace what I want. But if I use --wait and I type something to narrow down the popup list - it works fine - but I do NOT see what I'm typing.
Perhaps you have some local changes (e.g. still on 10.5 SDK?) because this works fine for myself and others. If you look at the ui.rb in Review/Support/lib it has a complete() method which uses the --wait option
On 17 Apr 2008, at 15:30, Ciarán Walsh wrote:
On 17 Apr 2008, at 02:16, Hans-Joerg Bibiko wrote:
If I use popup without --wait popup will insert automatically the match string. But I want to insert my self-defined string. Thus I use --wait to get a plist of the chosen item, I parse it, and I insert/replace what I want. But if I use --wait and I type something to narrow down the popup list - it works fine - but I do NOT see what I'm typing.
Perhaps you have some local changes (e.g. still on 10.5 SDK?) because this works fine for myself and others. If you look at the ui.rb in Review/Support/lib it has a complete() method which uses the --wait option
I checked out DIALOG2 again and compiled it on 10.5.2 SDK 10.4 (I didn't change anything).
I run all tests in /ui.rb. Each works brilliant (esp. the nested example - very nice!). Fine.
Then I wrote a tmCommand in Ruby using the complete() method. It works fine. But if I write an other tmCommand in BASH, it works but I do not see what I'm typing and the output behaviour is also different (it gives me back the plist as well).
Here the codes: BASH echo '{suggestions = ( {display = "abbauen";}, {display = "abarbeiten";}, {display = "ab";}, {display = "bringen";}, {display = "brachte";}, );}' | "$DIALOG" popup --wait --initial-filter "$TM_CURRENT_WORD"
RUBY #!/usr/bin/env ruby -wKU require ENV['TM_SUPPORT_PATH'] + '/lib/textmate.rb' require ENV['TM_SUPPORT_PATH'] + '/lib/ui.rb' @choices = [ {'display' => 'abbauen'}, {'display' => 'abarbeiten'}, {'display' => 'ab'}, {'display' => 'bringen'}, {'display' => 'brachte'}, ]
TextMate::UI.complete(@choices)
Attached are both scrits I used. Please check the BASH script if it works for you.
Thanks,
--Hans
On 17 Apr 2008, at 09:31, Hans-Joerg Bibiko wrote:
But if I write an other tmCommand in BASH, it works but I do not see what I'm typing and the output behaviour is also different (it gives me back the plist as well).
Since the --wait flag causes dialog not to return until a choice is made, you must run the command in the background so that control is returned to TextMate right away (the Ruby complete() API does this for you, and supports the block). i.e., try adding '&>/dev/null &' to the end of the command
On 17 Apr 2008, at 16:40, Ciarán Walsh wrote:
On 17 Apr 2008, at 09:31, Hans-Joerg Bibiko wrote:
But if I write an other tmCommand in BASH, it works but I do not see what I'm typing and the output behaviour is also different (it gives me back the plist as well).
Since the --wait flag causes dialog not to return until a choice is made, you must run the command in the background so that control is returned to TextMate right away (the Ruby complete() API does this for you, and supports the block). i.e., try adding '&>/dev/null &' to the end of the command
Yes. This works. But then I can write simply:
echo '...' | "$DIALOG" popup --initial-filter "$TM_CURRENT_WORD"
without --wait to have the same behaviour. It's seems to me that -- wait is useless in BASH(?)
Because, if I write:
echo '...' | "$DIALOG" popup --wait --initial-filter "$TM_CURRENT_WORD" &
it does not work. My intention also was to get back the selected item as plist and do something with it. But I must write &>/dev/null.
Thanks,
--Hans
On 17 Apr 2008, at 09:54, Hans-Joerg Bibiko wrote:
On 17 Apr 2008, at 16:40, Ciarán Walsh wrote:
On 17 Apr 2008, at 09:31, Hans-Joerg Bibiko wrote:
But if I write an other tmCommand in BASH, it works but I do not see what I'm typing and the output behaviour is also different (it gives me back the plist as well).
Since the --wait flag causes dialog not to return until a choice is made, you must run the command in the background so that control is returned to TextMate right away (the Ruby complete() API does this for you, and supports the block). i.e., try adding '&>/dev/null &' to the end of the command
Yes. This works. But then I can write simply:
echo '...' | "$DIALOG" popup --initial-filter "$TM_CURRENT_WORD"
without --wait to have the same behaviour. It's seems to me that -- wait is useless in BASH(?)
Because, if I write:
echo '...' | "$DIALOG" popup --wait --initial-filter "$TM_CURRENT_WORD" &
it does not work. My intention also was to get back the selected item as plist and do something with it. But I must write &>/dev/null.
See http://pastie.textmate.org/private/ontx9ap7jdensks4peffg for how you could get the result from the popup. What are you planning to do with it though? You could use e.g.
osascript -e'tell app "TextMate" to insert "foo" as snippet yes'
to insert a snippet based on the result.
On 17 Apr 2008, at 17:22, Ciarán Walsh wrote:
See http://pastie.textmate.org/private/ontx9ap7jdensks4peffg for how you could get the result from the popup.
Thanks a lot!! YES, of course. One can use a {} block. Sometimes I can't see the forest for trees ;)
--Hans
Hi,
maybe some of you wondered about this thread ;)
I would like to clarify it a bit.
My overall goal was to figure out whether it's possible to use this popup dialog in such a way that one can separate: what I'm seeing in the list, what I'm typing, and what I'm getting. I call it lookup mode.
Example:
{display="2" ; match="DIGIT TWO 2 NUMBER DOS DOIS ZWEI TWEE" ; insert="${1:you've chosen }2${0;}"; } | "$DIALOG" -ile ' '
option -l = lookup mode
If you invoke that you will see the normal popup list but with an header. The header title stores my keyboard events, because no keyboard event will send to TM, only to popup.
Now you can type any string in like "ois" and it find "2". If one types "ois digit" it also finds "2" because popup looks for CONTAINS "ois" AND CONTAINS "digit".
In other words you can insert a string by looking for its properties.
Well, what can you do with it? There are multifarious applications possible.
Here
http://www.bibiko.de/TM_DIALOG2_popup_lookup.mov (1M)
I show three simple examples. (This is only a prototype!!)
-insert a character by looking for its Unicode name -insert an HTML entity by looking for the character itself or by the entity name -Obj-C: It often occur to me that I want to insert a method let's say for NSString and I cannot remember how it begins, e.g. "stringWithUTFString". But I know that "utf" is in it. So I can use this lookup mode.
Further more one could use it as a tiny translator. display="work"; match="arbeiten" Thus I can search for "arbeit" and I get "work".
And so forth.
Furthermore there is an option -b which allow to look for the begin of words only inside "match".
But by doing this I have some limitations: 1) The size of my suggestions: Up to now I have to pipe it to DIALOG2 but this size is limited. Maybe it is worth to think about a mechanism to load a file containing the suggestions.
2) Dead keys: In lookup mode I allow to use OPTION+ to insert e.g. ß or ø. But if I want to use a dead key like OPTION+e u to get ú, well this is up to now not possible, because I do not how. One easy solution would be instead of using the header of the table to use a NSTextField which can handle it.
Well, to have that functionality in popup it only costs a very few lines of code more.
But the first question to all of you is whether it's worth to implement that lookup mode?
All the best,
--Hans
On 18 Apr 2008, at 14:27, Hans-Joerg Bibiko wrote:
But by doing this I have some limitations:
- The size of my suggestions:
Up to now I have to pipe it to DIALOG2 but this size is limited. Maybe it is worth to think about a mechanism to load a file containing the suggestions.
This is wrong. Of course, I can use cat instead of echo. I've just tried out to pipe a 1Mb file with 16500 suggestion to popup in lookup mode, and it works ;) The speed is also OK. I didn't yet optimized it ;) Up to now I'm using the NSPredicate regexp engine.
Cheers,
--Hans
On 18 Apr 2008, at 14:52, Hans-Joerg Bibiko wrote:
On 18 Apr 2008, at 14:27, Hans-Joerg Bibiko wrote:
But by doing this I have some limitations:
- The size of my suggestions:
Up to now I have to pipe it to DIALOG2 but this size is limited. Maybe it is worth to think about a mechanism to load a file containing the suggestions.
This is wrong. Of course, I can use cat instead of echo. I've just tried out to pipe a 1Mb file with 16500 suggestion to popup in lookup mode, and it works ;)
Yeah, there is an ARG_MAX define which tells the maximum size of environment variables and command arguments. I think it is around 64 KB.
Pipes of course are without such limits. This is also why it is generally preferred to take selection (for TM commands) as input rather than use TM_SELECTED_TEXT, at least for commands where it might be more than a few words/lines.
On 21 Apr 2008, at 17:39, Allan Odgaard wrote:
On 18 Apr 2008, at 14:52, Hans-Joerg Bibiko wrote:
On 18 Apr 2008, at 14:27, Hans-Joerg Bibiko wrote:
But by doing this I have some limitations:
- The size of my suggestions:
Up to now I have to pipe it to DIALOG2 but this size is limited. Maybe it is worth to think about a mechanism to load a file containing the suggestions.
This is wrong. Of course, I can use cat instead of echo. I've just tried out to pipe a 1Mb file with 16500 suggestion to popup in lookup mode, and it works ;)
Yeah, there is an ARG_MAX define which tells the maximum size of environment variables and command arguments. I think it is around 64 KB.
Pipes of course are without such limits. This is also why it is generally preferred to take selection (for TM commands) as input rather than use TM_SELECTED_TEXT, at least for commands where it might be more than a few words/lines.
Yeap.
But there is still the question, whether it's worth to implement such lookup mode in popup? See http://www.bibiko.de/TM_DIALOG2_popup_lookup.mov (1M)
--Hans
That looks pretty hip. But the ui should show what you're typing somewhere.
Thomas Aylott [SubtleGradient] from iPhone
On Apr 21, 2008, at 12:10 PM, Hans-Joerg Bibiko bibiko@eva.mpg.de wrote:
On 21 Apr 2008, at 17:39, Allan Odgaard wrote:
On 18 Apr 2008, at 14:52, Hans-Joerg Bibiko wrote:
On 18 Apr 2008, at 14:27, Hans-Joerg Bibiko wrote:
But by doing this I have some limitations:
- The size of my suggestions:
Up to now I have to pipe it to DIALOG2 but this size is limited. Maybe it is worth to think about a mechanism to load a file containing the suggestions.
This is wrong. Of course, I can use cat instead of echo. I've just tried out to pipe a 1Mb file with 16500 suggestion to popup in lookup mode, and it works ;)
Yeah, there is an ARG_MAX define which tells the maximum size of environment variables and command arguments. I think it is around 64 KB.
Pipes of course are without such limits. This is also why it is generally preferred to take selection (for TM commands) as input rather than use TM_SELECTED_TEXT, at least for commands where it might be more than a few words/lines.
Yeap.
But there is still the question, whether it's worth to implement such lookup mode in popup? See http://www.bibiko.de/TM_DIALOG2_popup_lookup.mov (1M)
--Hans
For new threads USE THIS: textmate@lists.macromates.com (threading gets destroyed and the universe will collapse if you don't) http://lists.macromates.com/mailman/listinfo/textmate
On 21.04.2008, at 22:51, Thomas Aylott wrote:
That looks pretty hip. But the ui should show what you're typing somewhere.
It does. Everything what's typed in is displayed in the header of the table column. (An interim solution)
But there is still the question, whether it's worth to implement such lookup mode in popup? See http://www.bibiko.de/TM_DIALOG2_popup_lookup.mov (1M)
--Hans
Hi,
I have an other note:
The key 'insert': This is very useful to have but I believe its name is a bit confusing. I expected that instead to insert "match" or "display" to insert the value of "insert". But it is a kind of static suffix. Maybe better to rename it to suffix?
--Hans
On 17 Apr 2008, at 11:29, Hans-Joerg Bibiko wrote:
The key 'insert': This is very useful to have but I believe its name is a bit confusing. I expected that instead to insert "match" or "display" to insert the value of "insert". But it is a kind of static suffix. Maybe better to rename it to suffix?
I do not follow this. We have:
display → the string displayed in the pop-up match → the string matched against user input insert → the string inserted after the user press ↩
How would you like to see this changed/renamed?
On 17 Apr 2008, at 11:58, Allan Odgaard wrote:
On 17 Apr 2008, at 11:29, Hans-Joerg Bibiko wrote:
The key 'insert': This is very useful to have but I believe its name is a bit confusing. I expected that instead to insert "match" or "display" to insert the value of "insert". But it is a kind of static suffix. Maybe better to rename it to suffix?
I do not follow this. We have:
display → the string displayed in the pop-up match → the string matched against user input insert → the string inserted after the user press ↩
Yes, yes ;) Maybe I was a bit confused. I only have my "problem" in mind and popup is really a narrow down completion. And "insert" is linked to insert after the completion is finished, and not to insert the content of "insert" instead of the completion's result.
In addition what purpose has the option "wait"? As I mentioned it works but I do not see what I'm typing whereas popup follows my keyboard input correctly. If I then press ESC everything what I typed will be inserted. (?) If I press RETURN the term I typed will inserted plus its completion coming from my selected item and additionally I will get a plist of my selected item. This behaviour led me to the conclusion that instead of the completion result the content of "insert" would inserted.
Maybe it's worth to write a tiny manual for DIALOG2 ;)
--Hans
On 17 Apr 2008, at 13:00, Hans-Joerg Bibiko wrote:
In addition what purpose has the option "wait"?
"For me it would be more logical" if --wait behaves like this:
- any alphanumerical NSEvent will NOT be sent to TM
- in TMDIncrementalPopUpMenu.mm > method: completeAndInsertSnippet NOT: if([aString length] > [temp length]) { insertText... } BUT: if([aString length] > [temp length] && !wait) { insertText... }
- if the selected item has the key "insert" insert the content of "insert" else if there is a shell-cmd do shell-cmd and insert the result else only write the result as plist to stdout end if end if
But still, there's the issue that I do not see what I'm typing. Maybe one could add the current mutablePrefix as first item in the list shadowed and not selectable(?)
Or am I wrong?
--Hans