-
Notifications
You must be signed in to change notification settings - Fork 203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add disable-hclip function #1089
Open
junjihashimoto
wants to merge
3
commits into
yi-editor:master
Choose a base branch
from
junjihashimoto:feature/disable-hclip
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{-# OPTIONS_HADDOCK show-extensions #-} | ||
|
||
-- | | ||
-- Module : Yi.Clip | ||
-- License : GPL-2 | ||
-- Maintainer : [email protected] | ||
-- Stability : experimental | ||
-- Portability : portable | ||
-- | ||
-- A proxy of clipboard. | ||
|
||
module Yi.Clip ( setClipboard | ||
, getClipboard | ||
) | ||
where | ||
|
||
import qualified System.Hclip as H (getClipboard, setClipboard) | ||
import Data.IORef | ||
import System.IO.Unsafe | ||
|
||
import Yi.Types (configDisableSystemClipboard, askCfg) | ||
import Yi.Utils (io) | ||
import Yi.Keymap (YiM) | ||
|
||
clipboard :: IORef String | ||
clipboard = unsafePerformIO $ newIORef "" | ||
|
||
getClipboard' :: IO String | ||
getClipboard' = readIORef clipboard | ||
|
||
setClipboard' :: String -> IO () | ||
setClipboard' = writeIORef clipboard | ||
|
||
getClipboard :: YiM String | ||
getClipboard = do | ||
config <- askCfg | ||
if configDisableSystemClipboard config | ||
then io getClipboard' | ||
else io H.getClipboard | ||
|
||
setClipboard :: String -> YiM () | ||
setClipboard text = do | ||
config <- askCfg | ||
if configDisableSystemClipboard config | ||
then io $ setClipboard' text | ||
else io $ H.setClipboard text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getClipboard
can then determine where to read clipboard state from.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just a emulation of Hclip's function, so it uses String and a global variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When vty-mode, Hclip calls a command of
xclip
, it is really slow.So I think we do not need YiRope.
I just do not want to increase the mutable state of YiM.
If you do not want to use IORef by all means, I'll use the state of YiM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's zero reason to throw away performance. In this case it's more about convenience of any users: why force them to convert from string all the time? Further, String sucks for space, there's no reason to hold onto the clipboard contents as String and put completely unnecessary pressure on GHC's copying GC.
Just add it to YiM state, it's a lot easier to reason about than some random floating globals.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @noughtmare ,
Do you have any comments?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that quality is very important, especially when an objectively better solution is known. I understand that it is not always possible, a balance needs to be struck between effort and quality.
I will explain my interpretation of @Fuuzetsu's proposal in more detail. The proposal consists of two parts. Firstly, to have the virtual clipboard provide and store
YiString
s, to prevent conversion betweenYiString
s andString
s which saves memory and CPU time. The system clipboard can then has to explicitly convert theYiString
s toString
s, because the system clipboard can't storeString
s. The second part is to use the dynamic state inside theYiM
monad to store the virtual clipboard contents, instead of a loose reference.I think the first part of the proposal is objectively an improvement. We don't expect performance from the clipboard, but we do expect it from the editor as a whole and many small performance deficiencies can add up.
The second part, however, is not so clear-cut. The loose reference is not exposed by the
Yi.Clip
module, so it will not be accessible to other parts of the editor. Storing the clipboard contents in theYiM
monad will make it accessible to the whole editor, to me that sounds harder to reason about.@Fuuzetsu and @junjihashimoto have I convinced you or do you still have objections?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree, use it.
This is not a Bad Thing™. If anything, this allows you to make
getClipboard
andsetClipboard
run inYiM
instead ofIO
: this means you can actually stop someone using these somewhere arbitrary and things changing uncontrollably.It's a bit like using global IORef instead of ReaderT with IORef in the env… I don't like it.
Having said that, this is about emulating system clipboard which is arguably this global system thing. So I don't care too strongly about it. If you want it in IORefs, hide them in the module and I'll stomach it.