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

LaTeX mode: the feature that encloses a region by $ doesn't work #834

Closed
ghost opened this issue Dec 26, 2017 · 11 comments
Closed

LaTeX mode: the feature that encloses a region by $ doesn't work #834

ghost opened this issue Dec 26, 2017 · 11 comments

Comments

@ghost
Copy link

ghost commented Dec 26, 2017

Expected behavior

in LaTeX mode, when marking a region like foo |zoo bar|> zar, where | indicates the region boundary, and > indicates the cursor and type the $ key, I expected that the text zoo bar will be enclosed in a pair of $, like: foo $zoo bar$ zar.

Actual behavior

The text zoo bar is deleted. The remain text is foo zar

Steps to reproduce the problem

  • In LaTeX mode, type foo zoo bar zar,
  • Mark the region zoo bar
  • Type $
  • Result: foo zar (zoo bar is deleted)

Environment & version information

Linux Mint 18.3, Spacsmacs, GNU Emacs 26.0.90, smartparens-20171201.242

@ghost
Copy link
Author

ghost commented Dec 27, 2017

I try to test with a new few pairs in latex mode and here is the result:

(sp-local-pair "^" "^")  --> the wrapping feature works normally
(sp-local-pair "^" "$")  --> the wrapping feature works normally
(sp-local-pair "$" "^")  --> the wrapping feature doesn't work
(sp-local-pair "$" "$")  --> the wrapping feature doesn't work

Looking in the code of smartparens, I observed that the variable sp-wrap-overlays was computed differently, when $ is typed, as opposed to {, (, [ (at the same location of tex)

sp-wrap-overlay for $:
(#<overlay from 720 to 721 in foo.tex> . #<overlay from 722 to 722 in foo.tex>)

sp-wrap-overlay for {.(,[:
(#<overlay from 721 to 722 in foo.tex> . #<overlay from 732 to 732 in foo.tex>)

@ghost
Copy link
Author

ghost commented Dec 27, 2017

I did more investigation and believed that the issue was introduced in the commit 7a8dff4: (Properly integrate strict mode and delete-selection-mode)

The revision 97e6dd6 (Add nil-check to sp-in-docstring-p for string bounds) works normally.

@Fuco1
Copy link
Owner

Fuco1 commented Dec 27, 2017

The problem is that $ in latex mode is bound to some command which does not fire self-insert-command which is what delete-selection-mode uses as a hook. So the region is deleted prior to the wrapping because delsel does not register the command as "working on the region".

This can be fixed somehow, but is pretty hackish. I'm trying to come up with some nice solution (the issue being that only one predicate can be registered for delete-selection property and latex mode already adds something by itself).

@ghost
Copy link
Author

ghost commented Dec 28, 2017

Thank you for the confirmation and I'm looking forward to your update!
Currently, I am using the working revision 97e6dd6 of smartparens

@jabranham
Copy link
Collaborator

jabranham commented Jan 30, 2018

A workaround in the meantime is to rebind $ to self-insert-command in TeX-mode-map.

@ghost
Copy link
Author

ghost commented Feb 25, 2018

@jabranham Thank you for the suggestion!

@DrWaleedAYousef
Copy link

Same happen for the quotation; where it is supposed that the marked region is inserted in a quotation like `` " , when I just hit ". How can we fix that? Also, I do not know how to " rebind $ to self-insert-command in TeX-mode-map" as you suggested.

@ghost
Copy link
Author

ghost commented Sep 5, 2018

For rebind $, you can try this: (define-key LaTeX-mode-map (kbd "$") 'self-insert-command)

@Fuco1
Copy link
Owner

Fuco1 commented Sep 5, 2018

It works for me with the default config on emacs 26.1, I can't repro this.

@Fuco1 Fuco1 added this to the October batch milestone Nov 11, 2018
@pietro-coretto
Copy link

pietro-coretto commented Jul 10, 2021

For rebind $, you can try this: (define-key LaTeX-mode-map (kbd "$") 'self-insert-command)

this doesn't work for me (GNU Emacs 26.3 (build 2, x86_64-pc-linux-gnu, GTK+ Version 3.22.30) of 2019-09-16)

Without the code above, when I selected abc and then press $, it cancela the whole string abc.

With the code above, it does differently: it delets abc and put inside $$ the next 3 chars after the original abc

@Fuco1 Fuco1 added this to Triage Mar 18, 2024
@Fuco1 Fuco1 moved this to To triage in Triage Mar 18, 2024
@Fuco1
Copy link
Owner

Fuco1 commented Mar 30, 2024

Seems that this was also happening because before the functions were called TeX-insert-dollar and TeX-insert-quote and now are renamed to all lower-case. I added the new variants to the list of functions where we use some special handling and it started to work for me. I also added a test case for future regressions.

@Fuco1 Fuco1 closed this as completed in 8459f2f Mar 30, 2024
@github-project-automation github-project-automation bot moved this from To triage to Done in Triage Mar 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

No branches or pull requests

4 participants