How can i map " in org-mode to perform LaTeX mode's tex-insert-quote

I added the following to my config.el

(map! :after evil-org            
      :map evil-org-mode-map     
      :i "\"" #'tex-insert-quote)

When I type " in org-mode, it gives me an error that the function doesn’t exist.

Is there a way to call a function from another major mode from within org-mode? I suppose I could hijack the full set of tex-insert-quote functions from tex-mode.el into my config.el. (But I’m a total LISP newb and would rather be able to import by reference, or whatever the equivalent.)

System information


Loading data dump...

Well, I went the inelegant route and just hijacked the code from tex-mode.el and created my own macro file to include.

;;; my-tex-insert-quote.el -*- lexical-binding: t; -*-
;;
;; The variables and function are stolen directly from the tex-mode.el
;; repository.  The only change is to add "my-" in front of all the
;; variable and function names.

(defcustom my-tex-open-quote (purecopy "``")
  "String inserted by typing \\[my-tex-insert-quote] to open a quotation."
  :type 'string
  :options '("``" "\"<" "\"`" "<<" "«"))
;;  :group 'tex)

;;;###autoload
(defcustom my-tex-close-quote (purecopy "''")
  "String inserted by typing \\[my-tex-insert-quote] to close a quotation."
  :type 'string
  :options '("''" "\">" "\"'" ">>" "»"))
;;  :group 'tex)

(defun my-tex-insert-quote (arg)
  "Insert the appropriate quote marks for TeX.
Inserts the value of `my-tex-open-quote' (normally \\=`\\=`) or `my-tex-close-quote'
\(normally \\='\\=') depending on the context.  With prefix argument, always
inserts \" characters."
  (interactive "*P")
  ;; Discover if we'll be inserting normal double quotes.
  ;;
  (if (or arg (memq (char-syntax (preceding-char)) '(?/ ?\\))
          (eq (get-text-property (point) 'face) 'tex-verbatim)
          (nth 4 (syntax-ppss)) ; non-nil if point is in a TeX comment
          ;; Discover if a preceding occurrence of `my-tex-open-quote'
          ;; should be morphed to a normal double quote.
          ;;
          (and (>= (point) (+ (point-min) (length my-tex-open-quote)))
               (save-excursion
                 (backward-char (length my-tex-open-quote))
                 (when (or (looking-at (regexp-quote my-tex-open-quote))
                           (looking-at (regexp-quote my-tex-close-quote)))
                   (delete-char (length my-tex-open-quote))
                   (when (looking-at (regexp-quote my-tex-close-quote))
                     (delete-char (length my-tex-close-quote)))
                   t))))
      ;; Insert the normal quote (eventually letting
      ;; `electric-pair-mode' do its thing).
      ;;
      (self-insert-command (prefix-numeric-value arg))
    ;; We'll be inserting fancy TeX quotes, but consider and imitate
    ;; `electric-pair-mode''s two behaviors: pair-insertion and
    ;; region wrapping.
    ;;
    (if (and electric-pair-mode (use-region-p))
        (let* ((saved (point-marker)))
          (goto-char (mark))
          (insert (if (> saved (mark)) my-tex-open-quote my-tex-close-quote))
          (goto-char saved)
          (insert (if (> saved (mark)) my-tex-close-quote my-tex-open-quote)))
      (if (or (memq (char-syntax (preceding-char)) '(?\( ?> ?\s))
              (memq (preceding-char) '(?~ ?')))
          ;; We're in an "opening" context
          ;;
          (if electric-pair-mode
              (if (looking-at (regexp-quote my-tex-close-quote))
                  (forward-char (length my-tex-close-quote))
                (insert my-tex-open-quote)
                (insert my-tex-close-quote)
                (backward-char (length my-tex-close-quote)))
            (insert my-tex-open-quote))
        ;; We're in a "closing" context.
        ;;
        (if (looking-at (regexp-quote my-tex-close-quote))
            (forward-char (length my-tex-close-quote))
          (insert my-tex-close-quote))))))
;; --------------------------------------------------------------------------
;; --------------------     END STOLEN CODE    ------------------------------
;; --------------------------------------------------------------------------

;; In org-mode, do LaTeX quote expansion
(map! :after evil-org
       :map evil-org-mode-map
       :i "\"" #'my-tex-insert-quote)

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.