1

I have the following skeleton pair setup to quickly insert LaTeX fragents into org-mode documents:

(setq skeleton-pair t)
(global-set-key (kbd "$") 'skeleton-pair-insert-maybe)

This works. But the trouble is that it works everywhere. How can I limit this behavior, so that it affects the body text of Emacs org documents (i.e., not applied to babel code-blocks)?

Drew
  • 75,699
  • 9
  • 109
  • 225
Adam
  • 1,857
  • 11
  • 32

1 Answers1

3

While I can't tell you anything about skeletons, you can try the following:

(define-key org-mode-map (kbd "$")
  (lambda ()
    (interactive)
    (if (org-in-block-p '("SRC" "EXAMPLE"))
        (self-insert-command 1)
      (self-insert-command 2)
      (backward-char))))

The binding works only for org-mode and inserts $$ if the cursor is not in BEGIN_SRC or BEGIN_EXAMPLE blocks. Otherwise it inserts only one $.

You can adjust block names you want to avoid double $ to be inserted -- I know not that much about block names in org but I believe you can figure it out.

PS Short demo: https://youtu.be/h4Gxl0zRk5Y

Maxim Kim
  • 1,516
  • 9
  • 17