Skip to content
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

Implements feature requested in #1043 #1048

Closed
wants to merge 3 commits into from

Conversation

ig0774
Copy link
Collaborator

@ig0774 ig0774 commented Mar 16, 2017

Adds a command to wrap the selected text in a simple LaTeX command and automatically expands no selection to the current word. This also changes the keybindings from using snippets to using the command for emph, bold, etc. Additionally, I suppose, this makes new keybindings for new similar commands pretty trivial to implement. I've left the snippets in place so they can be used if desired, but obviously they do not have the same word-grabbing rules.

Adds a command to wrap the selected text in a simple LaTeX command and automatically expands no selection to the current word. This also changes the keybindings from using snippets to using the command for emph, bold, etc. Additionally, I suppose, this makes new keybindings for new similar commands pretty trivial to implement. I've left the snippets in place so they can be used if desired, but obviously they do not have the same word-grabbing rules.
@r-stein
Copy link
Member

r-stein commented May 10, 2017

I think this is a little bit to greedy in selecting words and we should insert a snippet if the selection is empty to easy jump-out of it.

@ig0774
Copy link
Collaborator Author

ig0774 commented May 10, 2017

The greediness (i.e., selecting the word immediately after or immediately before the cursor) is quite intentional. That was part of the initial request. On the snippet thing: I'm not exactly sure I see inserting, e.g., \emph{|} without a tab-out as being that major of an inconvenience. Presumably inserting such a command means you want to add to its content...

@r-stein
Copy link
Member

r-stein commented May 10, 2017

The greediness (i.e., selecting the word immediately after or immediately before the cursor) is quite intentional. That was part of the initial request.

This does not only select words, but also other characters, e.g. if you have foo bar.| and press C-l,C-b you will have foo bar\textbf{.}.

On the snippet thing: I'm not exactly sure I see inserting, e.g., \emph{|} without a tab-out as being that major of an inconvenience. Presumably inserting such a command means you want to add to its content...

The snippets usually only have a few words/one sentence, so I personally just press it, write the content, and press tab to go further.

@ig0774
Copy link
Collaborator Author

ig0774 commented May 10, 2017

This does not only select words, but also other characters, e.g. if you have foo bar.| and press C-l,C-b you will have foo bar\textbf{.}.

That's a good point and a limitation of the word() function. I suppose we can check if it's a one-character string and matches one the word_separators and just treat it like an empty string.

The snippets usually only have a few words/one sentence, so I personally just press it, write the content, and press tab to go further.

Good point. I think I was thinking broadly in terms of getting this working across multiple selections, which is hard to do with snippets, where the selections might vary from one another. The common case, though, is probably just a single cursor and that could be optimised to use a snippet, I suppose.

- No longer wraps word_separator characters by default (less greedy)
- Uses snippet for simple case of a single insertion of new command
@ig0774
Copy link
Collaborator Author

ig0774 commented May 10, 2017

@r-stein: 1acf8ab implements what I mentioned above. I'd be grateful if you could take a look.

@r-stein
Copy link
Member

r-stein commented May 10, 2017

I would use the expand feature very conservative, because you always can just manually expand it before triggering, but not the other way.
So I would do it like this:

if all selections are empty and (preceded by a word character or inside a word):
    wrap the word around the selection with `textbf{....}`
else:
    insert_snippet("\textbf{${1:$SELECTION}}$0")

@r-stein r-stein added this to the v4.0 milestone May 23, 2017
@r-stein r-stein changed the base branch from master to version4 May 23, 2017 06:07
@ig0774 ig0774 deleted the branch SublimeText:version4 August 24, 2021 21:06
@ig0774 ig0774 closed this Aug 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants