6

Using Aquamacs 3.2 on Mac OSX Yosemite. I run with delete-selection-mode set, and it mostly works as advertised. However, if I'm in TeX mode (AucTeX), make a selection, and then type $, the selection is cleared and the $ appended. So for example if I select foobar in xyzfoobarxyz and type $, I get xyzfoobar$xyz instead of the desired xyz$xyz. Is this known/documented behavior, or a bug? If it's a bug, is it an AucTeX or an Aquamacs issue (or an Emacs issue)?

Edit: In response to Tobias' comment below, C-h k $ returns

$ runs the command TeX-insert-dollar, which is an interactive compiled Lisp function in `tex.el'.

It is bound to $.

(TeX-insert-dollar &optional ARG)

Insert dollar sign.

If current math mode was not entered with a dollar, refuse to insert one. Show matching dollar sign if this dollar sign ends the TeX math mode and 'blink-matching-paren' is non-nil. When outside math mode, the behavior is controlled by the variable 'TeX-electric-math'.

With raw ^U prefix, insert exactly one dollar sign. With optional ARG, insert that many dollar signs.

And, the function delete-selection-mode is defined in delsel.el.

I'm far from LISP-literate. Perhaps the TeX-insert-dollar function does not take the delete selection mode into account (either by design or by omission)?

npostavs
  • 9,033
  • 1
  • 21
  • 53
rogerl
  • 205
  • 4
  • 9
  • 3
    Probably `$` runs some special command in AucTeX, and that command isn't marked to as an insertion command, see [delsel.el commentary](http://git.savannah.gnu.org/cgit/emacs.git/tree/lisp/delsel.el?id=emacs-24.5#n34) – npostavs Mar 30 '16 at 15:08
  • 2
    According to @npostavs's comment, try this `(put 'TeX-insert-dollar 'delete-selection t)` – xuchunyang Mar 30 '16 at 15:18
  • @xuchunyang That did not work; it seeming had no effect. I tried both `TeX-insert...` and `LaTeX-insert...`. – rogerl Mar 30 '16 at 22:14
  • You should give some more info. What does `C-h k $` deliver? When you input `C-h f delete-selection-mode RET` what file is this function defined in? (As I understand, this determines the version of `delete-selection-mode`.) – Tobias Mar 31 '16 at 19:27
  • 1
    What is the value of `TeX-electric-mode`? – Harald Hanche-Olsen Mar 31 '16 at 21:29
  • @rogerl: How did you evaluate that code? It should work I think. See also [tex.el:6315](http://git.savannah.gnu.org/cgit/auctex.git/tree/tex.el?id=release_11_89#n6315), they marked some commands, it seems `TeX-insert-dollar` was missed. – npostavs Mar 31 '16 at 21:32
  • @npostavs Interesting. Perhaps I should ask the AucTeX folks about that. Thanks. – rogerl Mar 31 '16 at 21:33
  • @HaraldHanche-Olsen if `TeX-electric-math` (not `TeX-electric-mode`, I guess it was a type ;-) I confirm that `(put 'TeX-insert-dollar 'delete-selection t)` works as expected. – giordano Mar 31 '16 at 21:37
  • 1
    @npostavs `TeX-insert-dollar` wasn't missed, it's so by design because for the features it provides the function needs to keep alive the current selection – giordano Mar 31 '16 at 21:38
  • 1
    Actually `TeX-insert-dollar` had in the past the `delete-selection` property, but it was removed in order to provide the feature mentioned above: http://git.savannah.gnu.org/cgit/auctex.git/commit/tex.el?id=d59628f1ee02abccc179c463214baddb5a17bf71 – giordano Mar 31 '16 at 21:44
  • @giordano ah, then probably it should use `(put 'TeX-insert-dollar 'delete-selection #'TeX-insert-dollar-drops-current-selection)` where `TeX-insert-dollar-drops-current-selection` would be a function returns nil in case that feature will be activated. – npostavs Mar 31 '16 at 21:49
  • @giordano So if I understand your comment (and the code) correctly, if some other variable is set, then typing $ will enclose the entire region in a pair of dollar signs? So why couldn't the code be a tad smarter and do the more obvious thing if that other variable is not set? – rogerl Mar 31 '16 at 21:57

1 Answers1

5

AUCTeX provides the feature to wrap opening and closing inline equation markers around active region on pressing $, when TeX-electric-math is non-nil (and this isn't the default). In order to have this, the delete-selection property had to be removed. Actually, its behavior can be dynamically determined by a function, so that

(put 'TeX-insert-dollar 'delete-selection (lambda () (null TeX-electric-math)))

enables or disables it depending on the value of TeX-electric-math. Thanks to this discussion, the above line is now present also in development version of AUCTeX.

giordano
  • 3,245
  • 13
  • 19