0

I've got this function in my .bash_rc:

function ForwardSearchXdvi {
latex -src *.tex;
for i in *.dvi; do xdvi -sourceposition "$1 ${i/.dvi/.tex}" $i; done ;
}

it works... I call it by command line with the $1 argument (the target line number in my file.tex) and it's fine.

I'd like to run it directly from emacs so I made this command:

(defun ForwardXdviSearch ()
(interactive)
(shell-command (format "bash -ic %s" (shell-quote-argument "latex -src J[HCI]*.tex; for i in J[HCI]*.dvi; do xdvi -sourceposition \"$1 ${i/.dvi/.tex}\" $i; done ;")))
)

How can I pass the argument $1 to the function when I call it with "M-x Function" ?

1
  • Make sure you read C-h f interactive Commented Jul 16, 2013 at 10:33

1 Answer 1

2

You would need to use special form interactive for reading arguments. Something like this untested code:

(defun forward-xdvi-search (line-number)
  (interactive "nForward to line: ")
  (shell-command
   (format "bash -ic %s"
           (shell-quote-argument
            (format "latex -src J[HCI]\*.tex; for i in J[HCI]\*.dvi; do xdvi -sourceposition \"%d ${i/.dvi/.tex}\" $i; done ;"
                    line-number)))))

Edited with the improvement suggested by @phils

Sign up to request clarification or add additional context in comments.

8 Comments

interactive has a code for reading numbers, so you can use "nForward to line: "
It doesn't work for me. I obtain: Wrong number of arguments: (lambda (line) (interactive) (shell-command (format "bash -ic %s" (shell-quote-argument "latex -src J[HCI]*.tex; for i in J[HCI]*.dvi; do xdvi -sourceposition \"$1 ${i/.dvi/.tex}\" $i; done ;")))), 0
@phils Right! I should have read C-h f interactive myself :-) Updated the code with your suggestion.
@GabrieleNicolardi, it seems you did not copied the code right, you copied (interactive), instead of (interactive "nForward to line: "), so emacs cannot figure how to read the 1st argument.
@juanleon, thank you very much for your help but I copied the code right and it doesn't work. I'm trying to figure out how to pass the argument to the function. I tried C-u "number" M-x Function. I tried M-x Function. No way. I'm not a programmer so please, don't blame me.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.