-
-
Notifications
You must be signed in to change notification settings - Fork 252
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
Edit message in a terminal editor subprocess #1394
Conversation
36e0c30
to
44d5242
Compare
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.
@neruyzo Thanks for thinking of this feature and contributing 👍
Once I had set $EDITOR this worked for me with vim
, though prior to that it simply failed with no error.
Was ctrl o
the shortcut in your editor, or from something else? Selecting a new shortcut key is often challenging as it then is difficult to change later.
One issue I found is that there seems to be a blank line added after the text in the compose box, after resuming from the editor?
One followup we could discuss may be to have a header line automatically generated in the message to indicate the recipients/context, which would then be stripped out later. At an extreme we could even defer compose to an editor, though we'd lose features like validation and autocomplete that we currently have.
I update the pull request by adding an environment variable I rename the command |
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.
@neruyzo Thanks for improving this - I left a few more comments.
The other point that occurs for me is the blank line issue I mentioned in the previous review - do you see this too?
For example, for This text
in vim, becomes
This text[]
in the compose box ([]
being the cursor)
I updated it. I missed before the trailing empty line that may be create by code editor, to fix that I now use In addition to the comments, should I document $ZULIP_EDITOR_COMMAND somewhere, maybe in the README ? I tested in most of my code editors I could use Zulip terminal will try to position the cursor at the same place as before the message was edit. There is no problem when the new message is smaller than cursor position. |
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.
@neruyzo For use with terminal editors this looks fine to me 👍
I'll adjust the commit text if we merge this as-is soon, to match the style we use.
The extra line issue looks resolved, and cursor position isn't a problem 👍
Re the description, I definitely agree that Open
works in terms of ctrl o
, and looking at adjacent entries, we use 'message' rather than 'composition' or similar, so it's at least consistent for now :)
(it's also better in the more prominent position 👍)
I tried a little to debug the gvim issue, that it opens with no content. By the time that gvim opens with the PR right now, the file is empty/gone. If I add a sleep(20) after the open, ZT pauses and the content does enter the editor... and if (and only if) I edit and save the file within 20s does the content transfer back to ZT.
Other than these minor issues, which we can document, I do wonder if using a context manager with the NamedTemporaryFile may be cleaner/simpler - it already can be used to write to and read from a file, and is guaranteed to always clean up.
ZULIP_EDITOR_COMMAND works well enough, and we should document it, though a config file option may be easier in the long run. We can document in the README, or maybe just placing everything into a FAQ entry like 'Can I compose messages in another editor?' might work well enough. That can include how to set it up, as well as what values are known to work (or not).
Re the TEMPFILE:LINE:CHARACTER point, do you mean passing eg. /tmp/tmp12345filename:5:1
as an option? That can certainly be an option, and I'd welcome an issue being filed with anything that we don't complete here.
@andersk Based on feedback on previous external-command PRs, do you have any concerns with this implementation? |
c70ce82
to
f747d0c
Compare
2d4ecaf
to
389a903
Compare
Update using shlex instead of oslex |
@mek-yt Unfortunately this great PR got a bit buried with other work over the Summer, but seems essentially good to go? Re-reading this:
@andersk Do you have any outstanding concerns regarding this in its current state? |
I updated the code with setting from ZULIPRC in |
beed246
to
cc1b0e5
Compare
@neiljp everything should be done and clean. I updated the message on opening and add
or with new config source
if there is no config in zuliprc or environment the message is
|
I fix the conflicts. |
@mek-yt Thanks for all your work on this, it's really appreciated! I'm working on resolving some conflicts and changes necessary to integrate with other recent commits, and plan to merge soon! |
A new OPEN_EXTERNAL_EDITOR command (hotkey: Ctrl o) may now open an external editor, if details of one are provided, to allow message content to be edited outside of the application, during message compose or editing. The external editor may be specified by, in order of increasing precedence: - the semi-standard EDITOR environment variable - a ZULIP_EDIT_COMMAND environment variable - a new 'editor' key in the zuliprc file ZULIP_EDIT_COMMAND is added to allow a custom form of EDITOR to be used, ie. to avoid causing issues with other tools that may depend upon the latter. The command is validated as being set and the path to it as existing, with errors reported to the user. The feature then operates via a randomly-named temporary file, initialized with any existing message content, which is opened by the application with the editor. The application pauses at this point, until the editing is complete, when the content is substituted back into the compose content area, and the application resumes. README updated to document new zuliprc option. hotkeys automaically updated for new command. Tests updated. Additional defensive approaches and textual changes made by neiljp.
Main content by original author, with phrasing adjustments by neiljp. Additional notes regarding the terminal switching between the application and terminal editors, and the application being paused while editing, added by neiljp.
@mek-yt Current changes that I will shortly push back here before merging include:
Generally my preference would be for a more spread-out sequence of commits, eg. we don't have environment variables as configuration, so that could be a clean separate addition. In an ideal world I'd also request more tests, but I'd prefer we get this merged and move on with this useful feature! 🎉 |
Create a new command OPEN_IN_TERMINAL_EDITOR (default
ctrl o
) for editing the current message in terminal editor with python tempfile.What does this PR do, and why?
I am using helix as my terminal editor and when I write in terminal I found myself using it's shortcut.
External discussion & connections
Composing in terminal editor #T1394
How did you test this?
Self-review checklist for each commit
Visual changes