0

I use LaTeX with Emacs and want to be able to pass words of what I write to a shell command. (As example I use xargs echo.)

For this purpose I defined an interactive elisp function:

(defun echo () 
  (interactive)
  (let ((bnds  (bounds-of-thing-at-point 'word)))
    (shell-command-on-region (car bnds) (cdr bnds) "xargs echo")))

This works well for most buffers, but not for LaTeX buffers, using AUCTeX font locking. Most words again work fine, but not words with quotation marks at their word boundary.

A minimal example:

\documentclass{article}
\usepackage{german}

\begin{document}
test "`Test"'
\end{document}

First, just as proof of concept: If point is on test in my LaTeX buffer and I try my command (echo) I get test as result in the minibuffer. (As expected.)

Now the problem: If point is on Test instead and I use my command xargs complains about unmatched double quotes.

The reason for this is that shell-command-on-region doesn't pass Test to the shell command but Test"'. This I can verify by using in my elisp code xargs -0. I then get as result in the minibuffer:

Test"'

The problem comes from AUCTeXs font locking. (Which I want to use!) If I set font-latex-quotes to nil, my command works fine (it returns Test in the minibuffer), but of course quoted content will not be fontified ...

Any ideas how I could either change my elisp code to work also with AUCTeX, or to customize AUCTeX so that it fontifies quoted content but preserves correct word boundaries?

newtothis
  • 15
  • 2
  • Could you please clarify what works and what doesn't? Should `"test"` and `"Test"` be quoted differently? – ChrisGPT was on strike Jan 28 '14 at 22:59
  • In both cases I would like to get the word without any quotation marks. That works of course for "test", as there are no quotation marks around it in my minimal example. It doesn't work for "Test", which has quotation marks around it in my minimal example. (To be precise it has LaTeX code for german quotation marks around it, and for that reason a simple double quote at it's end.) – newtothis Jan 28 '14 at 23:16
  • Your description is not clear. Give concrete examples of the use of your command `echo` at different positions of concrete example text --- whatever cases you are really trying to communicate. Secondly, the sexp at point returns a string if that is the sexp at point. If you don't want it to return a string, then consider looking for the word at point or whatever you really want. Or if you really want to pick up the string at point and then use the bounds of its contents, not including the `"` chars, then adjust the returned bounds. No one can help you until you say what you need. – Drew Jan 29 '14 at 04:19
  • I hope the question is now clearer. – newtothis Jan 29 '14 at 14:46
  • Without knowing anything about the actual problem -- have you tried setting `font-latex-quotes` temporarily to `nil` around the call to `bounds-of-thing-at-point`? (You can do this with an outer `let`.) – Lindydancer Jan 29 '14 at 15:05
  • Thanks for the suggestion. I tried it, but it doesn't help. – newtothis Jan 29 '14 at 15:52

1 Answers1

0
(defun echo ()
  (interactive)
  (let ((bnds (bounds-of-thing-at-point 'word)))
    (shell-command-on-region (car bnds) (cdr bnds) "xargs echo")
    (display-buffer "*Shell Command Output*")))

WRT your comment, change syntax-table temporarily with function modify-syntax-entry or use another one like this:

(defun echo ()
  (interactive)
  (with-syntax-table text-mode-syntax-table
    (let ((bnds (bounds-of-thing-at-point 'word)))
      (shell-command-on-region (car bnds) (cdr bnds) "xargs echo")
      (display-buffer "*Shell Command Output*"))))
Andreas Röhler
  • 4,804
  • 14
  • 18
  • I have tried `'word` before. But it doesn't resolve the issue. But I will change to it in my question, because it's the better code. – newtothis Jan 29 '14 at 11:17
  • @newtothis If the error appears with 'word also, it means, `"' got word-syntax. So change this. – Andreas Röhler Jan 29 '14 at 12:43
  • But how? That `"'` got word-syntax comes from AUCTeX font locking, I guess. I don't know who to interfere with that. (And nevertheless have quoted content fontified.) – newtothis Jan 29 '14 at 14:48