Note that there are some explanatory texts on larger screens.

plurals
  1. PORegexp in Emacs progn
    primarykey
    data
    text
    <p>I have the following Emacs macro, which evaluates the AucTex command <code>TeX-insert-macro</code> on selected text:</p> <pre class="lang-lisp prettyprint-override"><code>(eval-after-load "latex" '(progn (define-key LaTeX-mode-map (kbd "C-c (") (lambda () (interactive) (TeX-insert-macro "command"))))) </code></pre> <p>However, how would I perform a regexp on the selected text and pass that to <code>TeX-insert-macro</code>?</p> <p><a href="https://tex.stackexchange.com/questions/136563/command-emacs-selection-commandregexped-selection">See this question for more details.</a></p> <p>For example: Suppose I have the following text:</p> <blockquote> <p>…as shown in figure (24).</p> </blockquote> <p>Now, suppose I select "(24)." Then, I want a command to convert it to:</p> <blockquote> <p>…as shown in figure \command{eq:24}.</p> </blockquote> <p>Viz., how would I define a new Emacs command that I could place in <code>~/.emacs</code> that would run <code>C-C RET command RET</code> on a regexp'ed version of the selected text?</p> <p><strong>Why doesn't the following with regexp work?</strong></p> <pre class="lang-lisp prettyprint-override"><code>(eval-after-load "latex" '(progn (define-key LaTeX-mode-map (kbd "C-c )") (lambda () (interactive) (query-replace-regexp "\(([0-9]+)\)" "\1") (TeX-insert-macro "eq") )))) </code></pre> <p><strong>Minor improvement:</strong></p> <p>This works well if I select, e.g., "(45)" from the left to the right and then run the code by typing <kbd>C-c )</kbd></p> <pre class="lang-el prettyprint-override"><code>(eval-after-load "latex" '(progn (define-key LaTeX-mode-map (kbd "C-c )") (lambda () (interactive) (exchange-point-and-mark) (replace-regexp "[\(\)]" "") (TeX-insert-macro "eq") )))) </code></pre> <p>However, if I select "(45)" from the right to the left, it doesn't work because the point and mark are flipped. Is there a way to make sure the point and mark aren't flipped, such as by running <code>exchange-point-and-mark</code> when they are flipped?</p> <p>Also, there are other issue with the regexp, e.g., if there are other parentheses nearby it gets greedy.</p> <p>thanks</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload