Re: [xmonad] Changes to XPrompt

2012/5/7 Carlos López Camey
2012/5/6
: Hello Carlos!
Quoting Carlos López Camey
: The changes would be: * Autocomplete based on several modes (there is always a mode set) The autocomplete items are generally path to files, mode 1 could use for example `locate %s`, mode 2 `recollq` [0] (searches for tokens inside files) and mode 3 `locate --regexp %s` to autocomplete.
mkXPrompt already seems to allow you to specify an IO action to run to create your list of completions. That IO action can itself do any of the things you name, so I don't think you should need to make any changes to realize this wish.
* one-column-only list of autocompletions For the purpose, they are always paths, so they are quite large to keep it in different columns. But this be a setting on the configuration.
* Navigating through completion items and changing autocompletion list on "real time" There is always an item highlighted (if items > 0) The highlighted item not necesarilly is equal to the prompt buffer text. I may write "xmonad.hs" but the autocomplete item shows a full path highlighted. This implies adding an additional field to XPState, complIndex :: Int, that knows which item to highlight next (not based on the buffer's text)
I'm not an XPrompt user, so I can't comment on whether these are possible or not right now, but if not, they sound like nice things to add.
* Action is not necesarilly a String -> X a.
I'd like to count on a Map Extension (String -> String) in some config, where type Extension = String. This map would describe what to do with each file depending on its extension. e.g. an element of the map could be (".org",\path -> "emacs "++path). So I'm not sure how the new signature would be: String -> X a? but this String would be the command sent to spawn, computed using a function that uses the map described above.
You may accomplish this by having your String -> X a function close over the Map you want to query; for example, something like this:
fConstantMap :: String -> X a fConstantMap s = case lookup constMap (extension s) of Nothing -> spawn s Just modifier -> spawn (modifier s) where extension = reverse . take 4 . reverse constMap = fromList [ (".org", \path -> "emacs " ++ path), (".doc", \path -> "libreoffice " ++ path) ]
or, if the Map is going to be built dynamically rather than known at compile time, you can have the map be an argument to the function and pass the function partially-applied to mkXPrompt[WithReturn].
Good luck, and I hope this helps with half your requests! ~d
Greetings again, I forgot to copy the list earlier!
Hello, thanks for the help! After reading your comments, I think it is possible to make the changes to XPrompt. Modifications to XPrompt, XPState and XPConfig shouldn't have to break configs (default settings would have to be added to defaultXPConfig, as well as default definitions for possible new functions on XPrompt).
Back to it then. Carlos
I've coded a bit more, and I think that if different modes are to be added *and* backwards _api compatibility_ is to be kept, it is necessary to include either Data.Typeable or Data.Proxy according to [0]. Correct me if I'm wrong but we can't reify *any* function with Typeable? With Data.Proxy it is possible but xmonad-contrib would need package `tagged` as a dependency. There is a way to keep backwards compatibility to xmonad.hs files but not to modules that use XPrompt. They (XMonad/Prompt/*.hs and XMonad/Actions/Search.hs) must include an instance of XPMode and provide it to mkPrompt, instead of both the explicit completion and action functions, i.e. replace mkXPrompt t conf compl action with mkXPrompt t conf myMode where myMode = XPMode { complFunction = .. action = .. } Would that be ok? I don't think many xmonad.hs use mkXPrompt directly. Carlos

2012/5/8 Carlos López Camey
2012/5/7 Carlos López Camey
: 2012/5/6
: Hello Carlos!
Quoting Carlos López Camey
: The changes would be: * Autocomplete based on several modes (there is always a mode set) The autocomplete items are generally path to files, mode 1 could use for example `locate %s`, mode 2 `recollq` [0] (searches for tokens inside files) and mode 3 `locate --regexp %s` to autocomplete.
mkXPrompt already seems to allow you to specify an IO action to run to create your list of completions. That IO action can itself do any of the things you name, so I don't think you should need to make any changes to realize this wish.
* one-column-only list of autocompletions For the purpose, they are always paths, so they are quite large to keep it in different columns. But this be a setting on the configuration.
* Navigating through completion items and changing autocompletion list on "real time" There is always an item highlighted (if items > 0) The highlighted item not necesarilly is equal to the prompt buffer text. I may write "xmonad.hs" but the autocomplete item shows a full path highlighted. This implies adding an additional field to XPState, complIndex :: Int, that knows which item to highlight next (not based on the buffer's text)
I'm not an XPrompt user, so I can't comment on whether these are possible or not right now, but if not, they sound like nice things to add.
* Action is not necesarilly a String -> X a.
I'd like to count on a Map Extension (String -> String) in some config, where type Extension = String. This map would describe what to do with each file depending on its extension. e.g. an element of the map could be (".org",\path -> "emacs "++path). So I'm not sure how the new signature would be: String -> X a? but this String would be the command sent to spawn, computed using a function that uses the map described above.
You may accomplish this by having your String -> X a function close over the Map you want to query; for example, something like this:
fConstantMap :: String -> X a fConstantMap s = case lookup constMap (extension s) of Nothing -> spawn s Just modifier -> spawn (modifier s) where extension = reverse . take 4 . reverse constMap = fromList [ (".org", \path -> "emacs " ++ path), (".doc", \path -> "libreoffice " ++ path) ]
or, if the Map is going to be built dynamically rather than known at compile time, you can have the map be an argument to the function and pass the function partially-applied to mkXPrompt[WithReturn].
Good luck, and I hope this helps with half your requests! ~d
Greetings again, I forgot to copy the list earlier!
Hello, thanks for the help! After reading your comments, I think it is possible to make the changes to XPrompt. Modifications to XPrompt, XPState and XPConfig shouldn't have to break configs (default settings would have to be added to defaultXPConfig, as well as default definitions for possible new functions on XPrompt).
Back to it then. Carlos
I've coded a bit more, and I think that if different modes are to be added *and* backwards _api compatibility_ is to be kept, it is necessary to include either Data.Typeable or Data.Proxy according to [0]. Correct me if I'm wrong but we can't reify *any* function with Typeable? With Data.Proxy it is possible but xmonad-contrib would need package `tagged` as a dependency.
There is a way to keep backwards compatibility to xmonad.hs files but not to modules that use XPrompt. They (XMonad/Prompt/*.hs and XMonad/Actions/Search.hs) must include an instance of XPMode and provide it to mkPrompt, instead of both the explicit completion and action functions, i.e. replace
mkXPrompt t conf compl action
with
mkXPrompt t conf myMode where myMode = XPMode { complFunction = .. action = .. }
Would that be ok? I don't think many xmonad.hs use mkXPrompt directly.
Carlos
Sorry, the reference [0] http://stackoverflow.com/questions/10497967/given-its-body-functions-create-...

Quoting Carlos López Camey
provide it to mkPrompt, instead of both the explicit completion and action functions, i.e. replace
mkXPrompt t conf compl action
with
mkXPrompt t conf myMode where myMode = XPMode { complFunction = .. action = .. }
I'm not sure I understand. Why is providing a data structure that stores two values better than supplying the two values? What can the internal code do with an XPMode that it couldn't do with a completion function and an action? (...and even if there is an answer to this, why can't the API wrap its two arguments in an XPMode before doing whatever it is it's doing?) ~d

I'm not sure I understand. Why is providing a data structure that stores two values better than supplying the two values? What can the internal code do with an XPMode that it couldn't do with a completion function and an action? (...and even if there is an answer to this, why can't the API wrap its two arguments in an XPMode before doing whatever it is it's doing?)
A XPMode with these two values isn't really more powerful than the two values by themselves I guess :) -- So I've worked a bit on this [0], XMonad.Actions.Launcher uses mkXPromptWithModes to build a new Prompt, this prompt allows switching between modes, each one with its own autocomplete function. Right now there are 3 modes listed in Launcher, they autocomplete to file paths. When something is searched and a file path is selected, the Prompt executes the action function, with type String -> X(), that was provided to mkXPromptWithModes. However, I'd like it to have {- my question #1 -} 1. An action per mode. Have the prompt execute the action that the current mode contains, instead of the same one for every mode. 2. Allow the action to have the type String -> X a. About 1. I tried to follow Don Stewart's comments on stackoverflow but I couldn't convince GHC yet. Maybe I should try again and ask with the code I tried About 2. If 1. is possible and the action has type String -> X a, you can't implement one with type String -> X (), can you? If yes, problem solved. If not, I'd appreciate help with that. {- my question #2 -} The locate mode is slower than recollq, that is ok. The problem is when I write characters too fast, it becomes *slow*. I guess it's because all the spawned processes.. Should I do each autocompletion in a different thread? or are they already in another thread? I'd appreciate help here too If you would like to try it, take a look at my xmonad (around the line #179 in here: https://gist.github.com/2882350). Thanks for your time, Carlos [0] https://github.com/kmels/xmonad-contrib-launcher/commit/a534f0cd475215a4fd9d..., this code is very unclean, e.g. there are things hardcoded. When in Launcher.hs, ignore the comments on how it works, it was only the initial idea.
participants (2)
-
Carlos López Camey
-
wagnerdm@seas.upenn.edu