{"action":"created","issue":{"url":"https://api.github.com/repos/atom/find-and-replace/issues/944","repository_url":"https://api.github.com/repos/atom/find-and-replace","labels_url":"https://api.github.com/repos/atom/find-and-replace/issues/944/labels{/name}","comments_url":"https://api.github.com/repos/atom/find-and-replace/issues/944/comments","events_url":"https://api.github.com/repos/atom/find-and-replace/issues/944/events","html_url":"https://github.com/atom/find-and-replace/pull/944","id":251808598,"node_id":"MDExOlB1bGxSZXF1ZXN0MTM2ODcxMzYx","number":944,"title":"Feature: Javascript Function mode for replace","user":{"login":"bmperrea","id":5274371,"node_id":"MDQ6VXNlcjUyNzQzNzE=","avatar_url":"https://avatars2.githubusercontent.com/u/5274371?v=4","gravatar_id":"","url":"https://api.github.com/users/bmperrea","html_url":"https://github.com/bmperrea","followers_url":"https://api.github.com/users/bmperrea/followers","following_url":"https://api.github.com/users/bmperrea/following{/other_user}","gists_url":"https://api.github.com/users/bmperrea/gists{/gist_id}","starred_url":"https://api.github.com/users/bmperrea/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bmperrea/subscriptions","organizations_url":"https://api.github.com/users/bmperrea/orgs","repos_url":"https://api.github.com/users/bmperrea/repos","events_url":"https://api.github.com/users/bmperrea/events{/privacy}","received_events_url":"https://api.github.com/users/bmperrea/received_events","type":"User","site_admin":false},"labels":[{"id":193724917,"node_id":"MDU6TGFiZWwxOTM3MjQ5MTc=","url":"https://api.github.com/repos/atom/find-and-replace/labels/needs-review","name":"needs-review","color":"bfe5bf","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2017-08-22T00:56:18Z","updated_at":"2018-08-14T23:13:29Z","closed_at":"2018-08-14T23:13:29Z","author_association":"CONTRIBUTOR","pull_request":{"url":"https://api.github.com/repos/atom/find-and-replace/pulls/944","html_url":"https://github.com/atom/find-and-replace/pull/944","diff_url":"https://github.com/atom/find-and-replace/pull/944.diff","patch_url":"https://github.com/atom/find-and-replace/pull/944.patch"},"body":"### Requirements\r\n\r\n* Filling out the template is required. Any pull request that does not include enough information to be reviewed in a timely manner may be closed at the maintainers' discretion.\r\n* All new code requires tests to ensure against regressions\r\n\r\n### Description of the Change\r\n\r\nThis PR exposes the ability to pass a function as the second argument to javascript's String.prototype.replace() function. This can be useful if you want to replace snake_case with camelCase, for instance with `text.replace(/_([a-z])/g, (m, m1)=>m1.toUpperCase())`. The design is such that one types a javascript function into the Replace text box. \r\n\r\nCareful code design was taken to catch all possible errors, without slowing down the current implementation, and also making it efficient in the new function mode. Careful error analysis catches errors on function compilation and function evaluation, alerting the user appropriately in the error box.\r\n\r\n### Alternate Designs\r\n\r\n1. For the overall feature design, javascript functions were chosen for scriptable replacements. Alternate feature designs were suggested in #417 such as using a regex-style replace object such as with \\U and \\L for uppercase and lowercase (as in Sublime), and maybe match syntax `\\0` and `\\1`. One reason we decided to stick with the original suggestion was that it is immediately supported in javascript, the language in which atom is currently implemented. Specifically, the replace method currently relies on Javascript's string.prototype.replace method. Another is that the function syntax allows more functionality with full freedom to write one's own replace function. The biggest drawback is that one needs to use Javascript, which may not be familiar to all. I would point out that regex replace syntax is not completely standardized and would also be often unfamiliar.\r\n\r\n2. We added a button on the replace line to toggle function mode. One could consider adding this to the find options buttons, or otherwise.\r\n\r\n3. String.prototype.replace always casts it's result as a string. We chose to override this by first checking that the result is actually a string to help avoid errors such as returning an undefined key, or variable. One can still manually cast to a string in the user-written replace function, as in the error handling demo below.\r\n\r\n### Benefits\r\n\r\nOne can programmatically choose the replace text based on regex matches (or a single text match). Use cases include changing case and using simple logic to chose the replacement text.\r\n\r\n### Possible Drawbacks\r\n\r\nThis makes for more UI (an extra button - see demos below). It also makes the buffer_search code more involved.\r\n\r\n### Applicable Issues\r\n\r\nThis solves #417."},"comment":{"url":"https://api.github.com/repos/atom/find-and-replace/issues/comments/413045139","html_url":"https://github.com/atom/find-and-replace/pull/944#issuecomment-413045139","issue_url":"https://api.github.com/repos/atom/find-and-replace/issues/944","id":413045139,"node_id":"MDEyOklzc3VlQ29tbWVudDQxMzA0NTEzOQ==","user":{"login":"lee-dohm","id":1038121,"node_id":"MDQ6VXNlcjEwMzgxMjE=","avatar_url":"https://avatars0.githubusercontent.com/u/1038121?v=4","gravatar_id":"","url":"https://api.github.com/users/lee-dohm","html_url":"https://github.com/lee-dohm","followers_url":"https://api.github.com/users/lee-dohm/followers","following_url":"https://api.github.com/users/lee-dohm/following{/other_user}","gists_url":"https://api.github.com/users/lee-dohm/gists{/gist_id}","starred_url":"https://api.github.com/users/lee-dohm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lee-dohm/subscriptions","organizations_url":"https://api.github.com/users/lee-dohm/orgs","repos_url":"https://api.github.com/users/lee-dohm/repos","events_url":"https://api.github.com/users/lee-dohm/events{/privacy}","received_events_url":"https://api.github.com/users/lee-dohm/received_events","type":"User","site_admin":true},"created_at":"2018-08-14T23:13:29Z","updated_at":"2018-08-14T23:13:29Z","author_association":"MEMBER","body":"Thank you for your contribution.\r\n\r\nWe've reviewed this and while we can see that there are definite benefits for certain workflows, this is not functionality that we want to maintain long-term. Because of this, we're going to close this PR and the associated issue as well. Our apologies for taking so long to come to a decision on it.\r\n\r\nThanks for your contribution and your interest in Atom."}}
{"actor":{"display_login":"lee-dohm"}}