How do I pass the current file with its path to one of my source block in org-babel? For example:
#+name: cflow
#+header: var file=<what to put here?>
#+begin_src sh :exports none
# output posix format
# -i <symbol> include name start with <symbol> file
# brief input
cflow --format=posix -i _ --brief
#+end_src
I want the command to execute at the current directory of my buffer.
This will do it:
var file=(buffer-file-name)
Related
I am running emacs with Verilog-mode in batch mode. Normally, it overwrites the source file, but I would like to preserve the source file and write the output to a different file. I am trying to put this into a makefile flow, so I need separate input and output files.
My command line:
emacs --batch xyz.auto.sv -f verilog-diff-auto
Try
emacs --batch xyz.auto.sv -f verilog-diff-auto --eval '(write-file "output.sv")'
That should read the input file into a buffer, do whatever verilog-diff-auto is supposed to do and then save the modified buffer to the output file.
I used to make tree diagrams with dot in orgmode.
#+BEGIN_SRC dot :file hallo1_1_1.png
digraph hallo1_1_1 {
A [shape = "circle",style=filled, fillcolor=yellow]
}
#+END_SRC
Now, to pass latex commands (\def\mycommand{args})to my diagrams I would like to use dot2tex.
(the usepackages are in ~/.emacs)
\\usepackage[utf8]{inputenc}
\\usepackage[T1]{fontenc}
\\usepackage{graphicx}
\\usepackage{longtable}
\\usepackage{listings}
\\usepackage{xcolor}
\\usepackage{float}
\\usepackage{soul}
\\usepackage{amssymb}
\\usepackage{hyperref}
\\usepackage{sectsty}
\\usepackage{tabularx}
\\usepackage{pbox}
\\usepackage{tikz}
\\usepackage{stackengine}
\\usepackage{verbatim}
\\usepackage{changepage}
\\usepackage{dot2texi}
\\usepackage[pdf]{graphviz}
\\usetikzlibrary{shapes,arrows}
After using in my test.org:
#+headers: :cmdline latex -shell-escape
#+BEGIN_SRC latex
\digraph[scale=0.5]{MyGraph}{rankdir=LR; a->b; b->c}
#+END_SRC
I got the warning:
The file MyGraph.pdf hasn’t been created from MyGraph.dot yet.
Run ‘dot -Tpdf -o MyGraph.pdf MyGraph.dot’ to create it.
Or invoke LATEX with the -shell-escape option to have this done
automatically.
Is it possible to add the commandline arguments in the file correctly?
I would like the commandline arguments in the file for workflow reasons.
Thank you.
with this line in a file i'm tangling:
#+BEGIN_SRC shell :tangle ./tangle/aux.0 :comments link :paddling no
on tangling, this prompt appears:
"No comment syntax is define. Use: [ ]"
What needs to be set, or text entered in the source file to avoid the prompt?
I've tried:
# <<example>>
or
#
on the first line.
or ... comment-syntax #
after the ":comments link"
and searched the help for examples.
I'm reading the Org Manual, and emacs help, and not finding any specific instructions.
I believe your problem is because emacs cannot determine/recognise the correct mode for the exported source. As it does not recognise the mode, it cannot determine the correct comment character.
According the the org manual, the correct identifier for shell blocks is sh not shell. Try changing your line to
#+BEGIN_SRC sh :tangle ./tangle/aux.0 :comments link :paddling no
*.zsh files open in the default mode (text-mode for me). However, sh-mode is actually multiple modes including behaviours for zsh, bash, etc. How can I tell emacs to open *.zsh files specifically in the zsh flavor of sh-mode?
The flavor of sh-mode is autodetected from the shebang line (first line of your script). If you have "#!/bin/zsh", zsh will be assumed and (for instance) autoload will be recognized as a keyword. autoload will be not recognized as such if first line is "#!/bin/bash"
To make emacs recognize *.zsh files as shell scripts, just add this to your init file:
(add-to-list 'auto-mode-alist '("\\.zsh\\'" . sh-mode))
A programmatic way of selecting a flavor when you don't want to use the shebang is doing this in a sh-mode buffer:
(sh-set-shell "zsh")
So in your case what you need (unless you use shebang) is to update the auto-mode-alist as above and
(add-hook 'sh-mode-hook
(lambda ()
(if (string-match "\\.zsh$" buffer-file-name)
(sh-set-shell "zsh"))))
Whether your file has a #! shebang or not, you can always use a file mode line or a local variables section to set shell-script mode. Having one of these in your script will allow Emacs to do the right thing even if you haven't updated the auto-mode-alist, so is recommended for any non-standard file extension.
The Emacs file mode line for shell scripts is -*- mode: sh -*-. It should be in a comment, and must appear on the first line (or the second line if the first one is a shebang line).
If you can't put it on the first (second) line for some reason, you can create a local variables section at the end of the file (in the last 3000 characters of the file, and on the last page, according to the manual):
# Local Variables:
# mode: sh
# End:
Note that just setting the Emacs mode will still rely on a shebang line for shell type autodetection, and if no shebang line is detected will default to the current SHELL environment variable or the value of sh-shell-file if set).
If you can't have a shebang line, but want the correct shell type to be selected, the only way to do this is with an eval in the mode line or local variables section. Adding this will generate a confirmation prompt every time the file is loaded into Emacs, so this is not generally recommended, but may be acceptable in some cases.
The mode line would be -*- mode: sh; eval: (sh-set-shell "zsh") -*-, and the local variables form would be:
# Local Variables:
# mode: sh
# eval: (sh-set-shell "zsh")
# End:
If you use the shebang method, a more robust form is
#!/usr/bin/env zsh
# env will search the path for zsh. Some distros may put it a different place.
# env is pretty much guaranteed to be in /usr/bin
I know that emacs can recognize a file by the extension, a -*- mode -*- first line, and even by the shebang line, but what do I do if I want to override the shebang?
For example, a script that starts with
#!/usr/bin/env python2.7
...
won't be recognized by the shebang line alone. I also can't add in a -*-python-*- line, because then the shell tries to parse it. How do I deal with this?
You put the -*- mode: python -*- in the second line (special exception, added specifically for the shebang thingies).
You can try putting something like
(add-to-list 'interpreter-mode-alist '("python2.7" . python-mode))
in your .emacs. See “Choosing File Modes” for more info.
Like this:
#!/usr/bin/env python2.7
print "test"
# Local Variables:
# mode: python
# End:
This information comes from Specifying File Variables node of info.
Use f1 i to enter info.
Use g (emacs) to jump to emacs info.
Use g Specifying File Variables to jump to the page.
You can use tab to complete node names.