Skip to content

Allow adapting of cdlatex-math-symbol and cdlatex-math-modify in minibuffer and isearch-mode #75

Description

@nameiwillforget

cdlatex-math-symbol and cdlatex-math-modify both have behaviors depending on the math mode that make sense in a LaTeX-buffer, but not during searches or when the minibuffer is used for replacement. With cdlatex-math-symbol, the probem is that cdlatex-ensure-math will surround inserted symbols with math delimiters when the search might be for a symbol within math mode, so that the delimiters would prevent matching.

The issue with cdlatex-math-modify is similarly that the search might be for a modifier in math mode. So the modifier should be inserted into the minibuffer, but not be surrounded by delimiters. cdlatex-texmathp of course doesn't know this and will offer text-modifiers.

So for both commands there should be a possibility to adapt their behavior in minibuffer-mode and isearch-mode. For cdlatex-math-symbol this would be super-easy by using the (currently unused) prefix-argument to disable cdlatex-ensure-math if it is set. For cdlatex-math-modify something similar would work, but it already uses the prefix-argument. The way I've solved this is by placing cdlatex-math-modify in a wrapper that uses the prefix to switch between text and math modifiers if and only if minibuffer-mode or isearch-mode are on like this:

(defun d-emacs-cdlatex-math-modify (&optional arg)
  "A wrapper around `cdlatex-math-modify' that uses the prefix arg to determine
whether to use text or math if `minibuffer-mode' or `isearch-mode' is on."
  (interactive "p")
  (let ((minibuffer-or-isearch (or (derived-mode-p 'minibuffer-mode)
                                   (derived-mode-p 'isearch-mode))))
    (cl-letf (((symbol-function #'cdlatex--texmathp)
               (lambda () (if minibuffer-or-isearch
                         arg
                       (symbol-function #'cdlatex--texmathp)))))
      (cdlatex-math-modify (unless minibuffer-or-isearch current-prefix-arg)))))

I'm not sure that's the best way to implement this, but it would be nice if something like this were upstream.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions