I'm customizing spacemacs for my workflow. I'm new to elisp and can't figure out how to do this after looking at other functions in .el files and other posts.
Basically, I wrote an elisp function that executes a shell script on the currently open file(the shell script compiles a special kind of LaTeX file that includes something called Lilypond code which is used for music typesetting). The code for the function I wrote looks like this:
(defun lytex-to-pdf ()
(interactive)
(shell-command-to-string (format "bash ~/lytex-to-pdf.sh %s" buffer-file-name)))
(evil-leader/set-key "cb" 'lytex-to-pdf)
)
It works fine, but I'd like it to pop up a buffer with a terminal showing the std-out of the shell script. That way I can debug in case it fails to compile. How can I do this? Is shell-command-to-string the right emacs command I should be executing?
As an aside, how do I change my custom keybinding to only show up in the LaTeX major mode?
start-process
with aset-process-sentinel
and usebuffer-string
orbuffer-substring
to gather some/everything when the process ends successfully.start-process
has an optional argument to generate a buffer, and you can usedisplay-buffer
or other function to pop it up wherever/however you see fit. For long command lines, you may wish to consider using something like(start-process "my-process" "*OUTPUT-BUFFER*" "/bin/bash" "-c" "LONG-COMMAND-LINE-WITH-ARGS")
.start-process
did exactly what I needed, thanks! Please add as an answer so I can mark this question as answered. Also, figured out the major-mode key binding.latex-mode
, i.e. the one that labels your buffers as "LaTeX/MPS". My next step is to actually integrate my function better with this mode, and get spacemacs to recognize .lytex files with the latex/build command bound to SPC-m-b and to do the same with the TeX-view command bound to SPC-m-v(right now it throws an error because it's looking for "<file>.lytex.pdf" instead of just "<file>.pdf". Once I figure that out, I'll have things all set up how I want to for type-setting documents with musical notation! If I can't figure this out in a couple days, I'll post another question.